OnPlayerWeaponSwitch: Difference between revisions
Jump to navigation
Jump to search
JonChappell (talk | contribs) No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This event is triggered when a player switches weapons. | This event is triggered when a player switches weapons. | ||
Line 8: | Line 6: | ||
void onPlayerWeaponSwitch ( int previousWeaponID, int currentWeaponID ) | void onPlayerWeaponSwitch ( int previousWeaponID, int currentWeaponID ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Variables== | |||
*'''previousWeaponID''': An integer representing the weapon that was switched from | |||
*'''currentWeaponID''': An integer representing the weapon that was switched to | |||
==Example== | ==Example== | ||
This example | This example disables use of the minigun | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | --add an event handler for onPlayerWeaponSwitch | ||
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), "weaponSwitchDisableMinigun" ) | |||
-- | 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 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | |||
{{Event_functions}} |
Revision as of 14:34, 2 December 2006
This event is triggered when a player switches weapons.
Syntax
void onPlayerWeaponSwitch ( int previousWeaponID, int currentWeaponID )
Variables
- previousWeaponID: An integer representing the weapon that was switched from
- currentWeaponID: An integer representing the weapon that was switched to
Example
This example disables use of the minigun
--add an event handler for onPlayerWeaponSwitch addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), "weaponSwitchDisableMinigun" ) 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
See Also
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled