OnPlayerWeaponSwitch: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server event}}
{{Server event}}
This event is triggered when a player switches weapons.
This event is triggered whenever a player's equipped weapon '''slot''' changes. This means giveWeapon and takeWeapon will trigger this function if the equipped slot is forced to change.  


==Parameters==  
==Parameters==  

Revision as of 05:33, 7 December 2010

This event is triggered whenever a player's equipped weapon slot changes. This means giveWeapon and takeWeapon will trigger this function if the equipped slot is forced to change.

Parameters

int previousWeaponID, int currentWeaponID
  • previousWeaponID: An integer representing the weapon that was switched from
  • currentWeaponID: An integer representing the weapon that was switched to

Source

The source of this event is the player that switched his weapon.

Example

This example disables use of the minigun upon switch. It should be noted that this can be done more efficiently clientside.

function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID ) --when a player switches his weapon
     if currentWeaponID == 38 then --if the weapon ID is minigun
          toggleControl ( source, "fire", false ) --disable the fire button
     else --otherwise
          toggleControl ( source, "fire", true )  --enable it
     end
end
--add an event handler for onPlayerWeaponSwitch
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitchDisableMinigun )

See Also

Player events


Event functions