Scripting/Squirrel/Functions/Player.GiveWeapon: Difference between revisions

From Vice City Multiplayer
Jump to navigation Jump to search
Caution icon
This wiki is using an old backup from 2020
Some information may be old/missing
(This function will give player a new weapon without resetting old weapons)
No edit summary
 
(One intermediate revision by one other user not shown)
Line 12: Line 12:
function onPlayerCommand( player, cmd, text );
function onPlayerCommand( player, cmd, text );
{
{
if ( cmd == "givewep" )
else if ( cmd == "givewep" )
{
    {
if(!text) MessagePlayer( "[#ffffff]syntax - /givewep <playerID> <wepID>", player );
    if(!text) MessagePlayer( "[#ffffff]syntax - /givewep <playerName> <wepID>", player );
else
    else
{
    {
local params = split( text, " " ), plr = FindPlayer(params[0]), wep = params[1];
    local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
if(!plr) MessagePlayer( "[#ffffff]Error - invalid player", player );
    if(!plr) MessagePlayer( "[#ffffff]Error - invalid player", player );
else if(!wep || GetWeaponName(wep.tointeger()) == "Unknown") MessagePlayer( "[#ffffff]Error - invalid wep ID", player );
    else if(!wep || GetWeaponName(wep.tointeger()) == "Unknown") MessagePlayer( "[#ffffff]Error - invalid wep ID", player );
else {
else
plr.GiveWeapon(wep.tointeger(), 500);
{
MessagePlayer( "[#DC26FF]"+GetWeaponName(wep.tointeger())+" has given to you",plr);
                plr.GiveWeapon(wep.tointeger(), 500);
MessagePlayer( "[#DC26FF]"+GetWeaponName(wep.tointeger())+" has given to"+plr.Name,player);
                MessagePlayer( "[#DC26FF]"+GetWeaponName(wep.tointeger())+" has given to you",plr);
}
                MessagePlayer( "[#DC26FF]"+GetWeaponName(wep.tointeger())+" has given to"+plr.Name,player);
}
            }
}
        }
    }
}
}
</source>
</source>
Line 32: Line 33:
=== Notes ===
=== Notes ===
Call [[Scripting/Squirrel/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them in the corresponding pages.
Call [[Scripting/Squirrel/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them in the corresponding pages.
== Related Functions ==
{{Scripting/Squirrel/Functions/Player_Functions}}
[[Category:Scripting/Squirrel/Functions/Player_Functions]]

Latest revision as of 18:48, 30 January 2017

Syntax

player.GiveWeapon( WeaponID, Ammo );

Arguments

> Player - The player instance.

  • integer WeaponID - The ID of weapon you want. you can get IDs here Weapons
  • integer Ammo - The Ammo amount you want.
function onPlayerCommand( player, cmd, text );
{
	else if ( cmd == "givewep" )
    {
    if(!text) MessagePlayer( "[#ffffff]syntax - /givewep <playerName> <wepID>", player );
    else
    {
    local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
    if(!plr) MessagePlayer( "[#ffffff]Error - invalid player", player );
    else if(!wep || GetWeaponName(wep.tointeger()) == "Unknown") MessagePlayer( "[#ffffff]Error - invalid wep ID", player );
else
 {
                plr.GiveWeapon(wep.tointeger(), 500);
                MessagePlayer( "[#DC26FF]"+GetWeaponName(wep.tointeger())+" has given to you",plr);
                MessagePlayer( "[#DC26FF]"+GetWeaponName(wep.tointeger())+" has given to"+plr.Name,player);
            }
        }
    }
}

Notes

Call onPlayerCommand were used in this example. More info about them in the corresponding pages.

Related Functions

Player Game Functions

These functions exist for compatibility with the R2 Squirrel server.