Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <YSI\y_ini>
- #include <YSI\y_inline>
- enum pWeaponsDialog
- {
- pName[25],
- pID,
- pAmmo,
- pPrice
- };
- new WeaponsDialog[][pWeaponsDialog] =
- {
- //{"", ID, Ammo, Price}
- {"אגרופן", 1, 1, 120},
- {"Knife", 4, 1, 100},
- {"9mm", 22, 50, 250},
- {"Silenced 9mm", 23, 50, 250},
- {"Desert Eagle", 24, 50, 250},
- {"Shotgun", 25, 50, 250},
- {"Sawn Off", 26, 300, 2400},
- {"Combat Shotgun", 27, 300, 2400},
- {"AK-47", 30, 500, 1000},
- {"M4", 31, 500, 10000},
- {"Tec-9", 32, 200, 600},
- {"Country Rifle", 33, 800, 8000},
- {"Sniper Rifle", 34, 1300, 8500},
- {"MiniGun", 38, 3000, 25000}
- };
- enum pPlayerWeapons
- {
- pSlot,
- pAmmo
- };
- new PWeapons[MAX_PLAYERS][pPlayerWeapons][12];
- new PName[MAX_PLAYERS][MAX_PLAYER_NAME + 1];
- new gString[2048];
- #define FILTERSCRIPT
- public OnPlayerConnect(playerid)
- {
- GetPlayerName(playerid, PName[playerid], MAX_PLAYER_NAME + 1);
- if(fexist(PWeaponFile(playerid))) INI_ParseFile(PWeaponFile(playerid), using inline "PLoadWeaponFile");
- inline PLoadWeaponFile(string: name[], string: value[])
- {
- for(new i; i < 12; i++)
- {
- gString[0] = EOS;
- format(gString, 64, "Slot%02d", i);
- INI_Int(gString, PWeapons[playerid][pSlot][i]);
- gString[0] = EOS;
- format(gString, 64, "Ammo%02d", i);
- INI_Int(gString, PWeapons[playerid][pAmmo][i]);
- }
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- SavePlayerAllWeapons(playerid);
- for(new i; i < 12; i++)
- {
- new INI:pFile = INI_Open(PWeaponFile(playerid));
- gString[0] = EOS;
- format(gString, 64, "Slot%02d", i);
- INI_WriteInt(pFile, gString, PWeapons[playerid][pSlot][i]);
- gString[0] = EOS;
- format(gString, 64, "Ammo%02d", i);
- INI_WriteInt(pFile, gString, PWeapons[playerid][pAmmo][i]);
- INI_Close(pFile);
- }
- PName[playerid][0] = EOS;
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(fexist(PWeaponFile(playerid)))
- {
- SavePlayerAllWeapons(playerid);
- ResetPlayerWeapons(playerid);
- LoadPlayerWeapons(playerid);
- }
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(fexist(PWeaponFile(playerid)))
- {
- SavePlayerAllWeapons(playerid);
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!strcmp(cmdtext, "/Ammo", true))
- {
- format(gString, sizeof gString, "");
- for(new i = 0; i < sizeof WeaponsDialog; i++)
- {
- 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]));
- ShowPlayerDialog(playerid, 4000, DIALOG_STYLE_LIST, "{FFFF00}קניית נשקים", gString, "אישור", "ביטול");
- }
- return 1;
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == 4000)
- {
- if(!response) return ShowPlayerDialog(playerid, 4001, DIALOG_STYLE_MSGBOX, "{FFFF00}קניית נשקים", "? האם ברצונך לצאת מקניית הנשקים", "חזור", "ביטול");
- if(GetPlayerMoney(playerid) < WeaponsDialog[listitem][pPrice]) return ShowPlayerDialog(playerid, 4001, DIALOG_STYLE_MSGBOX, "{FFFF00}קניית נשקים", ".אין לך מספיק כסף בשביל נשק זה\n? האם ברצונך לחזור לדיאלוג הנשקים", "חזור", "אישור");
- GivePlayerMoney(playerid, -WeaponsDialog[listitem][pPrice]);
- GivePlayerWeapon(playerid, WeaponsDialog[listitem][pID], WeaponsDialog[listitem][pAmmo]);
- SavePlayerWeapon(playerid, GetWeaponSlot(WeaponsDialog[listitem][pID]));
- format(gString, 256, "{FFFF00}.$%s במחיר של \"%s\" קנית את הנשק\n? האם ברצונך לחזור לדיאלוג הנשקים", WeaponsDialog[listitem][pPrice], WeaponsDialog[listitem][pName]);
- ShowPlayerDialog(playerid, 4001, DIALOG_STYLE_MSGBOX, "{FFFF00}קניית נשקים", gString, "חזור", "ביטול");
- }
- if(dialogid == 4001)
- {
- if(response)
- {
- format(gString, sizeof gString, "");
- for(new i = 0; i < sizeof WeaponsDialog; i++)
- {
- 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]));
- ShowPlayerDialog(playerid, 4000, DIALOG_STYLE_LIST, "{FFFF00}קניית נשקים", gString, "אישור", "ביטול");
- }
- }
- }
- return 1;
- }
- stock GetWeaponSlot(weaponid)
- {
- switch (weaponid)
- {
- case 0, 1: return 0;
- case 2 .. 9: return 1;
- case 22 .. 24: return 2;
- case 25 .. 27: return 3;
- case 28, 29, 32: return 4;
- case 30, 31: return 5;
- case 33, 34: return 6;
- case 35 .. 38: return 7;
- case 16, 18, 39: return 8;
- case 42, 43: return 9;
- case 14 : return 10;
- case 44 .. 46: return 11;
- case 40 : return 12;
- }
- return 0;
- }
- stock SavePlayerWeapon(playerid, slot)
- {
- new szWeapon[2];
- GetPlayerWeaponData(playerid, slot, szWeapon[0], szWeapon[1]);
- PWeapons[playerid][pSlot][slot] = szWeapon[0];
- PWeapons[playerid][pAmmo][slot] = szWeapon[1];
- return 1;
- }
- stock SavePlayerAllWeapons(playerid)
- {
- new szWeapons[2][12];
- for(new i; i < 12; i++)
- {
- GetPlayerWeaponData(playerid, i, szWeapons[0][i], szWeapons[1][i]);
- PWeapons[playerid][pSlot][i] = szWeapons[0][i];
- PWeapons[playerid][pAmmo][i] = szWeapons[1][i];
- }
- return 1;
- }
- stock LoadPlayerWeapons(playerid)
- {
- for(new i; i < 12; i++) \
- GivePlayerWeapon(playerid, PWeapons[playerid][pSlot][i], PWeapons[playerid][pAmmo][i]);
- return 1;
- }
- stock PWeaponFile(playerid)
- {
- new szPath[64];
- format(szPath, sizeof szPath, "Weapons/%s.ini", PName[playerid]);
- return szPath;
- }
- stock AddCommas(num)
- {
- new string[64];
- format(string, sizeof(string), "%d", num);
- for(new idx = strlen(string) % 3 == 0 ? 3 : strlen(string) % 3; idx < strlen(string); idx += 4) strins(string, ",", idx);
- return string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement