Scripting/Squirrel/Functions/Player.SetWeapon: 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
No edit summary
 
Line 6: Line 6:
== Example ==
== Example ==
<source lang="squirrel">
<source lang="squirrel">
function onPlayerCommand( player, cmd, text )
{
{
  if( cmd == "wep" || cmd == "we" )
  if( cmd == "wep" || cmd == "we" )
Line 19: Line 20:
   {
   {
     player.SetWeapon( GetWeaponID( params[i] ), 99999 ); // Get the weapon ID from its Name
     player.SetWeapon( GetWeaponID( params[i] ), 99999 ); // Get the weapon ID from its Name
     weapons = weapons + " " + GetWeaponName( GetWeaponID( params[i] ) ); // Add the weapon name to given weapon list
     weapons = weapons + ", " + GetWeaponName( GetWeaponID( params[i] ) ); // Add the weapon name to given weapon list
   }
   }
   else if( IsNum( params[i] ) && params[i].tointeger() < 33 && params[i].tointeger() > 0 ) // if ID was specified
   else if( IsNum( params[i] ) && params[i].tointeger() < 33 && params[i].tointeger() > 0 ) // if ID was specified
   {
   {
     player.SetWeapon( params[i].tointeger(), 99999 ); // Then just give player that weapon
     player.SetWeapon( params[i].tointeger(), 99999 ); // Then just give player that weapon
     weapons = weapons + " " + GetWeaponName( params[i].tointeger() ); // Get the weapon name from the ID and add it.
     weapons = weapons + ", " + GetWeaponName( params[i].tointeger() ); // Get the weapon name from the ID and add it.
   }
   }
   else MessagePlayer( "[#FF0000]Invalid Weapon Name/ID!", player ); // if the invalid ID/Name was given
   else MessagePlayer( "[#FF0000]Invalid Weapon Name/ID!", player ); // if the invalid ID/Name was given
Line 32: Line 33:
   else MessagePlayer( "[#FF0000]No weapons specified", player );
   else MessagePlayer( "[#FF0000]No weapons specified", player );
  }
  }
{
}
}


</source>
</source>

Latest revision as of 09:06, 24 November 2017

Syntax

player.SetWeapon( weaponID, Ammo );


Example

function onPlayerCommand( player, cmd, text )
{
 if( cmd == "wep" || cmd == "we" )
{
 if( !text ) return MessagePlayer( "[#FF0000]/wep <wep 1> <wep 2> <...>", player );
 else
 {
  local params = split( text, " " ); // Take out the space array
  local weapons; // Create a new null variable which will be holding the list of weapons player took.
  for( local i = 0; i <= params.len() - 1; i++ ) // since the 'len' returns value from 1 and array's starting value point is 0, we will use len() - 1 otherwise we'll receive an error.
  {
   if( !IsNum( params[i] ) && GetWeaponID( params[i] ) && GetWeaponID( params[i] ) > 0 && GetWeaponID( params[i] ) <= 32 ) // if Name was specified. 
   {
    player.SetWeapon( GetWeaponID( params[i] ), 99999 ); // Get the weapon ID from its Name
    weapons = weapons + ", " + GetWeaponName( GetWeaponID( params[i] ) ); // Add the weapon name to given weapon list
   }
   else if( IsNum( params[i] ) && params[i].tointeger() < 33 && params[i].tointeger() > 0 ) // if ID was specified
   {
    player.SetWeapon( params[i].tointeger(), 99999 ); // Then just give player that weapon
    weapons = weapons + ", " + GetWeaponName( params[i].tointeger() ); // Get the weapon name from the ID and add it.
   }
   else MessagePlayer( "[#FF0000]Invalid Weapon Name/ID!", player ); // if the invalid ID/Name was given
  }
  
  if( weapons != null ) MessagePlayer( "[#00FF00]Received weapons: [#FFFFFF]" + weapons );
  else MessagePlayer( "[#FF0000]No weapons specified", player );
 }
 }
 }

Related Functions

Player Game Functions

These functions exist for compatibility with the R2 Squirrel server.