Advertisement
RiseAboveHate

מערכת נשקים על ידי CanadaSoldier && CanadaSolider

Jul 9th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.04 KB | None | 0 0
  1. #include <a_samp>
  2. #include <YSI\y_ini>
  3. #include <YSI\y_inline>
  4.  
  5. enum pWeaponsDialog
  6. {
  7.     pName[25],
  8.     pID,
  9.     pAmmo,
  10.     pPrice
  11. };
  12.  
  13. new WeaponsDialog[][pWeaponsDialog] =
  14. {
  15.     //{"", ID, Ammo, Price}
  16.     {"אגרופן", 1, 1, 120},
  17.     {"Knife", 4, 1, 100},
  18.     {"9mm", 22, 50, 250},
  19.     {"Silenced 9mm", 23, 50, 250},
  20.     {"Desert Eagle", 24, 50, 250},
  21.     {"Shotgun", 25, 50, 250},
  22.     {"Sawn Off", 26, 300, 2400},
  23.     {"Combat Shotgun", 27, 300, 2400},
  24.     {"AK-47", 30, 500, 1000},
  25.     {"M4", 31, 500, 10000},
  26.     {"Tec-9", 32, 200, 600},
  27.     {"Country Rifle", 33, 800, 8000},
  28.     {"Sniper Rifle", 34, 1300, 8500},
  29.     {"MiniGun", 38, 3000, 25000}
  30. };
  31.  
  32. enum pPlayerWeapons
  33. {
  34.     pSlot,
  35.     pAmmo
  36. };
  37.  
  38. new PWeapons[MAX_PLAYERS][pPlayerWeapons][12];
  39. new PName[MAX_PLAYERS][MAX_PLAYER_NAME + 1];
  40. new gString[2048];
  41.  
  42. #define FILTERSCRIPT
  43.  
  44. public OnPlayerConnect(playerid)
  45. {
  46.     GetPlayerName(playerid, PName[playerid], MAX_PLAYER_NAME + 1);
  47.     if(fexist(PWeaponFile(playerid))) INI_ParseFile(PWeaponFile(playerid), using inline "PLoadWeaponFile");
  48.     inline PLoadWeaponFile(string: name[], string: value[])
  49.     {
  50.         for(new i; i < 12; i++)
  51.         {
  52.             gString[0] = EOS;
  53.             format(gString, 64, "Slot%02d", i);
  54.             INI_Int(gString, PWeapons[playerid][pSlot][i]);
  55.             gString[0] = EOS;
  56.             format(gString, 64, "Ammo%02d", i);
  57.             INI_Int(gString, PWeapons[playerid][pAmmo][i]);
  58.         }
  59.     }
  60.     return 1;
  61. }
  62.  
  63. public OnPlayerDisconnect(playerid, reason)
  64. {
  65.     SavePlayerAllWeapons(playerid);
  66.     for(new i; i < 12; i++)
  67.     {
  68.         new INI:pFile = INI_Open(PWeaponFile(playerid));
  69.         gString[0] = EOS;
  70.         format(gString, 64, "Slot%02d", i);
  71.         INI_WriteInt(pFile, gString, PWeapons[playerid][pSlot][i]);
  72.         gString[0] = EOS;
  73.         format(gString, 64, "Ammo%02d", i);
  74.         INI_WriteInt(pFile, gString, PWeapons[playerid][pAmmo][i]);
  75.         INI_Close(pFile);
  76.     }
  77.     PName[playerid][0] = EOS;
  78.     return 1;
  79. }
  80.  
  81. public OnPlayerSpawn(playerid)
  82. {
  83.     if(fexist(PWeaponFile(playerid)))
  84.     {
  85.         SavePlayerAllWeapons(playerid);
  86.         ResetPlayerWeapons(playerid);
  87.         LoadPlayerWeapons(playerid);
  88.     }
  89.     return 1;
  90. }
  91.  
  92. public OnPlayerDeath(playerid, killerid, reason)
  93. {
  94.     if(fexist(PWeaponFile(playerid)))
  95.     {
  96.         SavePlayerAllWeapons(playerid);
  97.     }
  98.     return 1;
  99. }
  100.  
  101. public OnPlayerCommandText(playerid, cmdtext[])
  102. {
  103.     if(!strcmp(cmdtext, "/Ammo", true))
  104.     {
  105.         format(gString, sizeof gString, "");
  106.         for(new i = 0; i < sizeof WeaponsDialog; i++)
  107.         {
  108.             format(gString, sizeof gString, "%s{FF0000}%s {FFFFFF}| {BEDB00}Ammo: %02d {FFFFFF}| {FF6200}Price: %s", gString, WeaponsDialog[i][pName], WeaponsDialog[i][pAmmo], AddCommas(WeaponsDialog[i][pPrice]));
  109.             ShowPlayerDialog(playerid, 4000, DIALOG_STYLE_LIST, "{FFFF00}קניית נשקים", gString, "אישור", "ביטול");
  110.         }
  111.         return 1;
  112.     }
  113.     return 1;
  114. }
  115.  
  116. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  117. {
  118.     if(dialogid == 4000)
  119.     {
  120.         if(!response) return ShowPlayerDialog(playerid, 4001, DIALOG_STYLE_MSGBOX, "{FFFF00}קניית נשקים", "? האם ברצונך לצאת מקניית הנשקים", "חזור", "ביטול");
  121.         if(GetPlayerMoney(playerid) < WeaponsDialog[listitem][pPrice]) return ShowPlayerDialog(playerid, 4001, DIALOG_STYLE_MSGBOX, "{FFFF00}קניית נשקים", ".אין לך מספיק כסף בשביל נשק זה\n? האם ברצונך לחזור לדיאלוג הנשקים", "חזור", "אישור");
  122.         GivePlayerMoney(playerid, -WeaponsDialog[listitem][pPrice]);
  123.         GivePlayerWeapon(playerid, WeaponsDialog[listitem][pID], WeaponsDialog[listitem][pAmmo]);
  124.         SavePlayerWeapon(playerid, GetWeaponSlot(WeaponsDialog[listitem][pID]));
  125.         format(gString, 256, "{FFFF00}.$%s במחיר של \"%s\" קנית את הנשק\n? האם ברצונך לחזור לדיאלוג הנשקים", WeaponsDialog[listitem][pPrice], WeaponsDialog[listitem][pName]);
  126.         ShowPlayerDialog(playerid, 4001, DIALOG_STYLE_MSGBOX, "{FFFF00}קניית נשקים", gString, "חזור", "ביטול");
  127.     }
  128.     if(dialogid == 4001)
  129.     {
  130.         if(response)
  131.         {
  132.             format(gString, sizeof gString, "");
  133.             for(new i = 0; i < sizeof WeaponsDialog; i++)
  134.             {
  135.                 format(gString, sizeof gString, "%s{FF0000}%s {FFFFFF}| {BEDB00}Ammo: %02d {FFFFFF}| {FF6200}Price: %s\n", gString, WeaponsDialog[i][pName], WeaponsDialog[i][pAmmo], AddCommas(WeaponsDialog[i][pPrice]));
  136.                 ShowPlayerDialog(playerid, 4000, DIALOG_STYLE_LIST, "{FFFF00}קניית נשקים", gString, "אישור", "ביטול");
  137.             }
  138.         }
  139.     }
  140.     return 1;
  141. }
  142.  
  143. stock GetWeaponSlot(weaponid)
  144. {
  145.     switch (weaponid)
  146.     {
  147.         case 0, 1: return 0;
  148.         case 2 .. 9: return 1;
  149.         case 22 .. 24: return 2;
  150.         case 25 .. 27: return 3;
  151.         case 28, 29, 32: return 4;
  152.         case 30, 31: return 5;
  153.         case 33, 34: return 6;
  154.         case 35 .. 38: return 7;
  155.         case 16, 18, 39: return 8;
  156.         case 42, 43: return 9;
  157.         case 14 : return 10;
  158.         case 44 .. 46: return 11;
  159.         case 40 : return 12;
  160.     }
  161.     return 0;
  162. }
  163.  
  164. stock SavePlayerWeapon(playerid, slot)
  165. {
  166.     new szWeapon[2];
  167.     GetPlayerWeaponData(playerid, slot, szWeapon[0], szWeapon[1]);
  168.     PWeapons[playerid][pSlot][slot] = szWeapon[0];
  169.     PWeapons[playerid][pAmmo][slot] = szWeapon[1];
  170.     return 1;
  171. }
  172.  
  173. stock SavePlayerAllWeapons(playerid)
  174. {
  175.     new szWeapons[2][12];
  176.     for(new i; i < 12; i++)
  177.     {
  178.         GetPlayerWeaponData(playerid, i, szWeapons[0][i], szWeapons[1][i]);
  179.         PWeapons[playerid][pSlot][i] = szWeapons[0][i];
  180.         PWeapons[playerid][pAmmo][i] = szWeapons[1][i];
  181.     }
  182.     return 1;
  183. }
  184.  
  185. stock LoadPlayerWeapons(playerid)
  186. {
  187.     for(new i; i < 12; i++) \
  188.         GivePlayerWeapon(playerid, PWeapons[playerid][pSlot][i], PWeapons[playerid][pAmmo][i]);
  189.     return 1;
  190. }
  191.  
  192. stock PWeaponFile(playerid)
  193. {
  194.     new szPath[64];
  195.     format(szPath, sizeof szPath, "Weapons/%s.ini", PName[playerid]);
  196.     return szPath;
  197. }
  198.  
  199. stock AddCommas(num)
  200. {
  201.     new string[64];
  202.     format(string, sizeof(string), "%d", num);
  203.     for(new idx = strlen(string) % 3 == 0 ? 3 : strlen(string) % 3; idx < strlen(string); idx += 4) strins(string, ",", idx);
  204.     return string;
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement