OnClientWeaponFire

From Multi Theft Auto: Wiki
Revision as of 09:39, 21 March 2007 by PhatLooser (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This event is triggered when a player switches weapons.

Syntax

void onClientWeaponFire ( [[weapon]] weapon, int ammo, int ammoInClip, float fX, float fY, float fZ, [[element]] hitElement )

Variables

  • The source of this event is (clientside) the player which fired the gun.
  • weapon: An integer representing the weapon that was fired
  • ammo: An integer representing the remaining ammo
  • ammoInClip: An integer representing the remaining ammo in clip
  • fx fy fz: The coordinates where the shot hit
  • hitElement: Returns the element hit. Value is nil if nothing was hit.


Example

This example calls server events, when an object was hit, or the player shot at something with a special gun.

--add an event handler for onClientWeaponFire
addEventHandler ( "onClientWeaponFire", getRootElement (), "gunfire" )
function gunfire ( weapon, ammo, ammoInClip, fX, fY, fZ, hitElement )
         --something was hit?
	if ( hitElement ~= nil ) then
	   triggerServerEvent( "object_hit" , getLocalPlayer () , hitElement )
        end
         -- filters if the player himself shot the gun, and if its weapon 33
	 if source == getLocalPlayer () and weapon == 33 then
	   triggerServerEvent( "teleport_me" , getLocalPlayer () , fX, fY, fZ  )
         end
end

See Also