SetPlayerWeaponSlot: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 17: Line 17:


==Example==  
==Example==  
<section name="Server" class="server" show="true">
This example allows the player to type the command 'giveweapons', which gives the player a weapon for every slot. Instead of equipping the last given weapon, the script randomly decides which weapon to equip after all the weapons are given.
This example allows the player to type the command 'giveweapons', which gives the player a weapon for every slot. Instead of equipping the last given weapon, the script randomly decides which weapon to equip after all the weapons are given.
<syntaxhighlight lang="lua">function givePlayerWeapons ( player, commandName )
<syntaxhighlight lang="lua">function givePlayerWeapons ( player, commandName )
         --Give the player a weapon for each slot
         --Give the player a weapon for each slot
Line 38: Line 38:
end
end
addCommandHandler ( "giveweapons", givePlayerWeapons )</syntaxhighlight>
addCommandHandler ( "giveweapons", givePlayerWeapons )</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Revision as of 09:22, 11 October 2007

This function sets the player's weapon slot. This affects the current weapon.

Syntax

bool setPlayerWeaponSlot ( player theplayer, int weapon_slot )

Required Arguments

  • theplayer: The player whose weapon slot you want to set *No player clientside
  • weapon_slot: weapon slot to set
Weapon Slots
  • 0: WEAPONSLOT_TYPE_UNARMED
  • 1: WEAPONSLOT_TYPE_MELEE
  • 2: WEAPONSLOT_TYPE_HANDGUN
  • 3: WEAPONSLOT_TYPE_SHOTGUN
  • 4: WEAPONSLOT_TYPE_SMG (used for driveby's)
  • 5: WEAPONSLOT_TYPE_RIFLE
  • 6: WEAPONSLOT_TYPE_SNIPER
  • 7: WEAPONSLOT_TYPE_HEAVY
  • 8: WEAPONSLOT_TYPE_THROWN
  • 9: WEAPONSLOT_TYPE_SPECIAL
  • 10: WEAPONSLOT_TYPE_GIFT
  • 11: WEAPONSLOT_TYPE_PARACHUTE
  • 12: WEAPONSLOT_TYPE_DETONATOR

Returns

Returns true if successful in setting the player's equipped weapon slot, false otherwise.

Example

Click to collapse [-]
Server

This example allows the player to type the command 'giveweapons', which gives the player a weapon for every slot. Instead of equipping the last given weapon, the script randomly decides which weapon to equip after all the weapons are given.

function givePlayerWeapons ( player, commandName )
        --Give the player a weapon for each slot
	giveWeapon ( player, 1, 1 )
	giveWeapon ( player, 2, 1 )
	giveWeapon ( player, 22, 1 )
	giveWeapon ( player, 25, 1 )
	giveWeapon ( player, 28, 1 )
	giveWeapon ( player, 30, 1 )
	giveWeapon ( player, 33, 1 )
	giveWeapon ( player, 35, 1 )
	giveWeapon ( player, 16, 1 )
	giveWeapon ( player, 42, 1 )
	giveWeapon ( player, 10, 1 )
	giveWeapon ( player, 44, 1 )
	giveWeapon ( player, 40, 1 )
        --Randomly select which weapon to equip, slots 1 through 12
	setPlayerWeaponSlot ( player, math.random ( 1, 12) )
end
addCommandHandler ( "giveweapons", givePlayerWeapons )

See Also