https://wiki.multitheftauto.com/api.php?action=feedcontributions&user=AkaBlue&feedformat=atomMulti Theft Auto: Wiki - User contributions [en]2024-03-29T00:35:01ZUser contributionsMediaWiki 1.39.3https://wiki.multitheftauto.com/index.php?title=Control_names&diff=54760Control names2018-04-19T11:11:23Z<p>AkaBlue: /* GTA control list */</p>
<hr />
<div>This page lists all the control names. These can be used as key arguments by the console commands ''bind'' and ''unbind'' as well as the script functions [[bindKey]], [[unbindKey]] etc.<br />
<br />
Lua table of all the valid control names listed on this page:<br />
<syntaxhighlight lang="lua">controlTable = { "fire", "aim_weapon", "next_weapon", "previous_weapon", "forwards", "backwards", "left", "right", "zoom_in", "zoom_out",<br />
"change_camera", "jump", "sprint", "look_behind", "crouch", "action", "walk", "conversation_yes", "conversation_no",<br />
"group_control_forwards", "group_control_back", "enter_exit", "vehicle_fire", "vehicle_secondary_fire", "vehicle_left", "vehicle_right",<br />
"steer_forward", "steer_back", "accelerate", "brake_reverse", "radio_next", "radio_previous", "radio_user_track_skip", "horn", "sub_mission",<br />
"handbrake", "vehicle_look_left", "vehicle_look_right", "vehicle_look_behind", "vehicle_mouse_look", "special_control_left", "special_control_right",<br />
"special_control_down", "special_control_up" }</syntaxhighlight><br />
<br />
==GTA control list==<br />
<div style="border:3px solid green;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">ON FOOT</div><br />
* '''fire''' Fire a player's weapon<br />
* '''aim_weapon''' Aim the player's current weapon (if possible)<br />
* '''next_weapon''' Switch to the next weapon<br />
* '''previous_weapon''' Switch to the previous weapon<br />
* '''forwards''' Move forwards<br />
* '''backwards''' Move backwards<br />
* '''left''' Move left<br />
* '''right''' Move right<br />
* '''zoom_in''' Zoom targeted weapon in (sniper/rocket launcher/camera etc)<br />
* '''zoom_out''' Zoom targeted weapon out<br />
* '''change_camera''' Change camera mode<br />
* '''jump''' Make the player jump<br />
* '''sprint''' Make the player sprint<br />
* '''look_behind''' Make the player look behind (and allow the player to see behind them)<br />
* '''crouch''' Make the player crouch/duck<br />
* '''action''' Show the stats menu - Fire with tab key.<br />
* '''walk''' Make the player move slowly/quietly<br />
* '''conversation_yes''' Answer yes to a question<br />
* '''conversation_no''' Answer no to a question<br />
* '''group_control_forwards''' Make the group you are controlling move forwards<br />
* '''group_control_back''' Make the group you are controlling move backwards<br />
* '''enter_exit''' Make the player enter a vehicle. Also used for alternative fighting styles.<br />
</div><br />
<div style="border:3px solid red;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">IN VEHICLE</div><br />
* '''vehicle_fire''' Fire the player's vehicle's primary weapon (e.g. hunter's missiles) or shoot with driveby<br />
* '''vehicle_secondary_fire''' Fire the player's vehicle's secondary weapon (e.g. hunter's minigun)<br />
* '''vehicle_left''' Make the player's vehicle turn left<br />
* '''vehicle_right''' Make the player's vehicle turn right<br />
* '''steer_forward''' Make the player's vehicle turn down (lean forwards for helicopters/planes)<br />
* '''steer_back''' Make the player's vehicle turn up (lean backwards for helicopters/planes)<br />
* '''accelerate''' Make the player's vehicle accelerate<br />
* '''brake_reverse''' Make the player's vehicle brake (slow down) and if stationary reverse<br />
* '''radio_next''' Change to the next radio station (Doesn't work - use [[setRadioChannel]] and [[onClientPlayerRadioSwitch]] instead.)<br />
* '''radio_previous''' Change to the previous radio station (Doesn't work - use [[setRadioChannel]] and [[onClientPlayerRadioSwitch]] instead.)<br />
* '''radio_user_track_skip''' Skip the current track being played on the custom radio station<br />
* '''horn''' Play the horn of the player's vehicle (if the vehicle has a horn) and can trigger the siren on emergency vehicles<br />
* '''sub_mission''' Start a submission if one is avaliable (e.g. taxi missions)<br />
* '''handbrake''' Apply the handbrake on the player's vehicle<br />
* '''vehicle_look_left''' Look to the left<br />
* '''vehicle_look_right''' Look to the right<br />
* '''vehicle_look_behind''' Look behind<br />
* '''vehicle_mouse_look''' <br />
* '''special_control_left''' Move the some special vehicle component left (e.g. tank's turret)<br />
* '''special_control_right''' Move the some special vehicle component right (e.g. tank's turret)<br />
* '''special_control_down''' Move the some special vehicle component down (e.g. tank's turret)<br />
* '''special_control_up''' Move the some special vehicle component up (e.g. tank's turret)<br />
* '''enter_exit''' Make the player exit a vehicle<br />
</div><br />
<br />
==MTA hard-coded commands==<br />
The following are names of hard-coded MTA commands which do not use bindKey, but can act as bindKey by using them in an [[addCommandHandler]]. Other than that, this control list will '''only''' work with the functions [[toggleControl]] and [[toggleAllControls]]. Please note that [[toggleControl]] can't disable screenshot.<br />
<br />
<div style="border:3px solid blue;margin-bottom:3px;"><div<br />
style="float:right;padding-right:5px;font-weight:bold;">MTA COMMANDS</div><br />
* '''enter_passenger''' Enters the closest vehicle as passenger<br />
* '''screenshot''' Takes a screenshot<br />
* '''chatbox''' Opens the chatbox for input<br />
* '''radar''' Toggles the radar-map showing<br />
* '''radar_zoom_in''' Zooms in on the radar-map<br />
* '''radar_zoom_out''' Zooms out on the radar-map<br />
* '''radar_move_north''' Moves north on the radar-map<br />
* '''radar_move_south''' Moves south on the radar-map<br />
* '''radar_move_east''' Moves east on the radar-map<br />
* '''radar_move_west''' Moves west on the radar-map<br />
* '''radar_attach''' Attaches the view to the local-player on the radar-map<br />
</div><br />
[[Category:Scripting Concepts]]</div>AkaBluehttps://wiki.multitheftauto.com/index.php?title=CreateTrayNotification&diff=50895CreateTrayNotification2017-05-08T14:25:35Z<p>AkaBlue: /* Example */</p>
<hr />
<div>__NOTOC__ <br />
{{Client function}}<br />
This functions creates a notification ballon on the desktop.<br />
<br />
{{Note|MTA won't show any tray notifications if the MTA window is focused, because there is no reason to show tray notifications if you are ingame. If you want to test this function you should use a Timer and switch to your desktop.}}<br />
{{Note|You can only show a tray notification every 30 seconds.}}<br />
{{Note|Windows 10 isn't compatible with the function for now so dialogue won't pop out (see below at Issues)}}<br />
<br />
== Issues ==<br />
{{Issues|<br />
{{Issue|9447|createTrayNotification not working for Windows 10}}<br />
}}<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua">bool createTrayNotification ( string notificationText, [ string iconType = "default", bool useSound = true ] )</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''notificationText:''' The text to send in the notification.<br />
<br />
===Optional Arguments===<br />
*'''iconType:''' The notification icon type. Possible values are: '''"default" (the MTA icon), "info", "warning", "error"'''<br />
*'''useSound:''' A boolean value indicating whether or not to play a sound when receiving the notification.<br />
<br />
===Returns===<br />
Returns ''true'' if the notification is correctly created, ''false'' otherwise.<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
-- Note: You have to wait 30 seconds before showing another tray notification, there is no queuing<br />
<br />
-- Show a 'Hello World' notification<br />
createTrayNotification( "Hello World" )<br />
<br />
-- Show a notification with a warning symbol<br />
createTrayNotification( "Hello World", "warning" )<br />
<br />
-- Show a default notification without sound<br />
createTrayNotification( "Hello World", "default", false )<br />
</syntaxhighlight><br />
<br />
==Example of notification on minimize MTA application==<br />
<syntaxhighlight lang="lua"><br />
function setTrayOnMinimize( )<br />
createTrayNotification( "We are waiting for you again...", "warning" )<br />
end<br />
addEventHandler( "onClientMinimize", getRootElement( ), setTrayOnMinimize )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Client_utility_functions}}</div>AkaBluehttps://wiki.multitheftauto.com/index.php?title=GuiCreateStaticImage&diff=49656GuiCreateStaticImage2016-10-25T16:55:08Z<p>AkaBlue: /* Little change in Lua Syntax. Error with [lua] */</p>
<hr />
<div>__NOTOC__ <br />
{{Client function}}<br />
This function creates a static image using a .png image in the resource.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
element guiCreateStaticImage ( float x, float y, float width, float height, string path, bool relative, [element parent = nil] )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
[[Image:gui-staticimage.png|frame|Example GUI static image.]]<br />
*'''x:''' A float of the 2D x position of the image on a player's screen. This is affected by the ''relative'' argument.<br />
*'''y:''' A float of the 2D y position of the image on a player's screen. This is affected by the ''relative'' argument.<br />
*'''width:''' A float of the width of the image. This is affected by the ''relative'' argument.<br />
*'''height:''' A float of the height of the image. This is affected by the ''relative'' argument.<br />
*'''path:''' The [[filepath]] of the image file that is being loaded. <br />
*'''relative:''' This is whether sizes and positioning are relative. If this is ''true'', then all x,y,width,height floats must be between 0 and 1, representing measures relative to the parent.<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}} <br />
*'''parent:''' This is the parent that the image is attached to. If the ''relative'' argument is true, sizes and positioning will be made relative to this parent. If the ''relative'' argument is false, positioning will be the number of offset pixels from the parent's origin. If no parent is passed, the parent will become the screen - causing positioning and sizing according to screen positioning.<br />
<br />
===Returns===<br />
Returns [[element]] if image was created successfully, ''false'' otherwise.<br />
<br />
==Example==<br />
This example will display an image (imagename.png) on the client's (player's) screen.<br />
<section name="Client-side script (example.lua)" class="client" show="true"><br />
<syntaxhighlight lang="lua"><br />
function showClientImage()<br />
guiCreateStaticImage( 20, 200, 100, 100, "imagename.png", false )<br />
end<br />
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), showClientImage )<br />
</syntaxhighlight><br />
</section><br />
<br />
<section name="meta.xml" class="server" show="true"><br />
In this example [[Meta.xml]] is used to tell the server which files it will be using.<br />
<syntaxhighlight lang="xml"><br />
<meta><br />
<info author="Yourname" version="1.0" /><br />
<script src="example.lua" type="client" /><br />
<file src="imagename.png" /><br />
</meta><br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{GUI_functions}}</div>AkaBluehttps://wiki.multitheftauto.com/index.php?title=GetKeyState&diff=49434GetKeyState2016-10-07T19:18:54Z<p>AkaBlue: /* rctrl changed by p for the example */</p>
<hr />
<div>__NOTOC__<br />
{{Client function}}<br />
This function determines if a certain key is pressed or not.<br />
<br />
'''Note:''' 'ralt' may trigger both 'ralt' and 'lctrl', this is due to AltGr<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool getKeyState ( string keyName )<br />
</syntaxhighlight><br />
<br />
===Required Arguments=== <br />
*'''keyName:''' The name of the key you're checking state of. See [[Key names]].<br />
<br />
===Returns===<br />
Returns ''true'' if the specified key is pressed, ''false'' if it isn't or if an invalid key name is passed.<br />
<br />
==Example== <br />
This clientside example prints a message when "p" is pressed, and a different one for the "control+p" combination.<br />
<syntaxhighlight lang="lua"><br />
-- define a function that outputs a message if control is pressed, and a different one if it isn't<br />
function printMessageFunction()<br />
-- if the left or right control keys are pressed, the user has pressed the "control+p" combo<br />
if getKeyState( "lctrl" ) == true or getKeyState( "p" ) == true then<br />
outputChatBox ( "You have pressed 'control+p'." )<br />
-- if none of those were pressed, he just pressed the "p" key<br />
else<br />
outputChatBox ( "You have pressed 'p'." )<br />
end<br />
end<br />
-- bind the "p" key to our function<br />
bindKey( "p", "down", "Print message", printMessageFunction )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Client_input_functions}}</div>AkaBluehttps://wiki.multitheftauto.com/index.php?title=IsMouseInPosition&diff=49433IsMouseInPosition2016-10-07T13:43:58Z<p>AkaBlue: /* Spaces problem */</p>
<hr />
<div>{{Useful Function}}<br />
<lowercasetitle/><br />
__NOTOC__<br />
This function allows you to check whether the mouse cursor/pointer is within a rectangular position<br />
==Syntax==<br />
<syntaxhighlight lang="lua">bool isMouseInPosition ( int x, int y, int width, int height )</syntaxhighlight><br />
<br />
<br />
===Required arguments===<br />
* '''x''': Left-most X position for detection (absolute)<br />
* '''y''': Top-most Y position for detection (absolute)<br />
* '''width''': Width for detection (absolute)<br />
* '''heigh''': Height for detection (absolute)<br />
<br />
===Return===<br />
Returns true/false depending on whether the mouse is within the specified position or not<br />
<br />
==Code==<br />
<syntaxhighlight lang="lua"><br />
function isMouseInPosition ( x, y, width, height )<br />
if ( not isCursorShowing( ) ) then<br />
return false<br />
end<br />
local sx, sy = guiGetScreenSize ( )<br />
local cx, cy = getCursorPosition ( )<br />
local cx, cy = ( cx * sx ), ( cy * sy )<br />
if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then<br />
return true<br />
else<br />
return false<br />
end<br />
end<br />
<br />
-- Modified version for DX Text<br />
function isCursorOverText(posX, posY, sizeX, sizeY)<br />
if(isCursorShowing()) then<br />
local cX, cY = getCursorPosition()<br />
local screenWidth, screenHeight = guiGetScreenSize()<br />
local cX, cY = (cX*screenWidth), (cY*screenHeight)<br />
if(cX >= posX and cX <= posX+(sizeX - posX)) and (cY >= posY and cY <= posY+(sizeY - posY)) then<br />
return true<br />
else<br />
return false<br />
end<br />
else<br />
return false <br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==Example==<br />
<section name="Example" class="client" show="true"><br />
Changes the image when you move your cursor over it.<br />
<syntaxhighlight lang="lua"><br />
addEventHandler ( "onClientRender", root,<br />
function ( )<br />
local imgX, imgY, imgWidth, imgHeight = 50, 50, 200, 200<br />
dxDrawImage ( imgX, imgY, imgWidth, imgHeight, ( isMouseInPosition ( imgX, imgY, imgWidth, imgHeight ) and "myImage2.png" or "myImage.png" ), tocolor ( 255, 255, 255 ) )<br />
end<br />
)<br />
</syntaxhighlight><br />
</section><br />
<br />
<br />
<br />
Author: Castillo<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>AkaBluehttps://wiki.multitheftauto.com/index.php?title=OnElementClicked&diff=49388OnElementClicked2016-10-02T18:26:01Z<p>AkaBlue: /* Added other example */</p>
<hr />
<div>__NOTOC__<br />
{{Server event}}<br />
This event is triggered when an element is clicked on by the client. These events can only trigger when the client has its cursor enabled. It triggers for all three mousebuttons in both their up and down states.<br />
<br />
==Parameters==<br />
<syntaxhighlight lang="lua"><br />
string mouseButton, string buttonState, player playerWhoClicked, float clickPosX, float clickPosY, float clickPosZ<br />
</syntaxhighlight> <br />
<br />
*'''mouseButton''': A string representing the mousebutton that was clicked. This might be ''left'', ''middle'' or ''right''.<br />
*'''buttonState''': A string representing what state the button clicked is in. This might be ''up'' or ''down''.<br />
*'''playerWhoClicked''': The player that clicked on the element<br />
*'''clickPosX''': The X position in the world the player clicked at<br />
*'''clickPosY''': The Y position in the world the player clicked at<br />
*'''clickPosZ''': The Z position in the world the player clicked at<br />
<br />
==Source==<br />
The [[event system#Event source|source]] of this event is the [[element]] that got clicked by the player.<br />
<br />
==Examples== <br />
This example prints type of the element you clicked to chatbox when you click it.<br />
<syntaxhighlight lang="lua"><br />
function elementClicked( theButton, theState, thePlayer )<br />
if theButton == "left" and theState == "down" then -- if left mouse button was pressed down<br />
outputChatBox( "You clicked " .. getElementType( source ), thePlayer ) -- print the element type to players chatbox<br />
end<br />
end<br />
addEventHandler( "onElementClicked", getRootElement(), elementClicked ) -- add a handler function for the event<br />
</syntaxhighlight><br />
<br />
This example check if the clicked element is a vehicle. If is, then repairs it.<br />
<syntaxhighlight lang="lua"><br />
function repairClickedVehicle( button, state, player ) -- Add the function<br />
if button == "left" and state == "down" then<br />
if getElementType( source ) == "vehicle" then -- If the clicked element is a vehicle...<br />
local x, y, z = getElementPosition( player )<br />
local x1, y1, z1 = getElementPosition( source ) <br />
local distance = getDistanceBetweenPoints3D( x, y, z, x1, y1, z1 ) -- Some distance calculations<br />
if distance < 4 then -- Check if the player is near the vehicle<br />
if getElementHealth( source ) < 1000 then<br />
fixVehicle( source )<br />
outputChatBox( "You have repaired a "..getVehicleNameFromModel( getElementModel( source ) ), player, 0, 255, 0 )<br />
else<br />
outputChatBox( "Vehicle is not damaged!", player, 255, 0, 0 )<br />
end<br />
end<br />
end<br />
end<br />
end<br />
addEventHandler( "onElementClicked", getRootElement( ), elementClicked ) -- Add the event handler<br />
</syntaxhighlight><br />
{{See also/Server event|Element events}}</div>AkaBluehttps://wiki.multitheftauto.com/index.php?title=GuiGetScreenSize&diff=49342GuiGetScreenSize2016-09-30T18:17:37Z<p>AkaBlue: /* Using guiGetScreenSize to fit GUI & DX drawing in all resolutions */</p>
<hr />
<div>__NOTOC__<br />
{{Client function}}<br />
This function retrieves the local screen size according to the resolution they are using.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
float float guiGetScreenSize()<br />
</syntaxhighlight> <br />
<br />
===Returns===<br />
This returns two floats representing the player's screen resolution, ''width'' and ''height''.<br />
<br />
==Example== <br />
This example checks whether a player is using a low resolution, and warns them that GUI may appear incorrect.<br />
<syntaxhighlight lang="lua"><br />
--setup a function when the resource starts<br />
function checkResolutionOnStart ()<br />
local x,y = guiGetScreenSize() --get their screen size<br />
if ( x <= 640 ) and ( y <= 480 ) then --if their resolution is lower or equal to 640x480<br />
--warn them about GUI problems.<br />
outputChatBox ( "WARNING: You are running on a low resolution. Some GUI may be placed or appear incorrectly." )<br />
end<br />
end<br />
--attach the function to the event handler<br />
addEventHandler ( "onClientResourceStart", resourceRoot, checkResolutionOnStart )<br />
</syntaxhighlight><br />
<br />
<br />
==Using guiGetScreenSize to fit GUI & DX drawing in all resolutions==<br />
To get the precise coordinates of a GUI element or DX drawings, you need to decide which edges of the screen you want to have them positioned against, then you just need to find the difference between your screen size and your position values.<br />
<br />
For example, there is a DX text. It fits on 1024x768 resolution.<br />
<syntaxhighlight lang="lua"><br />
function DXtext ()<br />
dxDrawText(tostring "Hello World!",684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)<br />
end<br />
<br />
addEventHandler ( "onClientRender", getRootElement(), DXtext )<br />
</syntaxhighlight><br />
Now if you want it to fit on all resolutions. Then follow these steps:<br />
<br />
1. Add ''width'' and ''height'' variables to get GUI's screen size, here we use sWidth and sHeight.<br />
<syntaxhighlight lang="lua"><br />
local sWidth,sHeight = guiGetScreenSize() -- The variables<br />
dxDrawText( "Hello World!",684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)<br />
</syntaxhighlight><br />
<br />
2. Divide each of the DX text's position values by the screen size manually (remembering the resolution is 1024x768):<br />
<br />
*'''Left''' position value is 684, 684/1024 = 0.668<br />
*'''Top''' position value is 731, 731/768 = 0.952<br />
*'''Right''' position values is 732, 732/1024 = 0.715<br />
*'''Bottom''' position value is 766, 766/768 = 0.997<br />
<br />
You may want to use a calculator to help you count.<br />
<br />
3. Now with the answer above remove all of the position values and replace it with the width or height variable multiplied by the answer. Which would be:<br />
<syntaxhighlight lang="lua"><br />
local sWidth,sHeight = guiGetScreenSize() -- The variables<br />
dxDrawText("Hello World!",sWidth*0.668, sHeight*0.952, sWidth*0.715, sHeight*0.997,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)<br />
</syntaxhighlight><br />
<br />
So the final results will be a DX text which will fit on all resolutions which will be:<br />
<syntaxhighlight lang="lua"><br />
function DXtext ()<br />
local sWidth,sHeight = guiGetScreenSize() -- The variables<br />
dxDrawText("Hello World!",sWidth*0.668, sHeight*0.952, sWidth*0.715, sHeight*0.997,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)<br />
end<br />
<br />
addEventHandler ( "onClientRender", getRootElement(), DXtext )<br />
</syntaxhighlight><br />
<br />
We can also do it by ourself doing some calculations in the code. This works in all resolution, adjusting the scale to all screen-sizes.<br />
<syntaxhighlight lang="lua"><br />
local sx, sy = guiGetScreenSize( )<br />
<br />
addEventHandler( "onClientRender", root,<br />
function( )<br />
dxDrawText( "Hello World!", sx*( 684/1024 ), sy*( 731/768 ), sx*( 732/1024 ), sy( 766/768 ), tocolor(0,255,255,175), sx/1000*1.0,"bankgothic","left","top",false,false,false ) <br />
end<br />
)<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{GUI_functions}}</div>AkaBluehttps://wiki.multitheftauto.com/index.php?title=OnClientProjectileCreation&diff=49341OnClientProjectileCreation2016-09-30T18:10:43Z<p>AkaBlue: /* Example */</p>
<hr />
<div>__NOTOC__<br />
{{Client event}}<br />
This event is triggered when a [[projectile]] is created.<br />
<br />
==Parameters==<br />
<syntaxhighlight lang="lua"><br />
element creator<br />
</syntaxhighlight> <br />
<br />
==Source==<br />
The [[event system#Event source|source]] of this event is the [[projectile]] that was created.<br />
<br />
==Cancel effect==<br />
This event cannot be cancelled. To remove the projectile you can use setElementPosition (some where far away) and then destroyElement (which makes it explode).<br />
<br />
==Example==<br />
This will output a chatbox message when someone creates a projectile.<br />
<syntaxhighlight lang="lua"><br />
function projectileCreation()<br />
outputChatBox("A projectile was created!")<br />
end<br />
addEventHandler("onClientProjectileCreation", getRootElement(), projectileCreation)<br />
</syntaxhighlight><br />
<br />
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.<br />
<syntaxhighlight lang="lua"><br />
function projectileCreation( creator )<br />
local projectileType = getProjectileType( source ) -- We get the projectile type<br />
if projectileType == 17 then -- If is tear gas then...<br />
local creatorName = getPlayerName( creator ) -- We get the player name who creates the projectile<br />
local x, y, z = getElementPosition ( source ) --Getting the position from the projectile creator<br />
outputChatBox ( creatorName.." is a noob teargas user! But he got punished for it don't worry." )<br />
setTimer ( setElementPosition, 50, 250, source, x, y, z-0.5 )<br />
setTimer ( setElementPosition, 50, 250, creator, x, y, z-0.5 )<br />
end<br />
end<br />
addEventHandler( "onClientProjectileCreation", getRootElement( ), projectileCreation )<br />
</syntaxhighlight><br />
<br />
This will disable people from creating flares. ( Dropped by Hydras )<br />
<syntaxhighlight lang="lua"><br />
function disableFlares ( )<br />
local projType = getProjectileType( source ) -- get the projectile type<br />
<br />
if projType == 58 then -- if the projectile is a flare<br />
<br />
destroyElement(source) -- notice cancelEvent() does not work, so this destroys the projectile element after it was created.<br />
<br />
end<br />
<br />
end <br />
<br />
addEventHandler( "onClientProjectileCreation", getRootElement(), disableFlares ) -- when a projectile gets created call disableFlares.<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
===Client projectile events===<br />
{{Client_projectile_events}}</div>AkaBlue