OnPlayerWeaponSwitch: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
This event is triggered when a player switches weapons. | This event is triggered when a player switches weapons. | ||
== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
int previousWeaponID, int currentWeaponID | |||
</syntaxhighlight> | </syntaxhighlight> | ||
*'''previousWeaponID''': An integer representing the weapon that was switched from | *'''previousWeaponID''': An integer representing the weapon that was switched from | ||
*'''currentWeaponID''': An integer representing the weapon that was switched to | *'''currentWeaponID''': An integer representing the weapon that was switched to | ||
==Source== | |||
The [[event system#Event source|source]] of this event is the [[player]] that switched his weapon. | |||
==Example== | ==Example== | ||
This example disables use of the minigun | This example disables use of the minigun upon switch. It should be noted that this can be done more efficiently clientside. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID ) --when a player switches his weapon | function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID ) --when a player switches his weapon | ||
if currentWeaponID == 38 then --if the weapon ID is minigun | if currentWeaponID == 38 then --if the weapon ID is minigun | ||
Line 23: | Line 22: | ||
toggleControl ( source, "fire", true ) --enable it | toggleControl ( source, "fire", true ) --enable it | ||
end | end | ||
--add an event handler for onPlayerWeaponSwitch | |||
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitchDisableMinigun ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Event_functions}} | {{Event_functions}} |
Revision as of 14:22, 22 October 2007
This event is triggered when a player switches weapons.
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 --add an event handler for onPlayerWeaponSwitch addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitchDisableMinigun )
See Also
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled