[Tutorial] How to get the player weapon as passenger
#1

You should know that the function GetPlayerWeapon don't work for passengers, so i'll explain how to solve this problem.

First, store the player weapon when he enter in a vehicle in a PVar(or common variable).

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(ispassenger)
    {
        SetPVarInt(playerid, "HandWeapon", GetPlayerWeapon(playerid));
    }
}
Make sure that if the player receiving a gun, his pVar is updated. For this, is needed to create a function that give the player weapon and store your id.

pawn Код:
GivePlayerWeaponAndUpdate(playerid, weaponid, ammo)
{
    GivePlayerWeapon(playerid, weaponid, ammo);
    SetPVarInt(playerid, "HandWeapon", weaponid);
    return 1;
}
And finally, you need to create a function to get the player data stored in PVar, or you can use this directly.
pawn Код:
GetPlayerWeaponEx(playerid)
{
    return GetPVarInt(playerid, "HandWeapon");
}
//or simply:
GetPVarInt(playerid, "HandWeapon");
//or even, if you understand about Macros:
#define GetPlayerWeaponEx(%0) GetPVarInt(%0, "HandWeapon")
Doing this, you can get the player weapon as passenger, you can do the same thing for GetPlayerAmmo.
Reply
#2

Simple, nice tutorial could use abit more tweaking maybes.
Reply
#3

second! nice simple and useful for new scripter
Reply
#4

Yeah, I used this method for my weapon-changing-as-passenger script. The only bad thing about it is that you can change your weapon while entering the vehicle. So the script will detect the weapon you had when the callback was called.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)