OnClientProjectileCreation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Replace to predefined variables.)
 
(7 intermediate revisions by 5 users not shown)
Line 6: Line 6:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element creator
element creator
</syntaxhighlight>  
</syntaxhighlight>
*'''creator:''' the [[element]] that created the projectile.


==Source==
==Source==
The [[event system#Event source|source]] of this event is the [[projectile]] that was created.
The [[event system#Event source|source]] of this event is the [[projectile]] that was created.
==Cancel effect==
This event cannot be cancelled. To remove the projectile you can use setElementPosition (somewhere far away) and then destroyElement (which makes it explode).


==Example==
==Example==
Line 17: Line 21:
outputChatBox("A projectile was created!")
outputChatBox("A projectile was created!")
end
end
addEventHandler("onClientProjectileCreation", getRootElement(), projectileCreation)
addEventHandler("onClientProjectileCreation", root, projectileCreation)
</syntaxhighlight>
</syntaxhighlight>


This will punish a player for throwing a teargas grenade. When he throws it he keeps getting warped to the location where the teargas got created, and also the teargas keeps getting warped to it. This will result in  +/-60hp loss for the creator.
This will punish a player for throwing a teargas grenade. When he throws it he keeps getting warped to the location where the teargas got created, and also the teargas keeps getting warped to it. This will result in  +/-60hp loss for the creator.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function punishSatchelUsersz ( creator )
function projectileCreation( creator )
local zeType = getProjectileType( source )
local projectileType = getProjectileType( source ) -- We get the projectile type
if zeType == 17 then
if projectileType == 17 then -- If is tear gas then...
local zePlayerName = getPlayerName ( creator )
local creatorName = getPlayerName( creator ) -- We get the player name who creates the projectile
outputChatBox ( zePlayerName.." is a noob teargas user! But he got punished for it don't worry." )
local x, y, z = getElementPosition ( source ) --Getting the position from the projectile creator
local x, y, z = getElementPosition ( source ) --Getting the position from the projectile creator
outputChatBox ( creatorName.." is a noob teargas user! But he got punished for it don't worry." )
setTimer ( setElementPosition, 50, 250, source, x, y, z-0.5 )
setTimer ( setElementPosition, 50, 250, source, x, y, z-0.5 )
setTimer ( setElementPosition, 50, 250, creator, x, y, z-0.5 )
setTimer ( setElementPosition, 50, 250, creator, x, y, z-0.5 )
end
end
end
end
addEventHandler( "onClientProjectileCreation", root, projectileCreation )
addEventHandler( "onClientProjectileCreation", getRootElement(), punishSatchelUsersz )
</syntaxhighlight>
</syntaxhighlight>


This will disable people from creating flares. ( Dropped by hydra's )
This will disable people from creating flares. ( Dropped by Hydras )
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function disableFlares ( creator )
function disableFlares ( )
local projType = getProjectileType( source ) --  get the projectile type
local projType = getProjectileType( source ) --  get the projectile type
if projType == 58 then -- if the projectile is a flare
 
    if projType == 58 then -- if the projectile is a flare
destroyElement(source) -- notice cancelEvent() does not work, so this destroys the projectile element after it was created.
destroyElement(source) -- notice cancelEvent() does not work, so this destroys the projectile element after it was created.
end
    end


end
end


addEventHandler( "onClientProjectileCreation", getRootElement(), disableFlares ) -- when a projectile gets created call disableFlares.
addEventHandler( "onClientProjectileCreation", root, disableFlares ) -- when a projectile gets created call disableFlares.
</syntaxhighlight>
</syntaxhighlight>
==See Also==
==See Also==
===Client projectile events===
===Client projectile events===
{{Client_projectile_events}}
{{Client_projectile_events}}

Latest revision as of 18:55, 7 September 2023

This event is triggered when a projectile is created.

Parameters

element creator
  • creator: the element that created the projectile.

Source

The source of this event is the projectile that was created.

Cancel effect

This event cannot be cancelled. To remove the projectile you can use setElementPosition (somewhere far away) and then destroyElement (which makes it explode).

Example

This will output a chatbox message when someone creates a projectile.

function projectileCreation()
	outputChatBox("A projectile was created!")
end
addEventHandler("onClientProjectileCreation", root, projectileCreation)

This will punish a player for throwing a teargas grenade. When he throws it he keeps getting warped to the location where the teargas got created, and also the teargas keeps getting warped to it. This will result in +/-60hp loss for the creator.

function projectileCreation( creator )
	local projectileType = getProjectileType( source ) -- We get the projectile type
	if projectileType == 17 then -- If is tear gas then...
		local creatorName = getPlayerName( creator ) -- We get the player name who creates the projectile
		local x, y, z = getElementPosition ( source ) --Getting the position from the projectile creator
		outputChatBox ( creatorName.." is a noob teargas user! But he got punished for it don't worry." )
		setTimer ( setElementPosition, 50, 250, source, x, y, z-0.5 )
		setTimer ( setElementPosition, 50, 250, creator, x, y, z-0.5 )
	end
end
addEventHandler( "onClientProjectileCreation", root, projectileCreation )

This will disable people from creating flares. ( Dropped by Hydras )

function disableFlares ( )
local projType = getProjectileType( source ) --  get the projectile type

    if projType == 58 then -- if the projectile is a flare
	
	destroyElement(source) -- notice cancelEvent() does not work, so this destroys the projectile element after it was created.
		
    end

end	

addEventHandler( "onClientProjectileCreation", root, disableFlares ) -- when a projectile gets created call disableFlares.

See Also

Client projectile events