SA-MP Forums Archive
Custom weapon, problem. - 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: Custom weapon, problem. (/showthread.php?tid=569186)



Custom weapon, problem. - Baltimore - 28.03.2015

Hello !

I have a custom weapon.
How when I switch my weapon, the object is switched too? And when I "reswitch" a weapon, the object attached to it?

Thanks !


Re : Custom weapon, problem. - Baltimore - 29.03.2015

UP, please.


Re: Custom weapon, problem. - CalvinC - 29.03.2015

There's an example for detecting that in the OnPlayerUpdate wiki page:
https://sampwiki.blast.hk/wiki/OnPlayerUpdate

And an include:
https://sampforum.blast.hk/showthread.php?tid=59771


Re : Custom weapon, problem. - Baltimore - 29.03.2015

The link of include (version 2) is dead...
At the same time it dates from 2008.


Re : Custom weapon, problem. - Baltimore - 29.03.2015

UP, please.


Re: Custom weapon, problem. - CalvinC - 29.03.2015

What about the OnPlayerUpdate example?


Re : Custom weapon, problem. - Baltimore - 29.03.2015

pawn Код:
public OnPlayerUpdate(playerid)
{
    new iCurWeap = GetPlayerWeapon(playerid); // Return the player's current weapon    
    if(iCurWeap != GetPVarInt(playerid, "iCurrentWeapon")) // If he changed weapons since the last update
    {
        // Lets call a callback named OnPlayerChangeWeapon
        OnPlayerChangeWeapon(playerid, GetPVarInt(playerid, "iCurrentWeapon"), iCurWeap);
        SetPVarInt(playerid, "iCurrentWeapon", iCurWeap);//Update the weapon variable
    }
    return 1; // Send this update to other players.
}
 
stock OnPlayerChangeWeapon(playerid, oldweapon, newweapon)
{
    new     s[128],
        oWeapon[24],
        nWeapon[24];
 
    GetWeaponName(oldweapon, oWeapon, sizeof(oWeapon));
    GetWeaponName(newweapon, nWeapon, sizeof(nWeapon));
 
    format(s, sizeof(s), "You changed weapon from %s to %s!", oWeapon, nWeapon);
 
    SendClientMessage(playerid, 0xFFFFFFFF, s);
}
I have a variable that can store the weapon in my hand, and its number of ammos.

How to change the value of the variable when I switch my weapon etc?


Re : Custom weapon, problem. - S4t3K - 29.03.2015

You must check when the player switches of weapon.

Then, when he does, simply remove the weapon attached to this slot and attah the weapon attached to the new one.

As easy as it.


Re : Custom weapon, problem. - Baltimore - 29.03.2015

Quote:
Originally Posted by S4t3K
Посмотреть сообщение
You must check when the player switches of weapon.

Then, when he does, simply remove the weapon attached to this slot and attah the weapon attached to the new one.

As easy as it.
I know, but transcribe in pawn ...


Re: Custom weapon, problem. - CalvinC - 29.03.2015

Remove it in OnPlayerChangeWeapon with that script.
We can't help about removing it, as we don't know how your code works.

And @ProBrad, go away with your spam, do you think anybody cares about moderator in your server...