OnClientPlayerWeaponSwitch: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (grammar)
 
(16 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[[Category:Incomplete Event]]
__NOTOC__
{{Client event}}
This event is triggered whenever the local player's equipped '''[[weapon|weapon slot]]''' changes. This means giveWeapon and takeWeapon will trigger this event if the equipped slot is forced to change.


__NOTOC__
==Parameters==
This event is blahblah and is used for blahblah.
 
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onClientPlayerWeaponSwitch ( int previous, int current )
int previousWeaponSlot, int currentWeaponSlot
</syntaxhighlight>  
</syntaxhighlight>  
*'''previousWeaponSlot''': An integer representing the previous [[weapon|weapon slot]] the player had before he switched.
*'''currentWeaponSlot''': An integer representing the new [[weapon|weapon slot]] the player has after he switched.
==Source==
The [[event system#Event source|source]] of this event is the [[player]] who switched their weapon (Local player only)
==Cancel effect==
If this event is canceled, then the weapon will not be switched.


==Example==  
==Example==  
This example does...
This example disables the use of aiming for the minigun.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function disableMinigunOnSwitch(prevSlot, curSlot)
blabhalbalhb --abababa
if getPedWeapon(localPlayer, curSlot) == 38 then --if the switched weapon is the minigun
--This line does this...
toggleControl("aim_weapon", false) --disable the aim button
mooo
else --if it isnt the minigun
toggleControl("aim_weapon", true) --renable the aim button
end
end
addEventHandler("onClientPlayerWeaponSwitch", localPlayer, disableMinigunOnSwitch)
</syntaxhighlight>
</syntaxhighlight>
==See Also==
===Client player events===
{{Client_player_events}}
===Client event functions===
{{Client_event_functions}}

Latest revision as of 07:48, 1 March 2021

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

Parameters

int previousWeaponSlot, int currentWeaponSlot
  • previousWeaponSlot: An integer representing the previous weapon slot the player had before he switched.
  • currentWeaponSlot: An integer representing the new weapon slot the player has after he switched.

Source

The source of this event is the player who switched their weapon (Local player only)

Cancel effect

If this event is canceled, then the weapon will not be switched.

Example

This example disables the use of aiming for the minigun.

function disableMinigunOnSwitch(prevSlot, curSlot)
	if getPedWeapon(localPlayer, curSlot) == 38 then --if the switched weapon is the minigun
		toggleControl("aim_weapon", false) --disable the aim button
	else --if it isnt the minigun
		toggleControl("aim_weapon", true) --renable the aim button
	end
end
addEventHandler("onClientPlayerWeaponSwitch", localPlayer, disableMinigunOnSwitch)

See Also

Client player events


Client event functions

Shared