How to compare if a player has a weapon of that type - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to compare if a player has a weapon of that type (
/showthread.php?tid=216089)
How to compare if a player has a weapon of that type -
Outcast - 24.01.2011
Well, I have a system where you can have 4 different weapons. They're saved like weapon1, ammo1, weapon2,ammo2...
The problem is if I have like 3 weapons (deagle, m4, sniper) and I get an ak-47. The M4 get's swapped for ak-47 but in the script it's still there and the ak-47 saves on the 4. position (4. weapon slot in the user file). After that, I can't get any other weapon.
This is the code:
pawn Код:
public GivePlayerWeapons(senderid, playeridcheck, giveplayerweaponid)
{
if(PlayerInfo[playeridcheck][Weapon1] == 0)
{
GivePlayerWeapon(playeridcheck, giveplayerweaponid, 100);
PlayerInfo[playeridcheck][Weapon1] = giveplayerweaponid;
return 1;
}
if(PlayerInfo[playeridcheck][Weapon2] == 0)
{
GivePlayerWeapon(playeridcheck, giveplayerweaponid, 100);
PlayerInfo[playeridcheck][Weapon2] = giveplayerweaponid;
return 1;
}
if(PlayerInfo[playeridcheck][Weapon3] == 0)
{
GivePlayerWeapon(playeridcheck, giveplayerweaponid, 100);
PlayerInfo[playeridcheck][Weapon3] = giveplayerweaponid;
return 1;
}
if(PlayerInfo[playeridcheck][Weapon4] == 0)
{
GivePlayerWeapon(playeridcheck, giveplayerweaponid, 100);
PlayerInfo[playeridcheck][Weapon4] = giveplayerweaponid;
return 1;
}
SendClientMessage(senderid, 0x935724, "That player can't hold anymore weapons");
return 1;
}