SetPlayerArmedWeapon

From SA-MP Wiki

Jump to: navigation, search


SetPlayerArmedWeapon was added in SA-MP 0.3a This function was added in SA-MP 0.3a and will not work in earlier versions!


Description:

Sets which weapon (that a player already has) the player is holding.


Parameters:
(playerid, weaponid)
playeridThe ID of the player to arm with a weapon.
weaponidThe ID of the weapon that the player should be armed with.


Return Values:

  • 1: The function executed successfully. Success is returned even when the function fails to execute (the player doesn't have the weapon specified, or it is an invalid weapon).
  • 0: The function failed to execute. The player is not connected.


Image:32px-Ambox_warning_orange.png

Note

This function arms a player with a weapon they already have; it does not give them a new weapon. See GivePlayerWeapon.


Example Usage:

public OnPlayerUpdate(playerid)
{
    SetPlayerArmedWeapon(playerid,0); // disables weapons
    return 1;
}
// SMG driveby by [03]Garsino (for SA:MP 0.3c)
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new weapon, ammo;
        GetPlayerWeaponData(playerid, 4, weapon, ammo); // Get the players SMG weapon in slot 4
        SetPlayerArmedWeapon(playerid, weapon); // Set the player to driveby with SMG
    }
    return 1;
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.

In other languages