FerrariL

System Weapons

Oct 12th, 2018
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.36 KB | None | 0 0
  1.  
  2. #include <a_samp>
  3. #include <DOF2>
  4. #include <Zcmd>
  5.  
  6. #define FOLDER_WEAPONS                                                          "Weapons/%s.ini"
  7.  
  8. #define SaveStats                                                               0
  9. #define GetStats                                                                1
  10.  
  11. const  DIALOG_WEAPONS = 1000;
  12.  
  13. enum WEAPON_DATA
  14. {
  15.     WEAPON_ID,
  16.     WEAPON_AMMUNITION,
  17.     WEAPON_NAME[40]
  18. };
  19.  
  20. static const WEAPON_DATA_PLAYER[][WEAPON_DATA] =
  21. {
  22.     { 24, 500,      "Desert"        },
  23.     { 25, 500,      "Escopeta"      },
  24.     { 29, 500,      "MP - 5"        },
  25.     { 30, 1500,     "AK - 47"       },
  26.     { 31, 1500,     "M4"            },
  27.     { 27, 500,      "SPAS - 12"     },
  28.     { 34, 500,      "Snipe Rifle"   },
  29.     { 16,   3,      "Granada"       },
  30.     { 9,  999,      "MotoSerra"     }
  31. };
  32.  
  33. new bool: IsWeaponActived[MAX_PLAYERS][sizeof(WEAPON_DATA_PLAYER)], Name[MAX_PLAYERS][MAX_PLAYER_NAME];
  34.  
  35. public OnFilterScriptInit()
  36. {
  37.     print("\n--------------------------------------");
  38.    
  39.     print("System Weapons Spawn");
  40.     print("Development By: FerrariL\n");
  41.    
  42.     print("\n--------------------------------------");
  43.    
  44.     return 1;
  45. }
  46.  
  47. public OnFilterScriptExit()
  48. {
  49.     DOF2_Exit();
  50.    
  51.     return 1;
  52. }
  53.  
  54. public OnPlayerConnect(playerid)
  55. {
  56.     GetPlayerName(playerid, Name[playerid], MAX_PLAYER_NAME);
  57.    
  58.     WeaponsVerify(playerid);
  59.    
  60.     WeaponsAcess(playerid, GetStats);
  61.    
  62.     return 1;
  63. }
  64.  
  65. public OnPlayerDisconnect(playerid, reason)
  66. {
  67.     WeaponsAcess(playerid, SaveStats);
  68.    
  69.     return 1;
  70. }
  71.  
  72. public OnPlayerSpawn(playerid)
  73. {
  74.     SetPlayerWeapon(playerid);
  75.    
  76.     return 1;
  77. }
  78.  
  79. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  80. {
  81.     if(dialogid == DIALOG_WEAPONS)
  82.     {
  83.         if(response)
  84.         {
  85.             IsWeaponActived[playerid][listitem] = !IsWeaponActived[playerid][listitem];
  86.            
  87.             DialogWeapons(playerid);
  88.         }
  89.        
  90.         return 1;
  91.     }
  92.  
  93.     return 0;
  94. }
  95.  
  96. CMD:armas(playerid)
  97.     return DialogWeapons(playerid);
  98.    
  99. DialogWeapons(playerid)
  100. {
  101.     new Message[295];
  102.  
  103.     strcat(Message,"Arma\tStatus\n");
  104.  
  105.     for(new i = 0; i < 9; i++)
  106.         format(Message, sizeof(Message), "%s\n %s\t%s\n", Message, WEAPON_DATA_PLAYER[i][WEAPON_NAME], IsWeaponActived[playerid][i]  ? ("{3a8423}Habilitado") : ("{ba1d22}Desabilitado"));
  107.  
  108.     return ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_TABLIST_HEADERS, "Armas", Message, "Selecionar", "Sair");
  109. }
  110.  
  111. SetPlayerWeapon(playerid)
  112. {
  113.     for(new i = 0; i < sizeof(WEAPON_DATA_PLAYER); i++)
  114.     {
  115.         if(!IsWeaponActived[playerid][i])
  116.             continue;
  117.  
  118.         GivePlayerWeapon(playerid, WEAPON_DATA_PLAYER[i][WEAPON_ID], WEAPON_DATA_PLAYER[i][WEAPON_AMMUNITION]);
  119.     }
  120. }
  121.  
  122. GetFolderPlayer(playerid)
  123. {
  124.     new File[37];
  125.  
  126.     format(File, sizeof(File), FOLDER_WEAPONS, Name[playerid]);
  127.  
  128.     return File;
  129. }
  130.  
  131. WeaponsVerify(playerid)
  132. {
  133.     new Aux[60];
  134.  
  135.     if(!DOF2_FileExists( GetFolderPlayer(playerid) ))
  136.     {
  137.         DOF2_CreateFile( GetFolderPlayer(playerid) );
  138.  
  139.         for(new i = 0; i < sizeof(WEAPON_DATA_PLAYER); i++)
  140.         {
  141.             format(Aux, sizeof(Aux), "Status Arma %d", i);
  142.            
  143.             DOF2_SetBool(GetFolderPlayer(playerid), Aux, IsWeaponActived[playerid][i]);
  144.         }
  145.     }
  146. }
  147.  
  148. WeaponsAcess(playerid, Acess)
  149. {
  150.     new Aux[60];
  151.  
  152.     for(new i = 0; i < sizeof(WEAPON_DATA_PLAYER); i++)
  153.     {
  154.         format(Aux, sizeof(Aux), "Status Arma %d", i);
  155.  
  156.         if(Acess == SaveStats)
  157.  
  158.             DOF2_SetBool(GetFolderPlayer(playerid), Aux, IsWeaponActived[playerid][i]);
  159.  
  160.         else
  161.  
  162.             IsWeaponActived[playerid][i] = DOF2_GetBool(GetFolderPlayer(playerid), Aux);
  163.     }
  164.  
  165.     DOF2_SaveFile();
  166. }
Advertisement
Add Comment
Please, Sign In to add comment