SetPlayerWeaponSlot: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server client function}}
{{Server client function}}
{{Deprecated}}
Please use [[setPedWeaponSlot]]
This function sets the player's weapon slot. This affects the current weapon.
This function sets the player's weapon slot. This affects the current weapon.


Line 9: Line 13:


===Required Arguments===
===Required Arguments===
*'''theplayer:''' The player whose weapon slot you want to set *''No player clientside''
*'''theplayer:''' the [[player]] whose weapon slot you want to set. In a clientside script, this can only be the local player.
*'''weapon_slot:''' weapon slot to set
*'''weapon_slot:''' the weapon slot to set.
{{Weapon_Slots}}
{{Weapon_Slots}}


Line 17: Line 21:


==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 42:
end
end
addCommandHandler ( "giveweapons", givePlayerWeapons )</syntaxhighlight>
addCommandHandler ( "giveweapons", givePlayerWeapons )</syntaxhighlight>
</section>


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

Latest revision as of 21:38, 20 April 2011

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions, but there should be a more generic way to perform what it does.


Please use setPedWeaponSlot

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. In a clientside script, this can only be the local player.
  • weapon_slot: the 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