Guest User

Untitled

a guest
Feb 2nd, 2013
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.01 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini>
  3.  
  4. #define VERSION "---BIND System V1 By DreDas---"
  5.  
  6. #define PRESSED(%0) \
  7.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  8.  
  9. enum keys
  10. {
  11.     TAB,
  12.     C,
  13.     LMB,
  14.     SPACE,
  15.     ENTER,
  16.     LSHIFT,
  17.     NUM1,
  18.     NUM8,
  19.     NUM2,
  20.     NUM4,
  21.     NUM6,
  22.     Y,
  23.     N,
  24.     H
  25. }
  26.  
  27. #define K_TAB    KEY_ACTION
  28. #define K_C      KEY_CROUCH
  29. #define K_LMB    KEY_FIRE
  30. #define K_SPACE  KEY_SPRINT
  31. #define K_ENTER  KEY_SECONDARY_ATTACK
  32. #define K_LSHIFT KEY_JUMP
  33. #define K_NUM1    KEY_SUBMISSION
  34. #define K_NUM8    KEY_ANALOG_UP
  35. #define K_NUM2    KEY_ANALOG_DOWN
  36. #define K_NUM4    KEY_ANALOG_LEFT
  37. #define K_NUM6    KEY_ANALOG_RIGHT
  38. #define K_Y       KEY_YES
  39. #define K_N       KEY_NO
  40. #define K_H       KEY_CTRL_BACK  
  41.  
  42.  
  43. new Commands[][] =
  44. {
  45.        "{FF0000}Unbind",
  46.        "{04C731}Zinute",
  47.        "{04C731}GautiHP",
  48.        "{04C731}GautiArmor"
  49. };
  50.  
  51.  
  52. new pKey[MAX_PLAYERS][keys];
  53. new pasirinko[MAX_PLAYERS];
  54.  
  55. #define GUI_KEY_LIST 105
  56. #define GUI_CMDS_LIST 106
  57.  
  58. stock pName(playerid)
  59. {
  60.     new Vardas[MAX_PLAYER_NAME];
  61.     GetPlayerName(playerid,Vardas,MAX_PLAYER_NAME);
  62.     return Vardas;
  63. }
  64.  
  65. public OnFilterScriptInit()
  66. {
  67.     print("\n--------------------------------------");
  68.     print("       Bind Script By DreDas Loaded     ");
  69.     print("--------------------------------------\n");
  70.     return 1;
  71. }
  72.  
  73. public OnFilterScriptExit()
  74. {
  75.     return 1;
  76. }
  77.  
  78. public OnPlayerConnect(playerid)
  79. {
  80.     new string[128];
  81.     SendClientMessage(playerid,014789,"Sveikas Atvykęs");
  82.     format(string,sizeof(string),"Bind/%s.txt",pName(playerid));
  83.     if(!dini_Exists(string))
  84.     {
  85.         dini_Create(string);
  86.         dini_IntSet(string,"TAB",pKey[playerid][TAB]);
  87.         dini_IntSet(string,"C",pKey[playerid][C]);
  88.         dini_IntSet(string,"LMB",pKey[playerid][LMB]);
  89.         dini_IntSet(string,"SPACE",pKey[playerid][SPACE]);
  90.         dini_IntSet(string,"ENTER",pKey[playerid][ENTER]);
  91.         dini_IntSet(string,"LSHIFT",pKey[playerid][LSHIFT]);
  92.         dini_IntSet(string,"NUM1",pKey[playerid][NUM1]);
  93.         dini_IntSet(string,"NUM8",pKey[playerid][NUM8]);
  94.         dini_IntSet(string,"NUM2",pKey[playerid][NUM2]);
  95.         dini_IntSet(string,"NUM4",pKey[playerid][NUM4]);
  96.         dini_IntSet(string,"NUM6",pKey[playerid][NUM6]);
  97.         dini_IntSet(string,"Y",pKey[playerid][Y]);
  98.         dini_IntSet(string,"N",pKey[playerid][N]);
  99.         dini_IntSet(string,"H",pKey[playerid][H]);
  100.     }
  101.     else
  102.     {
  103.         pKey[playerid][TAB] = dini_Int(string, "TAB");
  104.         pKey[playerid][C]   = dini_Int(string, "C");
  105.         pKey[playerid][LMB] = dini_Int(string, "LMB");
  106.         pKey[playerid][SPACE] = dini_Int(string, "SPACE");
  107.         pKey[playerid][ENTER] = dini_Int(string, "ENTER");
  108.         pKey[playerid][LSHIFT] = dini_Int(string, "LSHIFT");
  109.         pKey[playerid][NUM1] = dini_Int(string, "NUM1");
  110.         pKey[playerid][NUM8] = dini_Int(string, "NUM8");
  111.         pKey[playerid][NUM2] = dini_Int(string, "NUM2");
  112.         pKey[playerid][NUM4] = dini_Int(string, "NUM4");
  113.         pKey[playerid][NUM6] = dini_Int(string, "NUM6");
  114.         pKey[playerid][Y] = dini_Int(string, "Y");
  115.         pKey[playerid][N] = dini_Int(string, "N");
  116.         pKey[playerid][H] = dini_Int(string, "H");
  117.  
  118.     }
  119.     return 1;
  120. }
  121.  
  122. public OnPlayerDisconnect(playerid, reason)
  123. {
  124.     SaveInfo(playerid);
  125.     return 1;
  126. }
  127.  
  128.  
  129. public OnPlayerCommandText(playerid, cmdtext[])
  130. {
  131.     if(!strcmp(cmdtext, "/bind", true))
  132.     {
  133.         new string[512], string1[600];
  134.         new TAB1[40],C1[40],LMB1[40],SPACE1[40],ENTER1[40],LSHIFT1[40];
  135.         new NUM11[40],NUM81[40],NUM21[40],NUM41[40],NUM61[40],Y1[40],N1[40],H1[40];
  136.         ZaidejoKomandos(playerid,TAB,TAB1);
  137.         ZaidejoKomandos(playerid,C,C1);
  138.         ZaidejoKomandos(playerid,LMB,LMB1);
  139.         ZaidejoKomandos(playerid,SPACE,SPACE1);
  140.         ZaidejoKomandos(playerid,ENTER,ENTER1);
  141.         ZaidejoKomandos(playerid,LSHIFT,LSHIFT1);
  142.         ZaidejoKomandos(playerid,NUM1,NUM11);
  143.         ZaidejoKomandos(playerid,NUM8,NUM81);
  144.         ZaidejoKomandos(playerid,NUM2,NUM21);
  145.         ZaidejoKomandos(playerid,NUM4,NUM41);
  146.         ZaidejoKomandos(playerid,NUM6,NUM61);
  147.         ZaidejoKomandos(playerid,Y,Y1);
  148.         ZaidejoKomandos(playerid,N,N1);
  149.         ZaidejoKomandos(playerid,H,H1);
  150.  
  151.  
  152.         format(string,sizeof(string),"1. TAB = %s\n2. C = %s\n3. LMB = %s\n4. SPACE = %s\n5. ENTER = %s\n6. LSHIFT = %s\n7. NUM1 = %s\n",TAB1,C1,LMB1,SPACE1,ENTER1,LSHIFT1,NUM11);
  153.         format(string1,sizeof(string1),"%s8. NUM8 = %s\n9. NUM2 = %s\n10. NUM4 = %s\n11. NUM6 = %s\n12. Y = %s\n13. N = %s\n14. H = %s",string, NUM81,NUM21,NUM41,NUM61,Y1,N1,H1);
  154.         ShowPlayerDialog(playerid, GUI_KEY_LIST, DIALOG_STYLE_LIST, VERSION, string1, "Select", "Close");
  155.         return 1;
  156.     }
  157.     return 0;
  158. }
  159.  
  160. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  161. {
  162.     if(dialogid == GUI_KEY_LIST)
  163.     {
  164.         if(response)
  165.         {
  166.             new VERSION1[128];
  167.             pasirinko[playerid] = listitem;
  168.             format(VERSION1,sizeof(VERSION1),"%s %s", VERSION,KeyName(playerid));
  169.             ShowPlayerDialog(playerid, GUI_CMDS_LIST, DIALOG_STYLE_LIST, VERSION1, Commands1(), "Select", "Close");
  170.         }
  171.         return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
  172.     }
  173.     if(dialogid == GUI_CMDS_LIST)
  174.     {
  175.         if(response)
  176.         {
  177.             BindKey(playerid,pasirinko[playerid],listitem);
  178.             pasirinko[playerid] = 0;
  179.             SaveInfo(playerid);
  180.         }
  181.         return 1;    
  182.     }    
  183.  
  184.     return 0; // You MUST return 0 here! Just like OnPlayerCommandText.
  185. }
  186.  
  187. stock Zinute(playerid)
  188. {
  189.     SendClientMessage(playerid,123456,"Labas");
  190. }
  191. stock GautiHP(playerid)
  192. {
  193.     SetPlayerHealth(playerid,100.0);
  194.     SendClientMessage(playerid,123456,"Gavote 100 HP");
  195. }
  196. stock GautiArmor(playerid)
  197. {
  198.     SetPlayerArmour(playerid,100.0);
  199.     SendClientMessage(playerid,123456,"Gavote 100 ARMOUR");
  200. }
  201.  
  202.  
  203. stock ZaidejoKomandos(playerid,key,key1[40])
  204. {
  205.     switch(pKey[playerid][key])
  206.     {
  207.         case 0: key1 = "{FF0000} NEPASIRINKTA";
  208.         case 1: key1 = "{04C731}Zinute";
  209.         case 2: key1 = "{04C731}GautiHP";
  210.         case 3: key1 = "{04C731}GautiArmor";
  211.     }
  212.     return key1;
  213. }
  214.  
  215. stock BindKey(playerid,key,command)
  216. {
  217.    pKey[playerid][key] = command;  
  218. }
  219.  
  220. stock KeyName(playerid)
  221. {
  222.     new name[40];
  223.     switch(pasirinko[playerid])
  224.     {
  225.         case 0: name = "TAB";
  226.         case 1: name = "C";
  227.         case 2: name = "LMB";
  228.         case 3: name = "SPACE";
  229.         case 4: name = "ENTER";
  230.         case 5: name = "LSHIFT";
  231.         case 6: name = "NUM1";
  232.         case 7: name = "NUM8";
  233.         case 8: name = "NUM2";
  234.         case 9: name = "NUM4";
  235.         case 10: name = "NUM6";
  236.         case 11: name = "Y";
  237.         case 12: name = "N";
  238.         case 13: name = "H";
  239.     }
  240.     return name;
  241. }
  242.  
  243.  
  244.  
  245. stock Commands1()
  246. {
  247.     new txt[128];
  248.     for(new i; i < sizeof (Commands);i++)
  249.     {
  250.        strcat(txt, Commands[i]);
  251.        strcat(txt, "\n");
  252.     }
  253.     return txt;
  254. }
  255.  
  256. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  257. {
  258.     if (PRESSED(K_TAB))
  259.     {
  260.         CommandUse(playerid,TAB);
  261.     }
  262.     if (PRESSED(K_C))
  263.     {
  264.         CommandUse(playerid,C);
  265.     }    
  266.     if (PRESSED(K_LMB))
  267.     {
  268.         CommandUse(playerid,LMB);
  269.     }
  270.     if (PRESSED(K_SPACE))
  271.     {
  272.         CommandUse(playerid,SPACE);
  273.     }
  274.     if (PRESSED(K_ENTER))
  275.     {
  276.         CommandUse(playerid,ENTER);
  277.     }
  278.     if (PRESSED(K_LSHIFT))
  279.     {
  280.         CommandUse(playerid,LSHIFT);
  281.     }
  282.     if (PRESSED(K_NUM1))
  283.     {
  284.         CommandUse(playerid,NUM1);
  285.     }
  286.     if (PRESSED(K_NUM8))
  287.     {
  288.         CommandUse(playerid,NUM8);
  289.     }
  290.     if (PRESSED(K_NUM2))
  291.     {
  292.         CommandUse(playerid,NUM2);
  293.     }
  294.     if (PRESSED(K_NUM4))
  295.     {
  296.         CommandUse(playerid,NUM6);
  297.     }
  298.     if (PRESSED(K_Y))
  299.     {
  300.         CommandUse(playerid,Y);
  301.     }
  302.     if (PRESSED(K_N))
  303.     {
  304.         CommandUse(playerid,N);
  305.     }
  306.     if (PRESSED(K_H))
  307.     {
  308.         CommandUse(playerid,H);
  309.     }
  310.     return 1;
  311. }
  312.  
  313. stock CommandUse(playerid,key)
  314. {
  315.     switch(pKey[playerid][key])
  316.     {
  317.         case 1: Zinute(playerid);
  318.         case 2: GautiHP(playerid);
  319.         case 3: GautiArmor(playerid);
  320.     }
  321. }  
  322.  
  323. SaveInfo(playerid)
  324. {
  325.     new string[128];
  326.     format(string,sizeof(string),"Bind/%s.txt",pName(playerid));
  327.     dini_IntSet(string,"TAB",pKey[playerid][TAB]);
  328.     dini_IntSet(string,"C",pKey[playerid][C]);
  329.     dini_IntSet(string,"LMB",pKey[playerid][LMB]);
  330.     dini_IntSet(string,"SPACE",pKey[playerid][SPACE]);
  331.     dini_IntSet(string,"ENTER",pKey[playerid][ENTER]);
  332.     dini_IntSet(string,"LSHIFT",pKey[playerid][LSHIFT]);
  333.     dini_IntSet(string,"NUM1",pKey[playerid][NUM1]);
  334.     dini_IntSet(string,"NUM8",pKey[playerid][NUM8]);
  335.     dini_IntSet(string,"NUM2",pKey[playerid][NUM2]);
  336.     dini_IntSet(string,"NUM4",pKey[playerid][NUM4]);
  337.     dini_IntSet(string,"NUM6",pKey[playerid][NUM6]);
  338.     dini_IntSet(string,"Y",pKey[playerid][Y]);
  339.     dini_IntSet(string,"N",pKey[playerid][N]);
  340.     dini_IntSet(string,"H",pKey[playerid][H]);
  341. }
Advertisement
Add Comment
Please, Sign In to add comment