OnPlayerWeaponSwitch: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[[Category:Incomplete Event]]
__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 does...
This example disables use of the minigun
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
--add an event handler for onPlayerWeaponSwitch
blabhalbalhb --abababa
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), "weaponSwitchDisableMinigun" )
--This line does this...
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID ) --when a player switches his weapon
mooo
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

Shared