OnClientPlayerWeaponSwitch: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(getPlayerWeapon -> getPedWeapon)
Line 18: Line 18:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function disableMinigunOnSwitch ( prevSlot, newSlot )
function disableMinigunOnSwitch ( prevSlot, newSlot )
if getPlayerWeapon(getLocalPlayer(),newSlot) == 38 then --if the switched weapon is the minigun
if getPedWeapon(getLocalPlayer(),newSlot) == 38 then --if the switched weapon is the minigun
toggleControl ( "aim_weapon", false ) --disable the aim button
toggleControl ( "aim_weapon", false ) --disable the aim button
else --if it isnt the minigun
else --if it isnt the minigun

Revision as of 18:22, 8 August 2011

This event is triggered whenever a player's equipped weapon slot changes. This means giveWeapon and takeWeapon will trigger this function 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.

Source

The source of this event is the player who changed his weapon

Example

This example disables the use of aiming for the minigun.

function disableMinigunOnSwitch ( prevSlot, newSlot )
	if getPedWeapon(getLocalPlayer(),newSlot) == 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", getRootElement(), disableMinigunOnSwitch )

See Also

Client player events


Client event functions