OnPlayerWeaponSwitch: Difference between revisions

From Multi Theft Auto: Wiki
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.


==Syntax==  
==Parameters==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onPlayerWeaponSwitch ( int previousWeaponID, int currentWeaponID )
int previousWeaponID, int currentWeaponID
</syntaxhighlight>  
</syntaxhighlight>  


==Variables==
* The source of this event is the player who switched his weapon
*'''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">
--add an event handler for onPlayerWeaponSwitch
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), "weaponSwitchDisableMinigun" )
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

Shared