SA-MP Forums Archive
help with scripting this! - 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: help with scripting this! (/showthread.php?tid=559616)



help with scripting this! - Puff - 24.01.2015

Hi I want to make if person have gun id 27 it automatically remove it and replace it with M4 anyone can do that?!


Re: help with scripting this! - nezo2001 - 24.01.2015

PHP код:
public OnPlayerUpdate(playerid)
{
if(
GetPlayerWeapon(playerid) == 27)
{
GivePlayerWeapon(playerid,270);
GivePlayerWeapon(playerid,31,5000);//amount of ammo you want replace it with 5000
}
    return 
1;

Try this


Re: help with scripting this! - ATGOggy - 24.01.2015

PHP код:
stock RemovePlayerWeapon(playeridpweaponid)
{
        new 
plyWeapons[12];
        new 
plyAmmo[12];
 
        for(new 
slot 0slot != 12slot++)
        {
                new 
pweppammo;
                
GetPlayerWeaponData(playeridslotpweppammo);
 
                if(
pwep != pweaponid)
                {
                        
GetPlayerWeaponData(playeridslotplyWeapons[slot], plyAmmo[slot]);
                }
        }
 
        
ResetPlayerGuns(playerid);
        for(new 
slot 0slot != 12slot++)
        {
                
GivePlayerGun(playeridplyWeapons[slot], plyAmmo[slot]);
        }

PHP код:
public OnPlayerUpdate(playerid)
{
    new 
weaponammo;
    
GetPlayerWeaponData(playerid3weaponammo);
    if(
weapon==27)
    {
         
RemovePlayerWeapon(playerid27);
         
GivePlayerWeapon(playeridWEAPON_M4100);
    }




Re: help with scripting this! - Puff - 24.01.2015

Thanks both of you! +REP


Re: help with scripting this! - ATGOggy - 24.01.2015

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
PHP код:
public OnPlayerUpdate(playerid)
{
if(
GetPlayerWeapon(playerid) == 27)
{
GivePlayerWeapon(playerid,270);
GivePlayerWeapon(playerid,31,5000);//amount of ammo you want replace it with 5000
}
    return 
1;

Try this
Giving player 0 ammo doesn't remove his current weapon.
Also, your code gets the weapon that he is holding in his hand not the one he posses.


Re: help with scripting this! - nezo2001 - 24.01.2015

Ok but it will work when the player get the weapon and when the player get the weapon the weapon become in his hand !


Re: help with scripting this! - ATGOggy - 24.01.2015

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
Ok but it will work when the player get the weapon and when the player get the weapon the weapon become in his hand !
But it wont remove the weapon as weapon id 27 and M4 are in different slots.