SA-MP Forums Archive
How to remove player's weapon? - 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 remove player's weapon? (/showthread.php?tid=216069)



How to remove player's weapon? - Outcast - 24.01.2011

Well, I am creating an RP game mode and I want to player be able to only hold 4 weapons on him (different types). I divided where which weapon slot would go. I have primary weapon, secondary, meelee, special. I made a function that when player is given a weapon it is supposed to check if the player has a weapon of that slot. But, when I give player a weapon, his old weapon (let's say M4) stays there, and he is given a new "primary" weapon (let's say a Sawn-Off).

Here's the code:

pawn Код:
public GivePlayerWeapons(senderid, playeridcheck, giveplayerweaponid)
{
    for (new i = 0; i < 13; i++) // START THE LOOP TO CHECK WEAPONS
    {
        new tmpweapid, tmpweapammo;
        GetPlayerWeaponData(playeridcheck, i, tmpweapid, tmpweapammo);
        //FOR SLOT 1 - PRIMARY WEAPON
        if(i == 3 || i == 4 || i == 5 || i == 6 || i == 7)
            {
            GivePlayerWeapon(playeridcheck, tmpweapid, 0); // << to remove a weapon ???
            GivePlayerWeapon(playeridcheck, giveplayerweaponid, 999);
            }
        else
        {
        GivePlayerWeapon(playeridcheck, giveplayerweaponid, 999);
        }
    }
}
Also, how to make it if player has ammo in it he would get his weapon removed/replaced, and if not he would just get a new weapon?


Re: How to remove player's weapon? - Jefff - 24.01.2011

Where is senderid used?
pawn Код:
public GivePlayerWeapons(senderid, playeridcheck, giveplayerweaponid)
{
    for (new i = 0; i < 13; i++) // START THE LOOP TO CHECK WEAPONS
    {
        new tmpweapid, tmpweapammo;
        GetPlayerWeaponData(playeridcheck, i, tmpweapid, tmpweapammo);
        //FOR SLOT 1 - PRIMARY WEAPON
        if(3 <= i <= 7)
        {
            if(tmpweapammo > 0) {
                GivePlayerWeapon(playeridcheck, tmpweapid, -tmpweapammo); // << to remove a weapon ???
                GivePlayerWeapon(playeridcheck, giveplayerweaponid, 999);
            }
        }
        else
        {
            GivePlayerWeapon(playeridcheck, giveplayerweaponid, 999);
        }
    }
}