3 Weapon Limit - 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)
+--- Thread: 3 Weapon Limit (
/showthread.php?tid=586429)
3 Weapon Limit -
Krakuski - 22.08.2015
Howdy. I was wondering how I would be able to make it so people would only be allowed to hold 1 sidearm, 1 heavy and 1 melee weapon and restrict them from obtaining anymore.
Thanks.
Re: 3 Weapon Limit -
Abagail - 22.08.2015
You can hook GivePlayerWeapon and add in checks which loop through GetPlayerWeaponData.
Re: 3 Weapon Limit -
Krakuski - 22.08.2015
Perhaps you can give me an example?
Re: 3 Weapon Limit -
Abagail - 22.08.2015
pawn Код:
#include <a_samp>
#define WEAPONTYPE_UNDEFINED 0
#define WEAPONTYPE_HANDGUN 1
#define WEAPONTYPE_SHOTGUN 2
stock GivePlayerWeaponEx(playerid, weaponid, ammo)
{
new weapons[14], ammo[14];
for(new i; i < 14; i++)
{
GetPlayerWeaponData(playerid, weapons[i], ammo[i]);
if(GetWeaponType(weaponid) == GetWeaponType(weapons[i]) && GetWeaponSlot(i) != weapons[i])
{
return 1;
}
}
GivePlayerWeapon(playerid, weaponid, ammo);
return 1;
}
#if defined _ALS_GivePlayerWeapon
#undef GivePlayerWeapon
#else
#define _ALS_GivePlayerWeapon
#endif
#define GivePlayerWeapon GivePlayerWeaponEx
GetWeaponType(weaponid)
{
new type;
switch(weaponid)
{
case 23, 24: type = WEAPONTYPE_HANDGUN;
case 25, 30, 31: type = WEAPONTYPE_SHOTGUN;
default: type = WEAPONTYPE_UNDEFINED;
}
return 1;
}
stock GetWeaponSlot(weaponid)
{
new slot;
switch(weaponid)
{
case 0,1: slot = 0;
case 2 .. 9: slot = 1;
case 10 .. 15: slot = 10;
case 16 .. 18, 39: slot = 8;
case 22 .. 24: slot =2;
case 25 .. 27: slot = 3;
case 28, 29, 32: slot = 4;
case 30, 31: slot = 5;
case 33, 34: slot = 6;
case 35 .. 38: slot = 7;
case 40: slot = 12;
case 41 .. 43: slot = 9;
case 44 .. 46: slot = 11;
}
return slot;
}
The GetWeaponType function isn't complete; you'll need to finish it. By returning 1 in the hook the actual GivePlayerWeapon function doesn't get called and the player won't get the weapon. So if they are currently holding a shotgun and you attempt to give an M4, nothing happens.
Re: 3 Weapon Limit -
Krakuski - 22.08.2015
Thank you, Rep+