OnClientPlayerWeaponFire: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Removed depreciated tag)
Line 27: Line 27:
-- Add this as a handler so that the function will be triggered every time the local player fires.
-- Add this as a handler so that the function will be triggered every time the local player fires.
addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFireFunc )
addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFireFunc )
</syntaxhighlight>
This example makes the Shotgun fire explosive rounds.
<syntaxhighlight lang="lua">
function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement)
    if (weapon == 25) then -- If the player shoots with a shotgun
        createExplosion(hitX, hitY, hitZ, 12, true, false, true) -- Creates a tiny explosion where the bullet hit.
    end
end
-- Add this as a handler so that the function will be triggered every time a player fires.
addEventHandler("onClientPlayerWeaponFire", root, onClientPlayerWeaponFireFunc)
</syntaxhighlight>
</syntaxhighlight>



Revision as of 13:23, 7 August 2010

This event is called when player shoots a weapon. This does not trigger for projectiles based, or melee weapons. Also note that this event is only triggered for players nearby the local player's camera. This is due to elements far away being streamed out.

Parameters

int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement
  • weapon: an int representing weapon used for making a shot.
  • ammo: an int ammount of ammo left for this weapon type.
  • ammoInClip: an int ammount of ammo left for this weapon type in clip.
  • hitX, hitY, hitZ: float world coordinates representing a hit point.
  • hitElement: an element which was hit by a shot.

Source

The source of this event is the player who fired the weapon.

Example

This example sends a warning to the local player if they shoot another player with a minigun.

--First, we create a function for the event handler to use.
function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement )
    if weapon == 38 and getElementType(hitElement)=="player" then -- If the player shoots with a minigun, and hits another player...
         outputChatBox ( "Don't kill people with minigun, it's lame!", 255, 0, 0 ) -- We output a warning to him.
    end
end
-- Add this as a handler so that the function will be triggered every time the local player fires.
addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFireFunc )

This example makes the Shotgun fire explosive rounds.

function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement)
    if (weapon == 25) then -- If the player shoots with a shotgun
        createExplosion(hitX, hitY, hitZ, 12, true, false, true) -- Creates a tiny explosion where the bullet hit.
    end
end
-- Add this as a handler so that the function will be triggered every time a player fires.
addEventHandler("onClientPlayerWeaponFire", root, onClientPlayerWeaponFireFunc)

See Also

Client player events


Client event functions