https://wiki.multitheftauto.com/api.php?action=feedcontributions&user=Flobu&feedformat=atomMulti Theft Auto: Wiki - User contributions [en]2024-03-28T09:31:16ZUser contributionsMediaWiki 1.39.3https://wiki.multitheftauto.com/index.php?title=Talk:ResetTimer&diff=24370Talk:ResetTimer2010-08-16T22:01:46Z<p>Flobu: its clientside too</p>
<hr />
<div>I added it clientside in [http://code.google.com/p/mtasa-blue/source/detail?r=1876 r1876] may it should be backported to 1.0.4<br />
somebody missed to add the function in the lua manager</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=CreatePed&diff=23600CreatePed2010-06-04T12:03:07Z<p>Flobu: </p>
<hr />
<div>__NOTOC__ <br />
{{Server client function}}<br />
{{Needs_Checking|CPP has code for a serverside extra argument called bSynced}} <br />
Creates a Ped in the GTA world.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua">ped createPed ( int modelid, float x, float y, float z [, float rot ] )</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''modelid:''' A whole integer specifying the [[Character_Skins|GTASA skin ID]].<br />
*'''x:''' A floating point number representing the X coordinate on the map.<br />
*'''y:''' A floating point number representing the Y coordinate on the map.<br />
*'''z:''' A floating point number representing the Z coordinate on the map.<br />
*'''rot:''' A floating point number representing the rotation in degrees. <br />
<br />
===Returns===<br />
Returns the ped element.<br />
<br />
==Example== <br />
<br />
<section name="Server" class="server" show="true"><br />
This example creates an ped when the resource starts:<br />
<syntaxhighlight lang="lua"><br />
function pedLoad ( name )<br />
createPed ( 120, 5540.6654, 1020.55122, 1240.545 )<br />
end<br />
addEventHandler ( "onResourceStart", getRootElement(), pedLoad )<br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{Ped functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=CreatePed&diff=23599CreatePed2010-06-04T11:58:09Z<p>Flobu: </p>
<hr />
<div>__NOTOC__ <br />
{{Server client function}}<br />
{{Needs_Checking|CPP has code for a serverside extra argument called bSynced}} <br />
Creates a Ped in the GTA world.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua">ped createPed ( int modelid, float x, float y, float z, float rot )</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''modelid:''' A whole integer specifying the [[Character_Skins|GTASA skin ID]].<br />
*'''x:''' A floating point number representing the X coordinate on the map.<br />
*'''y:''' A floating point number representing the Y coordinate on the map.<br />
*'''z:''' A floating point number representing the Z coordinate on the map.<br />
*'''rot:''' A floating point number representing the rotation in degrees. <br />
<br />
===Returns===<br />
Returns the ped element.<br />
<br />
==Example== <br />
<br />
<section name="Server" class="server" show="true"><br />
This example creates an ped when the resource starts:<br />
<syntaxhighlight lang="lua"><br />
function pedLoad ( name )<br />
createPed ( 120, 5540.6654, 1020.55122, 1240.545 )<br />
end<br />
addEventHandler ( "onResourceStart", getRootElement(), pedLoad )<br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{Ped functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Template:BASS_Errors&diff=23577Template:BASS Errors2010-05-30T21:59:26Z<p>Flobu: Created page with '** '''0:''' BASS_OK all is OK ** '''1:''' BASS_ERROR_MEM memory error ** '''2:''' BASS_ERROR_FILEOPEN can't open the file ** '''3:''' BASS_ERROR_DRIVER can't find a f…'</p>
<hr />
<div>** '''0:''' BASS_OK all is OK<br />
** '''1:''' BASS_ERROR_MEM memory error<br />
** '''2:''' BASS_ERROR_FILEOPEN can't open the file<br />
** '''3:''' BASS_ERROR_DRIVER can't find a free/valid driver<br />
** '''4:''' BASS_ERROR_BUFLOST the sample buffer was lost<br />
** '''5:''' BASS_ERROR_HANDLE invalid handle<br />
** '''6:''' BASS_ERROR_FORMAT unsupported sample format<br />
** '''7:''' BASS_ERROR_POSITION invalid position<br />
** '''8:''' BASS_ERROR_INIT BASS_Init has not been successfully called<br />
** '''9:''' BASS_ERROR_START BASS_Start has not been successfully called<br />
** '''14:''' BASS_ERROR_ALREADY already initialized/paused/whatever<br />
** '''18:''' BASS_ERROR_NOCHAN can't get a free channel<br />
** '''19:''' BASS_ERROR_ILLTYPE an illegal type was specified<br />
** '''20:''' BASS_ERROR_ILLPARAM an illegal parameter was specified<br />
** '''21:''' BASS_ERROR_NO3D no 3D support<br />
** '''22:''' BASS_ERROR_NOEAX no EAX support<br />
** '''23:''' BASS_ERROR_DEVICE illegal device number<br />
** '''24:''' BASS_ERROR_NOPLAY not playing<br />
** '''25:''' BASS_ERROR_FREQ illegal sample rate<br />
** '''27:''' BASS_ERROR_NOTFILE the stream is not a file stream<br />
** '''29:''' BASS_ERROR_NOHW no hardware voices available<br />
** '''31:''' BASS_ERROR_EMPTY the MOD music has no sequence data<br />
** '''32:''' BASS_ERROR_NONET no internet connection could be opened<br />
** '''33:''' BASS_ERROR_CREATE couldn't create the file<br />
** '''34:''' BASS_ERROR_NOFX effects are not available<br />
** '''37:''' BASS_ERROR_NOTAVAIL requested data is not available<br />
** '''38:''' BASS_ERROR_DECODE the channel is a "decoding channel"<br />
** '''39:''' BASS_ERROR_DX a sufficient DirectX version is not installed<br />
** '''40:''' BASS_ERROR_TIMEOUT connection timedout<br />
** '''41:''' BASS_ERROR_FILEFORM unsupported file format<br />
** '''42:''' BASS_ERROR_SPEAKER unavailable speaker<br />
** '''43:''' BASS_ERROR_VERSION invalid BASS version (used by add-ons)<br />
** '''44:''' BASS_ERROR_CODEC codec is not available/supported<br />
** '''45:''' BASS_ERROR_ENDED the channel/file has ended<br />
** '''-1:''' BASS_ERROR_UNKNOWN some other mystery problem</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=GetElementCollidableWith&diff=23164GetElementCollidableWith2010-04-29T20:31:56Z<p>Flobu: Redirected page to IsElementCollidableWith</p>
<hr />
<div>#REDIRECT [[IsElementCollidableWith]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Template:Client_utility_functions&diff=23009Template:Client utility functions2010-04-23T13:25:41Z<p>Flobu: </p>
<hr />
<div>* [[getDistanceBetweenPoints2D]]<br />
* [[getDistanceBetweenPoints3D]]<br />
* [[getRealTime]]<br />
* [[getTickCount]]<br />
{{New feature|4|1.0.4|<br />
*[[getTimerDetails]]<br />
}}<br />
* [[getTimers]]<br />
* [[gettok]]<br />
* [[killTimer]]<br />
{{New feature|4|1.0.4|<br />
*[[resetTimer]]<br />
}}<br />
* [[setTimer]]<br />
* [[split]]<br />
* [[getVersion]]<br />
* [[isTimer]]<br />
* [[md5]]<br />
* [[tocolor]]<br />
<!--<br />
* [[ref]]<br />
* [[deref]]<br />
--></div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Template:Utility_functions&diff=23008Template:Utility functions2010-04-23T13:24:30Z<p>Flobu: </p>
<hr />
<div>*[[getColorFromString]]<br />
*[[getDistanceBetweenPoints2D]]<br />
*[[getDistanceBetweenPoints3D]]<br />
<!--<br />
*[[getPacketInfo]]<br />
--><br />
*[[getRealTime]]<br />
*[[getTickCount]]<br />
{{New feature|4|1.0.4|<br />
*[[getTimerDetails]]<br />
}}<br />
*[[getTimers]]<br />
*[[gettok]]<br />
*[[killTimer]]<br />
{{New feature|4|1.0.4|<br />
*[[resetTimer]]<br />
}}<br />
*[[setTimer]]<br />
*[[split]]<br />
*[[isTimer]]<br />
*[[md5]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Talk:GetChatboxLayout&diff=22840Talk:GetChatboxLayout2010-04-06T18:58:59Z<p>Flobu: </p>
<hr />
<div>'''''setChatboxLayout''''' is it possible?<br />
<br />
it is possible but it isn't a good idea to force other people to use a specific layout</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=AddBan&diff=22672AddBan2010-03-17T22:02:56Z<p>Flobu: /* Example */</p>
<hr />
<div>__NOTOC__ <br />
{{Server function}}<br />
This function will add a ban for the specified IP/username/serial to the server.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
ban addBan ( [ string IP, string Username, string Serial, player responsibleElement, string reason, int seconds = 0 ] ) <br />
</syntaxhighlight><br />
'''Note:''' One of the three: IP, Username or Serial have to be specified.<br />
<br />
===Required Arguments=== <br />
*'''IP:''' The IP to be banned. If you don't want to ban by IP, set this to ''nil''.<br />
'''or'''<br />
*'''Username:''' The username to be banned. If you don't want to ban by username, set this to ''nil''.<br />
'''or'''<br />
*'''Serial:''' The serial to be banned. If you don't want to ban by serial, set this to ''nil''.<br />
''' or any combination.'''<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}} <br />
*'''responsibleElement:''' The element that is responsible for banning the IP/username/serial. This can be a player or the root ([[getRootElement]]()).<br />
*'''reason:''' The reason the IP/username/serial will be banned from the server.<br />
*'''seconds:''' The amount of seconds the player will be banned from the server for. This can be 0 for an infinite amount of time.<br />
<br />
===Returns===<br />
Returns ''true'' if the IP/username/serial was banned succesfully, ''false'' if invalid arguments are specified.<br />
<br />
==Example==<br />
This example bans a player's IP with the reason "Requested" when they type "/ban-me".<br />
<syntaxhighlight lang="lua"><br />
function banMe ( source, command ) -- The function header and where source is defined<br />
local ipToBan = getPlayerIP ( source ) -- Get the player's IP<br />
addBan ( ipToBan, nil, nil, source, "Requested" ) -- Ban him with the reason; Requested<br />
end<br />
addCommandHandler ( "ban-me", banMe ) -- Make it trigger when a player types "/ban-me"<br />
</syntaxhighlight><br />
<br />
==Example 2==<br />
This example add command to ban player serial.<br />
<syntaxhighlight lang="lua"><br />
function banSerial( source, command, noob, reason )<br />
if ( noob ) then<br />
local theNoob = getPlayerFromName( noob )<br />
local theNoobSerial - getPlayerSerial( theNoob )<br />
if ( theNoob ) then<br />
addBan( nil, nil, theNoobSerial, source, reason )<br />
end<br />
end<br />
end<br />
addCommandHandler( "ban-serial", banSerial )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Admin functions}}<br />
[[ru:addBan]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=AddBan&diff=22671AddBan2010-03-17T22:02:44Z<p>Flobu: /* Example */</p>
<hr />
<div>__NOTOC__ <br />
{{Server function}}<br />
This function will add a ban for the specified IP/username/serial to the server.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
ban addBan ( [ string IP, string Username, string Serial, player responsibleElement, string reason, int seconds = 0 ] ) <br />
</syntaxhighlight><br />
'''Note:''' One of the three: IP, Username or Serial have to be specified.<br />
<br />
===Required Arguments=== <br />
*'''IP:''' The IP to be banned. If you don't want to ban by IP, set this to ''nil''.<br />
'''or'''<br />
*'''Username:''' The username to be banned. If you don't want to ban by username, set this to ''nil''.<br />
'''or'''<br />
*'''Serial:''' The serial to be banned. If you don't want to ban by serial, set this to ''nil''.<br />
''' or any combination.'''<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}} <br />
*'''responsibleElement:''' The element that is responsible for banning the IP/username/serial. This can be a player or the root ([[getRootElement]]()).<br />
*'''reason:''' The reason the IP/username/serial will be banned from the server.<br />
*'''seconds:''' The amount of seconds the player will be banned from the server for. This can be 0 for an infinite amount of time.<br />
<br />
===Returns===<br />
Returns ''true'' if the IP/username/serial was banned succesfully, ''false'' if invalid arguments are specified.<br />
<br />
==Example==<br />
This example bans a player's IP with the reason "Requested" when they type "/ban-me".<br />
<syntaxhighlight lang="lua"><br />
function banMe ( source, command ) -- The function header and where source is defined<br />
local ipToBan = getPlayerIP ( source ) -- Get the player's IP<br />
addBan ( ipToBan nil, nil, source, "Requested" ) -- Ban him with the reason; Requested<br />
end<br />
addCommandHandler ( "ban-me", banMe ) -- Make it trigger when a player types "/ban-me"<br />
</syntaxhighlight><br />
<br />
==Example 2==<br />
This example add command to ban player serial.<br />
<syntaxhighlight lang="lua"><br />
function banSerial( source, command, noob, reason )<br />
if ( noob ) then<br />
local theNoob = getPlayerFromName( noob )<br />
local theNoobSerial - getPlayerSerial( theNoob )<br />
if ( theNoob ) then<br />
addBan( nil, nil, theNoobSerial, source, reason )<br />
end<br />
end<br />
end<br />
addCommandHandler( "ban-serial", banSerial )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Admin functions}}<br />
[[ru:addBan]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=AddBan&diff=22670AddBan2010-03-17T21:45:56Z<p>Flobu: /* Example 2 */</p>
<hr />
<div>__NOTOC__ <br />
{{Server function}}<br />
This function will add a ban for the specified IP/username/serial to the server.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
ban addBan ( [ string IP, string Username, string Serial, player responsibleElement, string reason, int seconds = 0 ] ) <br />
</syntaxhighlight><br />
'''Note:''' One of the three: IP, Username or Serial have to be specified.<br />
<br />
===Required Arguments=== <br />
*'''IP:''' The IP to be banned. If you don't want to ban by IP, set this to ''nil''.<br />
'''or'''<br />
*'''Username:''' The username to be banned. If you don't want to ban by username, set this to ''nil''.<br />
'''or'''<br />
*'''Serial:''' The serial to be banned. If you don't want to ban by serial, set this to ''nil''.<br />
''' or any combination.'''<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}} <br />
*'''responsibleElement:''' The element that is responsible for banning the IP/username/serial. This can be a player or the root ([[getRootElement]]()).<br />
*'''reason:''' The reason the IP/username/serial will be banned from the server.<br />
*'''seconds:''' The amount of seconds the player will be banned from the server for. This can be 0 for an infinite amount of time.<br />
<br />
===Returns===<br />
Returns ''true'' if the IP/username/serial was banned succesfully, ''false'' if invalid arguments are specified.<br />
<br />
==Example==<br />
This example bans a player's IP with the reason "Requested" when they type "/ban-me".<br />
<syntaxhighlight lang="lua"><br />
function banMe ( source, command ) -- The function header and where source is defined<br />
local ipToBan = getPlayerIP ( source ) -- Get the player's IP<br />
addBan ( ipToBan, source, "Requested" ) -- Ban him with the reason; Requested<br />
end<br />
addCommandHandler ( "ban-me", banMe ) -- Make it trigger when a player types "/ban-me"<br />
</syntaxhighlight><br />
<br />
==Example 2==<br />
This example add command to ban player serial.<br />
<syntaxhighlight lang="lua"><br />
function banSerial( source, command, noob, reason )<br />
if ( noob ) then<br />
local theNoob = getPlayerFromName( noob )<br />
local theNoobSerial - getPlayerSerial( theNoob )<br />
if ( theNoob ) then<br />
addBan( nil, nil, theNoobSerial, source, reason )<br />
end<br />
end<br />
end<br />
addCommandHandler( "ban-serial", banSerial )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Admin functions}}<br />
[[ru:addBan]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Resource:Votemanager&diff=22379Resource:Votemanager2010-02-08T21:00:27Z<p>Flobu: /* Serverside events */</p>
<hr />
<div>{{Resource page}}<br />
__NOTOC__<br />
This script manages any kind of poll with multiple options. '''votemap''', '''votekick''', '''votekill''' and '''voteban''' are built in.<br />
==Built-in polls==<br />
<br />
'''votemap''' (starts a vote between a random list of up to 9 maps compatible with the current gamemode, if one is running)<br />
<br />
'''votemap gamemode''' (starts a vote between a random list of up to 9 maps compatible with the specified gamemode)<br />
<br />
'''votemap gamemode map''' (starts a vote to launch the specified gamemode with the specified map)<br />
<br />
'''votemap map''' (starts a vote to change to another map for the current gamemode, if one is running)<br />
<br />
'''votemode''' (starts a vote between a random list of up to 9 gamemodes. once the vote is done and a new gamemode is picked, automatically starts 'votemap gamemode')<br />
<br />
'''votekick player''' (starts a vote to kick the specified player)<br />
<br />
'''votekill player''' (starts a vote to kill the specified player)<br />
<br />
'''voteban player''' (starts a vote to ban the specified player)<br />
<br />
==Serverside functions==<br />
===startPoll===<br />
<syntaxhighlight lang="lua">bool, int startPoll ( table pollData )</syntaxhighlight><br />
Creates a poll. Returns ''true'' if the poll was created successfully, ''false'' and an error code otherwise (see the source for error codes).<br />
<br />
* '''pollData''' is a table containing poll settings and an array of ''at least two'' options. Each option comes in the form:<br />
<syntaxhighlight lang="lua"><br />
{<br />
string optionName,<br />
string eventToTrigger,<br />
[element triggerFrom = getRootElement()],<br />
default = [bool isDefaultOption = false],<br />
var argument1,<br />
var argument2,<br />
...<br />
}<br />
</syntaxhighlight><br />
The chosen option will trigger eventToTrigger from the triggerFrom element with ''arguments...'' as parameters when the poll ends.<br />
<br />
If there's not enough votes, the default option will be executed if there's one.<br />
<br />
Example:<br />
<syntaxhighlight lang="lua"><br />
local playerToKill = getRandomPlayer()<br />
local notEnoughVotesMessage = "Not enough votes to kill "..getPlayerName(playerToKill).."."<br />
startPoll {<br />
--start settings (dictionary part)<br />
title="Kill "..getPlayerName(playerToKill).."?",<br />
percentage=75,<br />
timeout=30,<br />
allowchange=false,<br />
maxnominations=3,<br />
visibleTo=getRootElement(),<br />
--start options (array part)<br />
[1]={"Yes", "doKillPlayer", playerToKill},<br />
[2]={"No", "doOutputChatBox", notEnoughVotesMessage, getRootElement(), vR, vG, vB; default=true},<br />
}<br />
</syntaxhighlight><br />
*'''title''' (required): the poll title which will be seen by clients on the manager GUI<br />
*'''percentage''' (optional, defaults to default.percentage): percentage needed for an option to pass<br />
*'''timeout''' (optional, defaults to default.timeout): poll timeout in seconds<br />
*'''allowchange''' (optional, defaults to default.allowchange): specifies if changing your vote is allowed<br />
*'''maxnominations''' (optional, defaults to default.maxnominations): specifies the max number of nominations in case there's a draw<br />
*'''visibleTo''' (optional, defaults to [[getRootElement]]()): a table or players that will be able to see the poll, OR an element that contains the players.<br />
If it is root, new players joining the server will be able to vote.<br />
<br />
''voteconfig.xml'' defaults will be used for missing optional settings.<br />
<br />
===stopPoll===<br />
<syntaxhighlight lang="lua">bool, int stopPoll ( )</syntaxhighlight><br />
Stops the running poll. Returns ''true'' if the current poll was stopped successfully, ''false'' and an error code otherwise.<br />
<br />
===voteMap===<br />
<syntaxhighlight lang="lua">bool, int voteMap ( string mapName )</syntaxhighlight><br />
Starts a votemap. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
===voteBetweenMaps===<br />
<syntaxhighlight lang="lua">bool, int voteBetweenMaps ( resource map1, resource map2, [ resource map3, ... ] )</syntaxhighlight><br />
Starts a poll to choose a map. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
===voteKick===<br />
<syntaxhighlight lang="lua">bool, int voteKick ( player thePlayer )</syntaxhighlight><br />
Starts a votekick. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
===voteKill===<br />
<syntaxhighlight lang="lua">bool, int voteKill ( player thePlayer )</syntaxhighlight><br />
Starts a votekill. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
===voteBan===<br />
<syntaxhighlight lang="lua">bool, int voteBan ( player thePlayer )</syntaxhighlight><br />
Starts a voteban. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
==Serverside events==<br />
===onPollStarting===<br />
<syntaxhighlight lang="lua">void onPollStarting ( table pollData )</syntaxhighlight><br />
Fired before a poll is starting. Allow other resources to modify the poll. Use onPollModified to send the poll back.<br />
<br />
===onPollModified===<br />
<syntaxhighlight lang="lua">void onPollModified ( table pollData )</syntaxhighlight><br />
You can use it to send the modified poll.<br />
<br />
===onPollStart===<br />
<syntaxhighlight lang="lua">void onPollStart ( )</syntaxhighlight><br />
Fired before a poll starts. Cancelling it aborts the poll.<br />
<br />
===onPollStop===<br />
<syntaxhighlight lang="lua">void onPollStop ( )</syntaxhighlight><br />
Fired before a poll is halted. Cancelling it prevents the poll from being halted.<br />
<br />
===onPollEnd===<br />
<syntaxhighlight lang="lua">void onPollEnd ( )</syntaxhighlight><br />
Fired after a poll finished. Cancelling it has no effect.<br />
<br />
===onPollDraw===<br />
<syntaxhighlight lang="lua">void onPollDraw ( )</syntaxhighlight><br />
Fired when a poll ends in a draw. Cancelling it aborts renominations.<br />
<br />
===onClientSendVote===<br />
<syntaxhighlight lang="lua">void onClientSendVote ( int vote )</syntaxhighlight><br />
Fired when a vote is sent to the server. ''client'' is the client who sent the vote. Cancelling it makes the manager ignore the client's choice.<br />
<br />
==Default settings==<br />
<syntaxhighlight lang="xml"><br />
<settings><br />
<setting name="*color" value="#DF6464" /><br />
<setting name="*log_votes" value="[true]" /><br />
<br />
<setting name="*default.timeout" value="[30]"/><br />
<setting name="*default.allowchange" value="[false]"/><br />
<setting name="*default.percentage" value="[75]"/><br />
<setting name="*default.maxnominations" value="[3]"/><br />
<br />
<setting name="*votemap.enabled" value="[true]"/><br />
<setting name="*votemap.timeout" value="[30]"/><br />
<setting name="*votemap.locktime" value="[60]"/><br />
<setting name="*votemap.percentage" value="[70]"/><br />
<setting name="*votemap.allowchange" value="[true]"/><br />
<br />
<setting name="*votekick.enabled" value="[true]"/><br />
<setting name="*votekick.timeout" value="[30]"/><br />
<setting name="*votekick.locktime" value="[120]"/><br />
<setting name="*votekick.percentage" value="[75]"/><br />
<setting name="*votekick.allowchange" value="[true]"/><br />
<br />
<setting name="*voteban.enabled" value="[false]"/><br />
<setting name="*voteban.timeout" value="[30]"/><br />
<setting name="*voteban.locktime" value="[120]"/><br />
<setting name="*voteban.percentage" value="[85]"/><br />
<setting name="*voteban.allowchange" value="[true]"/><br />
<br />
<setting name="*votekill.enabled" value="[true]"/><br />
<setting name="*votekill.timeout" value="[30]"/><br />
<setting name="*votekill.locktime" value="[120]"/><br />
<setting name="*votekill.percentage" value="[75]"/><br />
<setting name="*votekill.allowchange" value="[true]"/><br />
<br />
</settings><br />
</syntaxhighlight></div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Resource:Votemanager&diff=22378Resource:Votemanager2010-02-08T20:59:00Z<p>Flobu: added onPollStarting, onPollModified deleted votemap map gamemode</p>
<hr />
<div>{{Resource page}}<br />
__NOTOC__<br />
This script manages any kind of poll with multiple options. '''votemap''', '''votekick''', '''votekill''' and '''voteban''' are built in.<br />
==Built-in polls==<br />
<br />
'''votemap''' (starts a vote between a random list of up to 9 maps compatible with the current gamemode, if one is running)<br />
<br />
'''votemap gamemode''' (starts a vote between a random list of up to 9 maps compatible with the specified gamemode)<br />
<br />
'''votemap gamemode map''' (starts a vote to launch the specified gamemode with the specified map)<br />
<br />
'''votemap map''' (starts a vote to change to another map for the current gamemode, if one is running)<br />
<br />
'''votemode''' (starts a vote between a random list of up to 9 gamemodes. once the vote is done and a new gamemode is picked, automatically starts 'votemap gamemode')<br />
<br />
'''votekick player''' (starts a vote to kick the specified player)<br />
<br />
'''votekill player''' (starts a vote to kill the specified player)<br />
<br />
'''voteban player''' (starts a vote to ban the specified player)<br />
<br />
==Serverside functions==<br />
===startPoll===<br />
<syntaxhighlight lang="lua">bool, int startPoll ( table pollData )</syntaxhighlight><br />
Creates a poll. Returns ''true'' if the poll was created successfully, ''false'' and an error code otherwise (see the source for error codes).<br />
<br />
* '''pollData''' is a table containing poll settings and an array of ''at least two'' options. Each option comes in the form:<br />
<syntaxhighlight lang="lua"><br />
{<br />
string optionName,<br />
string eventToTrigger,<br />
[element triggerFrom = getRootElement()],<br />
default = [bool isDefaultOption = false],<br />
var argument1,<br />
var argument2,<br />
...<br />
}<br />
</syntaxhighlight><br />
The chosen option will trigger eventToTrigger from the triggerFrom element with ''arguments...'' as parameters when the poll ends.<br />
<br />
If there's not enough votes, the default option will be executed if there's one.<br />
<br />
Example:<br />
<syntaxhighlight lang="lua"><br />
local playerToKill = getRandomPlayer()<br />
local notEnoughVotesMessage = "Not enough votes to kill "..getPlayerName(playerToKill).."."<br />
startPoll {<br />
--start settings (dictionary part)<br />
title="Kill "..getPlayerName(playerToKill).."?",<br />
percentage=75,<br />
timeout=30,<br />
allowchange=false,<br />
maxnominations=3,<br />
visibleTo=getRootElement(),<br />
--start options (array part)<br />
[1]={"Yes", "doKillPlayer", playerToKill},<br />
[2]={"No", "doOutputChatBox", notEnoughVotesMessage, getRootElement(), vR, vG, vB; default=true},<br />
}<br />
</syntaxhighlight><br />
*'''title''' (required): the poll title which will be seen by clients on the manager GUI<br />
*'''percentage''' (optional, defaults to default.percentage): percentage needed for an option to pass<br />
*'''timeout''' (optional, defaults to default.timeout): poll timeout in seconds<br />
*'''allowchange''' (optional, defaults to default.allowchange): specifies if changing your vote is allowed<br />
*'''maxnominations''' (optional, defaults to default.maxnominations): specifies the max number of nominations in case there's a draw<br />
*'''visibleTo''' (optional, defaults to [[getRootElement]]()): a table or players that will be able to see the poll, OR an element that contains the players.<br />
If it is root, new players joining the server will be able to vote.<br />
<br />
''voteconfig.xml'' defaults will be used for missing optional settings.<br />
<br />
===stopPoll===<br />
<syntaxhighlight lang="lua">bool, int stopPoll ( )</syntaxhighlight><br />
Stops the running poll. Returns ''true'' if the current poll was stopped successfully, ''false'' and an error code otherwise.<br />
<br />
===voteMap===<br />
<syntaxhighlight lang="lua">bool, int voteMap ( string mapName )</syntaxhighlight><br />
Starts a votemap. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
===voteBetweenMaps===<br />
<syntaxhighlight lang="lua">bool, int voteBetweenMaps ( resource map1, resource map2, [ resource map3, ... ] )</syntaxhighlight><br />
Starts a poll to choose a map. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
===voteKick===<br />
<syntaxhighlight lang="lua">bool, int voteKick ( player thePlayer )</syntaxhighlight><br />
Starts a votekick. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
===voteKill===<br />
<syntaxhighlight lang="lua">bool, int voteKill ( player thePlayer )</syntaxhighlight><br />
Starts a votekill. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
===voteBan===<br />
<syntaxhighlight lang="lua">bool, int voteBan ( player thePlayer )</syntaxhighlight><br />
Starts a voteban. Returns ''true'' if it was successfully started, ''false'' and an error code otherwise.<br />
<br />
==Serverside events==<br />
===onPollStarting===<br />
<syntaxhighlight lang="lua">void onPollStarting ( )</syntaxhighlight><br />
Fired before a poll is starting. Allow other resources to modify the poll. Use onPollModified to send the poll back.<br />
<br />
===onPollModified===<br />
<syntaxhighlight lang="lua">void onPollModified ( )</syntaxhighlight><br />
You can use it to send the modified poll.<br />
<br />
===onPollStart===<br />
<syntaxhighlight lang="lua">void onPollStart ( )</syntaxhighlight><br />
Fired before a poll starts. Cancelling it aborts the poll.<br />
<br />
===onPollStop===<br />
<syntaxhighlight lang="lua">void onPollStop ( )</syntaxhighlight><br />
Fired before a poll is halted. Cancelling it prevents the poll from being halted.<br />
<br />
===onPollEnd===<br />
<syntaxhighlight lang="lua">void onPollEnd ( )</syntaxhighlight><br />
Fired after a poll finished. Cancelling it has no effect.<br />
<br />
===onPollDraw===<br />
<syntaxhighlight lang="lua">void onPollDraw ( )</syntaxhighlight><br />
Fired when a poll ends in a draw. Cancelling it aborts renominations.<br />
<br />
===onClientSendVote===<br />
<syntaxhighlight lang="lua">void onClientSendVote ( int vote )</syntaxhighlight><br />
Fired when a vote is sent to the server. ''client'' is the client who sent the vote. Cancelling it makes the manager ignore the client's choice.<br />
<br />
==Default settings==<br />
<syntaxhighlight lang="xml"><br />
<settings><br />
<setting name="*color" value="#DF6464" /><br />
<setting name="*log_votes" value="[true]" /><br />
<br />
<setting name="*default.timeout" value="[30]"/><br />
<setting name="*default.allowchange" value="[false]"/><br />
<setting name="*default.percentage" value="[75]"/><br />
<setting name="*default.maxnominations" value="[3]"/><br />
<br />
<setting name="*votemap.enabled" value="[true]"/><br />
<setting name="*votemap.timeout" value="[30]"/><br />
<setting name="*votemap.locktime" value="[60]"/><br />
<setting name="*votemap.percentage" value="[70]"/><br />
<setting name="*votemap.allowchange" value="[true]"/><br />
<br />
<setting name="*votekick.enabled" value="[true]"/><br />
<setting name="*votekick.timeout" value="[30]"/><br />
<setting name="*votekick.locktime" value="[120]"/><br />
<setting name="*votekick.percentage" value="[75]"/><br />
<setting name="*votekick.allowchange" value="[true]"/><br />
<br />
<setting name="*voteban.enabled" value="[false]"/><br />
<setting name="*voteban.timeout" value="[30]"/><br />
<setting name="*voteban.locktime" value="[120]"/><br />
<setting name="*voteban.percentage" value="[85]"/><br />
<setting name="*voteban.allowchange" value="[true]"/><br />
<br />
<setting name="*votekill.enabled" value="[true]"/><br />
<setting name="*votekill.timeout" value="[30]"/><br />
<setting name="*votekill.locktime" value="[120]"/><br />
<setting name="*votekill.percentage" value="[75]"/><br />
<setting name="*votekill.allowchange" value="[true]"/><br />
<br />
</settings><br />
</syntaxhighlight></div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Template:Radio_Station_IDs&diff=22263Template:Radio Station IDs2010-01-08T23:38:21Z<p>Flobu: </p>
<hr />
<div><div style="border:3px solid red;margin-bottom:3px;padding-left:5px;"><div style="float:right;padding-right:5px;font-weight:bold;"></div><br />
* '''0:''' Radio Off<br />
* '''1:''' Playback FM<br />
* '''2:''' K-Rose<br />
* '''3:''' K-DST<br />
* '''4:''' Bounce FM<br />
* '''5:''' SF-UR<br />
* '''6:''' Radio Los Santos<br />
* '''7:''' Radio X<br />
* '''8:''' CSR 103.9<br />
* '''9:''' K-Jah West<br />
* '''10:''' Master Sounds 98.3<br />
* '''11:''' WCTR<br />
* '''12:''' User Track Player<br />
</div></div>Flobuhttps://wiki.multitheftauto.com/index.php?title=GuiGetSize&diff=21065GuiGetSize2009-08-13T21:46:17Z<p>Flobu: /* Example */</p>
<hr />
<div>{{Client function}}<br />
__NOTOC__<br />
This function gets the size of a GUI element.<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
float float guiGetSize ( element theElement, bool relative )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''theElement:''' The GUI element to get size of.<br />
*'''relative:''' A boolean representing whether the size should be relative to the element's parent width, or an absolute size in pixels.<br />
<br />
===Returns===<br />
Returns the GUI element size ''x'' and ''y'' if the function has been successful, ''false'' otherwise.<br />
<br />
==Example== <br />
This example creates a random sized gui window and outputs its size to the chatbox.<br />
<syntaxhighlight lang="lua"><br />
local window = guiCreateWindow ( 0, 0, (math.random ( 0, 100 ) / 100), (math.random ( 0, 100 ) / 100), "test", true ) <br />
-- Create the window<br />
local x, y = guiGetSize ( window, false ) -- Get the gui window size<br />
outputChatBox ( "Window size: " .. x .. " " .. y ) --output the gui window size<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{GUI functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=SetVehicleAdjustableProperty&diff=21047SetVehicleAdjustableProperty2009-08-11T10:51:37Z<p>Flobu: /* See Also */</p>
<hr />
<div>{{client function}}<br />
__NOTOC__<br />
<br />
This function is used for adjusting the movable parts of a model, for example hydra jets or dump truck tray.<br />
This function only works on vehicles with adjustable properties.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool setVehicleAdjustableProperty ( element theVehicle, int value )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''theVehicle''': The vehicle you wish to change the adjustable property of.<br />
*'''value''': A value from 0 between ?. (Set the adjustable value between 0 and N. 0 is the default value. It is possible to force the setting beyond default maximum, for example setting above 5000 on the dump truck (normal max 2500) will cause the tray to be fully vertical.)<br />
<br />
===Returns===<br />
Returns true if the adjustable property was set. Otherwise false.<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
Needs an example.<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Client_vehicle_functions}}<br />
[[Category:Needs_Example]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=SetVehicleAdjustableProperty&diff=21046SetVehicleAdjustableProperty2009-08-11T10:47:36Z<p>Flobu: </p>
<hr />
<div>{{client function}}<br />
__NOTOC__<br />
<br />
This function is used for adjusting the movable parts of a model, for example hydra jets or dump truck tray.<br />
This function only works on vehicles with adjustable properties.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool setVehicleAdjustableProperty ( element theVehicle, int value )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''theVehicle''': The vehicle you wish to change the adjustable property of.<br />
*'''value''': A value from 0 between ?. (Set the adjustable value between 0 and N. 0 is the default value. It is possible to force the setting beyond default maximum, for example setting above 5000 on the dump truck (normal max 2500) will cause the tray to be fully vertical.)<br />
<br />
===Returns===<br />
Returns true if the adjustable property was set. Otherwise false.<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
Needs an example.<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Vehicle_functions}}<br />
[[Category:Needs_Example]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Template:DxFonts&diff=21029Template:DxFonts2009-08-09T21:48:06Z<p>Flobu: added Microsoft Sans Serif font</p>
<hr />
<div>** '''"default":''' Tahoma<br />
** '''"default-bold":''' Tahoma Bold<br />
** '''"clear":''' Verdana<br />
** '''"arial":''' Arial<br />
** '''"sans":''' Microsoft Sans Serif<br />
** '''"pricedown":''' Pricedown (GTA's theme text)<br />
<br />
{{New feature|3|1.0|<br />
** '''"bankgothic":''' Bank Gothic Medium<br />
** '''"diploma":''' Diploma Regular<br />
** '''"beckett":''' Beckett Regular<br />
}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=OnClientPreRender&diff=20990OnClientPreRender2009-08-06T20:24:29Z<p>Flobu: /* Parameters */</p>
<hr />
<div>__NOTOC__<br />
{{Client event}} <br />
This event is triggered every time before GTA renders a new frame.<br />
<br />
==Parameters==<br />
<syntaxhighlight lang="lua"><br />
float timeSlice<br />
</syntaxhighlight><br />
*'''timeSlice:''' The interval between this frame and the previous one in milliseconds (varies from 0 to 100).<br />
<br />
==Source==<br />
The [[event system#Event source|source]] of this event is the client's [[root element]].<br />
<br />
==Example==<br />
This example makes the camera follow the player in a GTA2-like way.<br />
<syntaxhighlight lang="lua"><br />
function updateCamera ()<br />
local x, y, z = getElementPosition ( getLocalPlayer () )<br />
setCameraMatrix ( x, y, z + 50, x, y, z )<br />
end<br />
addEventHandler ( "onClientPreRender", getLocalPlayer(), updateCamera )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
===Other client events===<br />
{{Client_other_events}}<br />
===Client event functions===<br />
{{Client_event_functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=GetPlayerFromName&diff=20933GetPlayerFromName2009-07-30T12:42:27Z<p>Flobu: Created page with '{{Server client function}} __NOTOC__ {{Deprecated}} This function returns a player element for the player with the name passed to the function. ==Syntax== <syntaxhighlight lang="lua"> …'</p>
<hr />
<div>{{Server client function}}<br />
__NOTOC__<br />
{{Deprecated}}<br />
This function returns a [[player]] [[element]] for the player with the name passed to the function.<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua"><br />
player getPlayerFromName ( string playerName )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
* '''playerName''': A string containing the name of the player you want to reference<br />
<br />
===Returns===<br />
Returns a [[player]] [[element]] for the player with the nickname provided. If there is no player with that name, ''false'' is returned.<br />
<br />
==Example==<br />
This example finds a [[player]] as specified in the command and outputs the direction and distance he is from the player who entered the command. For example: 'locate someguy'.<br />
<syntaxhighlight lang="lua"><br />
function locatePlayer( sourcePlayer, command, who )<br />
local targetPlayer = getPlayerFromName ( who ) -- find the player that was specified in the command<br />
if ( targetPlayer ) then -- if a player was found<br />
local x,y,z = getElementPosition ( sourcePlayer ) -- save the position of the player who entered the command<br />
local xp,yp,zp = getElementPosition ( targetPlayer ) -- save the position of the player who should be located<br />
local dir = nil<br />
if (yp > y) then<br />
dir = "N"<br />
else<br />
dir = "S"<br />
end<br />
if (xp > x) then<br />
dir = dir .. "E"<br />
else<br />
dir = dir .. "W"<br />
end<br />
local distance = math.ceil ( getDistanceBetweenPoints3D(x, y, z, xp, yp, zp) )<br />
outputChatBox( who .. " found " .. dir .. " (" .. distance .. ")", sourcePlayer) -- output the message<br />
end<br />
end<br />
addCommandHandler ( "locate", locatePlayer )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Player functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=OnClientGUIDoubleClick&diff=20829OnClientGUIDoubleClick2009-07-23T10:12:35Z<p>Flobu: </p>
<hr />
<div>{{Client event}}<br />
__NOTOC__ <br />
This event is fired when the user double clicks a GUI element.<br />
<br />
==Parameters== <br />
<syntaxhighlight lang="lua"><br />
string button, string state, int absoluteX, int absoluteY<br />
</syntaxhighlight><br />
*'''button:''' the name of the mouse button that the GUI element was double clicked with.<br />
*'''state:''' the state of the mouse button. "down" or "up".<br />
*'''absoluteX:''' the X position of the mouse cursor, in pixels, measured from the left side of the screen.<br />
*'''absoluteY:''' the Y position of the mouse cursor, in pixels, measured from the top of the screen.<br />
<br />
==Source==<br />
The source of this event is the GUI element that was double clicked.<br />
<br />
==Example== <br />
<br />
<syntaxhighlight lang="lua"><br />
<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
===GUI events===<br />
{{GUI_events}}<br />
===Client event functions===<br />
{{Client_event_functions}}<br />
<br />
[[Category:Incomplete Event]]<br />
[[Category:Needs_Example]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Check&diff=20650Check2009-07-18T11:57:24Z<p>Flobu: /* Example */ changed third and fourth dividend to divisor</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function checks the given arguments and calls the error-function if something is wrong. Finally it makes debugging easier since you'll get useful error-messages when calling a selfmade function with wrong or malformed arguments.<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua">void Check( string funcname, var types1, var arg1, string argname1, [ ... ] )</syntaxhighlight><br />
<br />
===Required Arguments===<br />
* '''funcname''': Name of the function in which the Check-function is called.<br />
* '''types1''': Type(s) that arg1 should/may be of. It's a string if only one type is possible, otherwise it can be a table with strings. Possible types are "nil", "boolean", "number", "string", "function", "table", "thread" and "userdata".<br />
* '''arg1''': Value of the argument that should be checked.<br />
* '''argname1''': Name of the argument whose value is arg1.<br />
<br />
===Optional Arguments===<br />
{{OptionalArg}}<br />
* '''...''': You may pass as many triples as you want to.<br />
<br />
==Code==<br />
<section name="Server- and/or clientside Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function Check(funcname, ...)<br />
local arg = {...}<br />
<br />
if (type(funcname) ~= "string") then<br />
error("Argument type mismatch at 'Check' ('funcname'). Expected 'string', got '"..type(funcname).."'.", 2)<br />
end<br />
if (#arg % 3 > 0) then<br />
error("Argument number mismatch at 'Check'. Expected #arg % 3 to be 0, but it is "..(#arg % 3)..".", 2)<br />
end<br />
<br />
for i=1, #arg-2, 3 do<br />
if (type(arg[i]) ~= "string" and type(arg[i]) ~= "table") then<br />
error("Argument type mismatch at 'Check' (arg #"..i.."). Expected 'string' or 'table', got '"..type(arg[i]).."'.", 2)<br />
elseif (type(arg[i+2]) ~= "string") then<br />
error("Argument type mismatch at 'Check' (arg #"..(i+2).."). Expected 'string', got '"..type(arg[i+2]).."'.", 2)<br />
end<br />
<br />
if (type(arg[i]) == "table") then<br />
local aType = type(arg[i+1])<br />
for _, pType in next, arg[i] do<br />
if (aType == pType) then<br />
aType = nil<br />
break<br />
end<br />
end<br />
if (aType) then<br />
error("Argument type mismatch at '"..funcname.."' ('"..arg[i+2].."'). Expected '"..table.concat(arg[i], "' or '").."', got '"..aType.."'.", 3)<br />
end<br />
elseif (type(arg[i+1]) ~= arg[i]) then<br />
error("Argument type mismatch at '"..funcname.."' ('"..arg[i+2].."'). Expected '"..arg[i].."', got '"..type(arg[i+1]).."'.", 3)<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Server- and/or clientside Example" class="both" show="true"><br />
This example shows the Check-function's usage in case of a more or less useless division function.<br />
<syntaxhighlight lang="lua"><br />
-- define the function<br />
function divide(dividend, divisor, round)<br />
-- check the passed arguments<br />
Check("divide", "number", dividend, "dividend", "number", divisor, "divisor", {"nil","boolean"}, round, "round")<br />
<br />
-- error if divisor is 0<br />
if (divisor == 0) then error("Someone tried to divide by 0. YOU MUST NOT DO THAT!!!") end<br />
<br />
-- calculate the result<br />
local quotient = dividend / divisor<br />
-- round the result if round is true<br />
if (round) then quotient = math.floor(quotient + .5)<br />
<br />
-- return the result<br />
return quotient<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
Author: NeonBlack<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=GuiCreateStaticImage&diff=19946GuiCreateStaticImage2009-06-16T21:15:05Z<p>Flobu: removing resource argument</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 />
*'''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 location of the image file that is being loaded. This should be the same as an image file specified in meta.xml file.<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 />
[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 />
<info author="Yourname" version="1.0" /><br />
<script src="example.lua" type="client" /><br />
<file src="imagename.png" /><br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{GUI_functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Weather&diff=19836Weather2009-06-09T13:00:34Z<p>Flobu: </p>
<hr />
<div>Weather can be changed using [[setWeather]] and [[setWeatherBlended]].<br />
{{New feature|3|1.0|<br />
Mixed weather ID's between 20 and 255 are also supported.<br />
}}<br />
<br />
==Weather IDs==<br />
* '''0 to 7:''' Different Versions of Blue Skies / Clouds <br />
* '''8:''' Stormy<br />
* '''9:''' Cloudy and Foggy<br />
* '''10:''' Clear Blue Sky<br />
* '''11:''' Scorching Hot (Los Santos heat waves)<br />
* '''12 to 15:''' Very Dull, Colourless, Hazy<br />
* '''16:''' Dull, Cloudy, Rainy<br />
* '''17 to 18:''' Scorching Hot<br />
* '''19:''' Sandstorm<br />
* '''20:''' Foggy, Greenish<br />
* '''21 to 22:''' Very dark, gradiented skyline, purple<br />
* '''23 to 26:''' Pale orange<br />
* '''27 to 29:''' Fresh blue<br />
* '''30 to 32:''' Dark, cloudy, teal<br />
* '''33:''' Dark, cloudy, brown<br />
* '''34:''' Blue/purple, regular<br />
* '''35:''' Dull brown<br />
* '''36 to 38:''' Bright, foggy, orange<br />
* '''39:''' Very bright<br />
* '''40 to 42:''' Blue/purple cloudy<br />
* '''43:''' Toxic clouds<br />
* '''44:''' Black/white sky<br />
* '''51 to 53:''' Amazing draw distance<br />
* '''150:''' Darkest weather ever<br />
* '''700:''' Stormy weather with pink sky and crystal water<br />
<br><br />
==See Also==<br />
[[id|ID Lists]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Weather&diff=19835Weather2009-06-09T12:59:58Z<p>Flobu: more weather ids</p>
<hr />
<div>Weather can be changed using [[setWeather]] and [[setWeatherBlended]].<br />
{{New feature|3|1.0|<br />
Mixed weather ID's between 20 and 255 are also supported.<br />
}}<br />
<br />
==Weather IDs==<br />
* '''0 to 7:''' Different Versions of Blue Skies / Clouds <br />
* '''8:''' Stormy<br />
* '''9:''' Cloudy and Foggy<br />
* '''10:''' Clear Blue Sky<br />
* '''11:''' Scorching Hot (Los Santos heat waves)<br />
* '''12 to 15:''' Very Dull, Colourless, Hazy<br />
* '''16:''' Dull, Cloudy, Rainy<br />
* '''17 to 18:''' Scorching Hot<br />
* '''19:''' Sandstorm<br />
* '''20:''' Foggy, Greenish<br />
* '''21 to 22:''' Very dark, gradiented skyline, purple<br />
* '''23 to 26:''' Pale orange<br />
* '''27 to 29:''' Fresh blue<br />
* '''30 to 32:''' Dark, cloudy, teal<br />
* '''33:''' Dark, cloudy, brown<br />
* '''34:''' Blue/purple, regular<br />
* '''35:''' Dull brown<br />
* '''36 to 38:''' Bright, foggy, orange<br />
* '''39:''' Very bright<br />
* '''40 to 42:''' Blue/purple cloudy<br />
* '''43:''' Toxic clouds<br />
* '''44:''' Black/white sky<br />
* '''51 to 53:''' Amazing draw distance<br />
* '''700:''' Stormy weather with pink sky and crystal water<br />
* '''150:''' Darkest weather ever<br />
<br><br />
==See Also==<br />
[[id|ID Lists]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=How_you_can_help&diff=19834How you can help2009-06-08T22:01:09Z<p>Flobu: Undo revision 19833 by Mostafatr (Talk)</p>
<hr />
<div>__NOTOC__<br />
Multi Theft Auto has loads of areas in which you can help us. In turn, we'll be more than happy to help you get started with any ideas you have, help test them and - if they're good enough - release them to the whole community. This page outlines the key areas you could do something in, of course, there's many things we've not thought of, so think outside the box!<br />
<br />
==Scripting==<br />
* Create a gamemode<br />
* Create an administration page on the HTTP server<br />
* Make a general purpose resource that provides useful functions to other resources<br />
<br />
==Mapping==<br />
* Create a map with the map editor for an existing gamemode<br />
<br />
==Web development==<br />
* Work with lil_Toady to add new features and improvements to community.mtasa.com<br />
* Create your own system for statistics - using the [[PHP SDK]] as a basis. Contact eAi or jbeta for help.<br />
<br />
==Documentation==<br />
* Finish documentation for [[:Category:Incomplete|Incomplete functions]] - ask in #mta.scripting if you're not sure of something<br />
* Add examples to [[:Category:Needs Example|functions missing examples]] - please test them, and again, as if you need help<br />
* Expand the pages that explain [[:Category:Scripting_Concepts|MTA core concepts]]<br />
<br />
==Specific tasks==<br />
* Create a fuzzer to check for crashes in our scripting functions<br />
* Help develop/fix existing gamemodes. Contact the original author on IRC (or ask a developer) to tell the author so you can work together.<br />
* The web interface resources (resourcemanager, resourcebrowser and webadmin chiefly) are really only compatible with Firefox. Someone could put in some time to make these work on Internet Explorer, Opera and Safari. See eAi for help.<br />
<br />
[[pl:Jak możesz pomóc]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=CreateBlipAttachedTo&diff=19832CreateBlipAttachedTo2009-06-08T18:31:21Z<p>Flobu: </p>
<hr />
<div>__NOTOC__ <br />
{{Server client function}}<br />
This function creates a [[blip]] that is attached to an [[element]]. This blip is displayed as an icon on the client's radar and will 'follow' the element that it is attached to around.<br />
<br />
==Syntax==<br />
<section name="Server" class="server" show="true"><br />
<syntaxhighlight lang="lua"><br />
blip createBlipAttachedTo ( element elementToAttachTo, [int icon=0, int size=2, int r=255, int g=0, int b=0, int a=255, int ordering=0, float visibleDistance=99999.0, visibleTo = getRootElement()] )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''elementToAttachTo:''' The [[element]] to attach the marker to.<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}} <br />
*'''icon:''' The icon that the radar blips should be. Valid values are:<br />
{{Blip_Icons}}<br />
*'''size:''' The size of the radar blip. Default is 2.<br />
*'''r:''' The amount of red in the blip's color (0 - 255). Only applicable to the ''none'' icon. 'Default is 255. <br />
*'''g:''' The amount of green in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 0.<br />
*'''b:''' The amount of blue in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 0.<br />
*'''a:''' The amount of alpha in the blip's color (0 - 255). Default is 255.<br />
{{New feature|3|1.0|<br />
*'''ordering:''' This defines the blip's Z-level ordering (-32768 - 32767). Default is 0.<br />
*'''visibleDistance:''' The maximum distance from the camera at which the blip is still visible<br />
}}<br />
*'''visibleTo:''' What elements can see the blip. Defaults to visible to everyone. See [[visibility]].<br />
</section><br />
<section name="Client" class="client" show="false"><br />
<syntaxhighlight lang="lua"><br />
blip createBlipAttachedTo ( element elementToAttachTo, [int icon=0, int size=2, int r=255, int g=0, int b=0, int a=255, int ordering=0, float visibleDistance=99999.0] )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''elementToAttachTo:''' The [[element]] to attach the marker to.<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}} <br />
*'''icon:''' The icon that the radar blips should be. Valid values are:<br />
{{Blip_Icons}}<br />
*'''size:''' The size of the radar blip. Default is 2.<br />
*'''r:''' The amount of red in the blip's color (0 - 255). Only applicable to the ''none'' icon. 'Default is 255. <br />
*'''g:''' The amount of green in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 0.<br />
*'''b:''' The amount of blue in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 0.<br />
*'''a:''' The amount of alpha in the blip's color (0 - 255). Default is 255.<br />
{{New feature|3|1.0|<br />
*'''ordering:''' This defines the blip's Z-level ordering (-32768 - 32767). Default is 0.<br />
*'''visibleDistance:''' The maximum distance from the camera at which the blip is still visible<br />
}}<br />
</section><br />
<br />
===Returns===<br />
Returns a [[blip]] if the blip was created succesfully, or ''false'' otherwise.<br />
<br />
==Example== <br />
<section name="Server" class="server" show="true"><br />
This example creates a radar blip attached to a random player, visible to everyone. The blip will follow the player around as they move. This could be used for manhunt, to emphasise a random player.<br />
<syntaxhighlight lang="lua"><br />
-- Pick a random player<br />
function setupRandomRobber ()<br />
local myPlayer = getRandomPlayer ()<br />
-- Create a radar blip at the player's position, with a 'cash' icon and only visible to everyone (no 'visibleTo' parameter)<br />
local myBlip = createBlipAttachedTo ( myPlayer, 52 )<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{Blip_functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=CreateBlip&diff=19831CreateBlip2009-06-08T18:29:06Z<p>Flobu: </p>
<hr />
<div>__NOTOC__ <br />
{{Server client function}}<br />
This function creates a [[blip]] [[element]], which is displayed as an icon on the client's radar.<br />
<br />
==Syntax==<br />
<section name="Server" class="server" show="true"><br />
<syntaxhighlight lang="lua"><br />
blip createBlip ( float x, float y, float z, [int icon=0, int size=2, int r=255, int g=0, int b=0, int a=255, int ordering=0 *, float visibleDistance=99999.0, visibleTo = getRootElement()] )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''x:''' The x position of the blip, in world coordinates.<br />
*'''y:''' The y position of the blip, in world coordinates.<br />
*'''z:''' The z position of the blip, in world coordinates.<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}} <br />
*'''icon:''' The icon that the radar blips should be. Valid values are:<br />
{{Blip_Icons}}<br />
*'''size:''' The size of the radar blip. Default is 2.<br />
*'''r:''' The amount of red in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 255. <br />
*'''g:''' The amount of green in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 0.<br />
*'''b:''' The amount of blue in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 0.<br />
*'''a:''' The amount of alpha in the blip's color (0 - 255). Default is 255.<br />
{{New feature|3|1.0|<br />
*'''ordering:''' This defines the blip's Z-level ordering (-32768 - 32767). Default is 0.<br />
*'''visibleDistance:''' The maximum distance from the camera at which the blip is still visible<br />
}}<br />
*'''visibleTo:''' What elements can see the blip. Defaults to visible to everyone. See [[visibility]].<br />
</section><br />
<section name="Client" class="client" show="false"><br />
<syntaxhighlight lang="lua"><br />
blip createBlip ( float x, float y, float z, [int icon=0, int size=2, int r=255, int g=0, int b=0, int a=255, int ordering=0, float visibleDistance ] )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''x:''' The x position of the blip, in world coordinates.<br />
*'''y:''' The y position of the blip, in world coordinates.<br />
*'''z:''' The z position of the blip, in world coordinates.<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}} <br />
*'''icon:''' The icon that the radar blips should be. Valid values are:<br />
{{Blip_Icons}}<br />
*'''size:''' The size of the radar blip. Default is 2.<br />
*'''r:''' The amount of red in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 255. <br />
*'''g:''' The amount of green in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 0.<br />
*'''b:''' The amount of blue in the blip's color (0 - 255). Only applicable to the ''none'' icon. Default is 0.<br />
*'''a:''' The amount of alpha in the blip's color (0 - 255). Default is 255.<br />
{{New feature|3|1.0|<br />
*'''ordering:''' This defines the blip's Z-level ordering (-32768 - 32767). Default is 0.<br />
*'''visibleDistance:''' The maximum distance from the camera at which the blip is still visible<br />
}}<br />
</section><br />
<br />
==Returns==<br />
Returns an [[element]] of the [[blip]] if it was created successfully, ''false'' otherwise.<br />
<br />
==Example== <br />
<section name="Server" class="server" show="true"><br />
'''Example 1:''' This example creates a radar blip at a random player's position and makes it so that it is only visible to that player.<br />
<syntaxhighlight lang="lua"><br />
-- Pick a random player<br />
myPlayer = getRandomPlayer ()<br />
-- Retrieve the player's position and store it in the variables x, y and z<br />
x,y,z = getElementPosition ( myPlayer )<br />
-- Create a radar blip at the player's position, with a 'cash' icon and only visible to the player<br />
myBlip = createBlip ( x, y, z, 51, 0, 0, 0, 255, myPlayer )<br />
</syntaxhighlight><br />
<br />
'''Example 2:''' This example attaches a blip to a player. You can attach a blip to an element by just setting the blip's parent to that element.<br />
<syntaxhighlight lang="lua"><br />
-- Pick a random player<br />
myPlayer = getRandomPlayer ()<br />
-- Create a radar blip in the middle of the map<br />
myBlip = createBlip ( 0, 0, 0 )<br />
-- Make the player the parent of the blip, so that the blip follows the player around<br />
setElementParent ( myBlip, myPlayer )<br />
</section><br />
<br />
==See Also==<br />
{{Blip_functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=GetScreenFromWorldPosition&diff=19823GetScreenFromWorldPosition2009-06-07T21:29:00Z<p>Flobu: </p>
<hr />
<div>__NOTOC__<br />
{{Client function}}<br />
This function gets the screen position of a point in the world. This is useful for attaching 2D gui elements to parts of the world (e.g. players) or detecting if a point is on the screen (though it does not check if it is actually visible, you should use [[processLineOfSight]] for that).<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua"><br />
float float getScreenFromWorldPosition ( float x, float y, float z [, float edgeTolerance=0, bool relative=false] )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''x:''' A float value indicating the x position in the world.<br />
*'''y:''' A float value indicating the y position in the world.<br />
*'''z:''' A float value indicating the z position in the world.<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}}<br />
{{New feature|3|1.0|<br />
*'''edgeTolerance:''' A [[float]] value indicating the tolerance which is used to calculate the screen position of positions that are slightly off-screen<br />
*'''relative:''' A [[boolean]] value that indicates if the returned x/y positions are relative to the screen size <br />
}}<br />
<br />
===Returns===<br />
Returns two ''x'', ''y'' [[float]]s indicating the screen position if successful, ''false'' otherwise.<br />
<br />
==See Also==<br />
{{Client_world_functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=GetScreenFromWorldPosition&diff=19811GetScreenFromWorldPosition2009-06-07T11:56:47Z<p>Flobu: add edgeTolerance and relative parameters</p>
<hr />
<div>__NOTOC__<br />
{{Client function}}<br />
This function gets the screen position of a point in the world. This is useful for attaching 2D gui elements to parts of the world (e.g. players) or detecting if a point is on the screen (though it does not check if it is actually visible, you should use [[processLineOfSight]] for that).<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua"><br />
float float getScreenFromWorldPosition ( float x, float y, float z, float edgeTolerance, bool relative )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''x:''' A float value indicating the x position in the world.<br />
*'''y:''' A float value indicating the y position in the world.<br />
*'''z:''' A float value indicating the z position in the world.<br />
<br />
===Optional Arguments=== <br />
{{OptionalArg}}<br />
*'''edgeTolerance:''' A float value indicating the tolerance which is used to calculate the screen position<br />
*'''relative:''' Bool that indicates if the returned x/y positions are relative to the screen size <br />
<br />
===Returns===<br />
Returns two ''x'', ''y'' [[float]]s indicating the screen position if successful, ''false'' otherwise.<br />
<br />
==See Also==<br />
{{Client_world_functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=SetPedAnimation&diff=19801SetPedAnimation2009-06-04T12:30:20Z<p>Flobu: /* Syntax */</p>
<hr />
<div>__NOTOC__<br />
{{Server client function}}<br />
<br />
Sets the current animation of a player or ped. Not specifying the type of animation will automatically cancel the current one.<br />
<br />
==Syntax==<br />
<section name="Server" class="server" show="true"><br />
<syntaxhighlight lang="lua"><br />
bool setPedAnimation ( ped thePed, [string block=nil, string anim=nil, float blendDelta=1.0,bool loop=true, bool updatePosition=true] )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''thePed:''' the player or ped you want to apply an animation to.<br />
<br />
===Optional Arguments===<br />
*'''block:''' the [[Animations|animation]] block's name.<br />
*'''anim:''' the name of the [[Animations|animation]] within the block.<br />
*'''blendDelta:''' the speed at which the previous and current animation are blended.<br />
*'''loop:''' indicates whether or not the animation will loop.<br />
*'''updatePosition:''' will change the actual coordinates of the ped according to the animation. Use this for e.g. walking animations.<br />
</section><br />
<br />
<section name="Client" class="client" show="false"><br />
<syntaxhighlight lang="lua"><br />
bool setPedAnimation ( ped thePed, [string block=nil, string anim=nil, float blendDelta=1.0,bool loop=true, bool updatePosition=true,function callbackFunction, var arguments, ...] )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''thePed:''' the player or ped you want to apply an animation to.<br />
<br />
===Optional Arguments===<br />
*'''block:''' the [[Animations|animation]] block's name.<br />
*'''anim:''' the name of the [[Animations|animation]] within the block.<br />
*'''blendDelta:''' the speed at which the previous and current animation are blended.<br />
*'''loop:''' indicates whether or not the animation will loop.<br />
*'''updatePosition:''' will change the actual coordinates of the ped according to the animation. Use this for e.g. walking animations.<br />
*'''callbackFunction''' A function that is called when the animation is finished<br />
*'''arguments''' Any arguments you want to pass to the callbackFunction, eg: animation name<br />
</section><br />
<br />
===Returns===<br />
Returns ''true'' if succesful, ''false'' otherwise.<br />
<br />
==Example== <br />
<br />
<section name="Client" class="client" show="true"><br />
This example creates a ped, rotates them, and makes them walk:<br />
<syntaxhighlight lang="lua"><br />
function makePed ( )<br />
ped1 = createPed ( 56, 1, 1, 4 )<br />
setPedRotation( ped1, 315 )<br />
setPedAnimation( ped1, "ped", "WOMAN_walknorm")<br />
end<br />
addEventHandler ( "onResourceStart", getRootElement(), makePed )<br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{Ped_functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Talk:IfElse&diff=19799Talk:IfElse2009-06-04T09:45:36Z<p>Flobu: </p>
<hr />
<div>There's not really any use for this, as far as i can tell. Lua supports this by its syntax sugars:<br />
<br />
moo = (variable) and (ifTrue) or (ifFalse)<br />
<br />
works the same as <br />
<br />
moo = (varible) ? ifTrue : ifFalse <br />
<br />
in C++.<br />
----<br />
oO You're right. Never thought of that. What I was thinking about, too, was something like<br />
<syntaxhighlight lang="lua">moo = ({ [true] = ifTrue, [false] = ifFalse })[condition]</syntaxhighlight><br />
But your code is much better. Thanks for posting this. ;D [[User:NeonBlack|NeonBlack]] 22:00, 18 May 2009 (CEST)<br />
<br />
----<br />
The problem with the plain Lua version is that 'ifTrue' is also part of the test condition.<br />
Consider this:<br />
<syntaxhighlight lang="lua"><br />
variable = true<br />
ifTrue = false<br />
ifFalse = true<br />
<br />
moo = (variable) ? ifTrue : ifFalse<br />
== false<br />
</syntaxhighlight><br />
ElseIf works fine here:<br />
<syntaxhighlight lang="lua"><br />
moo = IfElse( variable, ifTrue , ifFalse )<br />
== false<br />
</syntaxhighlight><br />
Lua's and's 'n' or's however may give unexpected results:<br />
<syntaxhighlight lang="lua"><br />
moo = (variable) and (ifTrue) or (ifFalse)<br />
moo == true<br />
</syntaxhighlight><br />
<br />
[[User:Ccw|MrSmartArse]] 08:46, 4 June 2009 (CEST)<br />
----<br />
<br />
it returns true because one of the two first arguments are false.<br />
<br />
this is lua's fault.<br />
<br />
[[User:Flobu|Flobu]] 11:43, 4 June 2009 (CEST)</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=DE/Lua_Tutorial&diff=19792DE/Lua Tutorial2009-06-02T21:02:02Z<p>Flobu: </p>
<hr />
<div>__TOC__<br />
<br />
==Vorwort==<br />
Da es bis auf einige knappe und teils unprofessionelle Tutorials kein deutsches Lua Tutorial gibt, habe ich beschlossen, nun ein eigenes zu schreiben, welches alle für MTA notwendigen Grundlagen einfach und übersichtlich erklärt.<br />
Weiterführende Möglichkeiten und Funktionen können der [http://www.lua.org/manual/5.1/ Offiziellen Lua Dokumentation] entnommen werden, die es jedoch nicht auf Deutsch gibt.<br />
<br />
Ein weiterer Grund ist, dass ich schon von einigen gehört habe und auch so schon den Verdacht hatte, dass MTA einfach so wenige deutsche Spieler und vor allem Server hat (gibt es überhaupt '''einen''' deutschen?), weil die meisten Probleme mit den englischen Dokumentationen haben oder der Meinung sind, dass für MTA ja sowieso kein deutscher Support vorhanden ist.<br />
<br />
Soviel nun dazu, wie es zu der Idee des deutschen Lua Tutorials kam.<br />
Fangen wir an mit dem Erlernen einer neuen Sprache!<br />
<br />
<br />
==Grundlagen==<br />
===Lua, eine Skriptsprache===<br />
Lua (portugiesisch für Mond) ist eine Skriptsprache zum Einbinden in Programme, um diese leichter weiterentwickeln und warten zu können. Insbesondere die geringe Größe des Interpreters von 120 KB und die hohe Geschwindigkeit verglichen mit anderen Skriptsprachen überzeugen viele Entwickler davon, Lua einzusetzen.<br />
<br />
Die Syntax lehnt sich an die von Pascal an, was besonders Anfängern den Einstieg in Lua erleichtert. Im Gegensatz zu von Pascal abgeleiteten Sprachen nutzt Lua jedoch „==“ und nicht „=“ als Vergleichsoperator.<br />
<br />
(Quelle: [http://de.wikipedia.org/wiki/Lua Wikipedia])<br />
<br />
Einige werden sich bei dieser Einführung vielleicht gefragt haben, was der Unterschied zwischen Skript- und Programmiersprache ist und was ein Interpreter sein soll. Im folgenden will ich diese beiden Fragen so kurz und einfach wie möglich klären.<br />
<br />
Eine '''Programmiersprache''' (z.B. C, C++, Pascal, Delphi) wird - wie der Name schon sagt - verwendet, um Programme zu schreiben. Ein Programm liegt bekannterweise in Form einer Executable (*.exe) vor. Diese kann weitgehend unabhängig von irgendwelchen Betriebssystemen oder der Umgebung selbstständig ausgeführt werden (z.B. durch Doppelklick). Weitgehend deswegen, da einige Programme aufgrund von Speicherersparnissen sogenannte Programmbibliotheken (original Dynamic Link Library, kurz dll) benötigen, um zu funktionieren. Erklärungen dazu findet ihr [http://de.wikipedia.org/wiki/Dynamic_Link_Library hier].<br><br />
Um einen Programmquellcode, d.h. einen Text, der in einer Programmiersprache geschrieben wurde, aus dem Textdokumentformat in eine Anwendung (original Executable, kurz exe) umzuwandeln, benötigt man nun einen Compiler (zu Deutsch Kompilierer oder Übersetzer), der die Programmiersprache aus der menschenlesbaren Form in die maschinenlesbare Form umwandelt. Neben dieser Hauptaufgabe übernimmt der Compiler natürlich noch weitere Aufgaben, auf die ich jetzt aber nicht genauer eingehen werde. Infos dazu findet ihr [http://de.wikipedia.org/wiki/Compiler hier].<br><br />
Die maschinenlesbare Form ist für Menschen unlesbar.<br />
<br />
Eine '''Skriptsprache''' (z.B. JavaScript, DOS-Batch(Win) bzw. Shell-Scripts(UNIX)) hingegen liegt standardmäßig in der menschenlesbaren Form vor. Skriptsprachen werden - wie im ersten Satz bereits erwähnt - vor allem von Programmen benutzt, um benutzerdefinierte Abläufe verwenden zu können. Zur Ausführung von Scripts wird ein sogenannter Interpreter benötigt, der das Skript liest und es Schritt für Schritt in die Maschinensprache umwandelt und ausführt. Manche Skriptsprachen kann man mit einem Precompiler (zu Deutsch Vorkompilierer oder Vorübersetzer) vorkompilieren. Diesen könnte man auch den Vorkauer vom Interpreter nennen, da er das Script schon zum Teil in die Maschinensprache umwandelt, jedoch nicht so extrem wie der Compiler der Programmiersprachen. Das Ergebnis davon ist logischerweise die schnellere Ausführung des Skripts.<br />
<br />
Genug der langweiligen Definitionen. Klären wir lieber, was man denn alles braucht, um ein Lua Script zu schreiben.<br />
<br />
===Materialien===<br />
Lua Skripte werden üblicherweise als Textdateien mit der Endung .lua gespeichert. Die Endung ist jedoch nicht von belang. Es kann jede beliebige Endung gewählt werden.<br />
<br />
Wie jede normale Textdatei kann man also auch Lua Skripte mit dem standard Texteditor des vorhandenen Betriebssystems schreiben, editieren und lesen. Ich persönlich empfehle jedoch das Programm Notepad++, welches [http://notepad-plus.sourceforge.net/de/site.htm hier] heruntergeladen werden kann. Das Programm ist Freeware und wird regelmäßig aktualisiert und erweitert. Der Vorteil daran ist, dass es ein professionelles Syntax-Highlighting eingebaut hat, welches Schlagwörter und Standardfunktionen farblich oder anderweitig hervorhebt und somit die Übersichtlichkeit erheblich verbessert.<br><br />
Standardmäßig wird die Sprache Lua automatisch an der Dateiendung .lua erkannt, solltest Du eine andere Endung verwenden und trotzdem das Lua Syntax-Highlighting verwenden wollen, kannst Du es oben im Menü „Sprachen“ einstellen.<br />
<br />
Wer ohne MTA seine kleinen Lua Skripte testen oder ausführen möchte, kann sich [http://luabinaries.luaforge.net/download.html hier] einen kostenlosen standalone Interpreter herunterladen. Wenn Du Dir nicht sicher bist, welche Windows Edition Du hast, dann hast Du wahrscheinlich eine 32 Bit Version, welche auf dieser Seite der „Windows x86 Executables“ entspricht. Die aktuelle Version (Win 32 Bit) dafür gibt es bei einem Klick auf [http://luaforge.net/frs/download.php/3134/lua5_1_3_Win32_bin.zip lua5_1_3_Win32_bin.zip].<br><br />
Nach dem Download kann der Standalone Interpreter mit einem Doppelklick auf die „lua5.1.exe“ gestartet werden. Dort kann man dann direkt Lua Befehle eingeben oder ein Script laden. Dies geht wie folgt:<br />
<syntaxhighlight lang="lua">dofile("dateiname.lua")</syntaxhighlight><br />
<br />
==Kommentare==<br />
Um sein Skript übersichtlicher zu gestalten, kann man mit Kommentaren bestimmte Zeilen eräutern, Bereiche abgrenzen, alten Code deaktivieren, ohne ihn zu entfernen und generell das Skript übersichtlicher gestalten.<br><br />
Kommentare werden vom Interpreter vollkommen ignoriert und sind nur für den Menschen lesbar und von Belang.<br />
<br />
===Einzeilig===<br />
<syntaxhighlight lang="lua">-- Dies ist ein einzeiliger Kommentar. Er gilt von -- bis zum Ende dieser Zeile. Automatische Zeilenumbrüche, die eingefügt werden, wenn die Zeilenlänge überschritten wurde, zählen nicht.</syntaxhighlight><br />
<br />
===Mehrzeilig===<br />
<syntaxhighlight lang="lua">--[[ Dieser Kommentar<br />
geht über beliebig viele Zeilen<br />
und endet mit ]]</syntaxhighlight><br />
<br />
<br />
==Variablen==<br />
===Einführung===<br />
Eine Variable kann man sich wie eine kleine Kiste vorstellen, auf der außen ein Bezeichner (oder Name) steht und die einen Wert enthält. Während der Bezeichner immer gleich ist, kann der Inhalt variieren.<br />
Jede Variable hat einen Variablentypen, der bei Programmiersprachen normalerweise zu Beginn des Programmes fest definiert wird und sich nicht ändern kann. Da Lua aber ja keine Programmiersprache ist, muss der Variablentyp zu Beginn und auch sonst nie festgelegt werden und kann sich beliebig oft verändern. Der Interpreter erkennt Variablentypen automatisch und nimmt dem Skripter somit eine Menge Arbeit (vor allem bzgl. der Planung) ab.<br />
<br />
===Typen===<br />
Im Folgenden will ich die wichtigsten Variablentypen auflisten und kurz beschreiben.<br />
;Integer (ganze Zahlen)<br />
:Umfasst alle Ganzzahlen, sowohl negative als auch positive.<br />
:Beispiele: -8, 0, 12, 2<br />
;Float (Komma- bzw. gebrochene Zahlen)<br />
:Umfasst alle Fließkommazahlen, sowohl negative als auch positive. Wichtig dabei ist, dass anstelle des Kommas (,) ein Dezimalpunkt (.) zum Trennen des ganzen vom gebrochenen Teil verwendet werden muss.<br />
:Beispiele: -77.2, 0.0, 3.14159, 9.81<br />
;String (Zeichenkette)<br />
:Kann jedes beliebige Zeichen enthalten. Eine maximale Länge ist mir nicht bekannt. Strings müssen immer in Anführungszeichen(" oder ') eingschlossen werden.<br />
:Beispiele: "hallo", 'Lua ist toll!', "", " :D "<br />
;Boolean (Schalter)<br />
:Kann zwei verschiedene Werte enthalten: ''true'' (dt. wahr bzw. an) oder ''false'' (dt. falsch bzw. aus). ''true'' entspricht dabei nicht dem Wert 1 und ''false'' nicht dem Wert 0.<br />
:Beispiele: ''true'', ''false''<br />
;Nil (Leer oder Nichts)<br />
:''nil'' ist sowohl ein Wert als auch ein Typ. Eine Variable vom Typ ''nil'' enthält automatisch den Wert ''nil''. ''nil'' bedeutet ganz einfach nichts. Wenn eine Variable ''nil'' ist, existiert sie nicht. ''nil'' entspricht weder dem Wert 0 noch dem Wert ''false'' noch dem Wert ""!<br />
:Beispiele: ''nil''<br />
Ich werde auf jeden Variablentypen noch detaillierter eingehen. Außerdem wurden hier die Variablentypen '''function''', '''table''' und '''userdata''' nicht aufgeführt, da diese jeweils ein eigenes Kapitel bekommen.<br />
<br />
===Deklaration===<br />
Eine Variable deklarieren bedeutet im Grunde genommen eine Variable anlegen. In Lua muss einer Variable bei der Deklaration ein Wert zugewiesen werden. ''nil'' ist dabei als Wert auch möglich, macht jedoch wenig Sinn, da jede beliebige Variablenbezeichnung automatisch den Wert ''nil'' enthält.<br />
<br />
Man unterscheidet zwischen '''lokalen''' und '''globalen''' Variablen. Um eine Variable als lokal zu definieren muss das Schlüsselwort ''local'' davor geschrieben werden. Lokal bedeutet für uns im Moment noch ganz einfach, dass die Variable nur im aktuellen Script verfügbar ist. Sollten also z.B. von einem Programm zwei verschiedene Lua Skripte geladen sein und benutzt werden, können diese untereinander auf die globalen Variablen des jeweils anderen Skripts zugreifen, auf die lokalen jedoch nicht. Generell empfiehlt es sich, immer lokale Variablen zu nehmen, falls man nicht explizit eine globale benötig, da so vermieden wird, dass mehrere parallel laufende Skripte aufgrund von gleichen Variablenbezeichnern durcheinander kommen.<br />
<br />
====Einzeln====<br />
Deklarieren wir uns also nun unsere erste lokale Variable und geben ihr einen Ganzzahligen Inhalt:<br />
<syntaxhighlight lang="lua">local zahl = 7 -- weist der lokalen Variable zahl den Wert 7 zu</syntaxhighlight><br />
<br />
Eine globale Variable erhält man, indem man einfach das ''local'' weglässt:<br />
<syntaxhighlight lang="lua">gZahl = 13 -- weist der globalen Variable gZahl den Wert 13 zu</syntaxhighlight><br />
<br />
Das selbe geht natürlich nun auch mit allen anderen Variablentypen:<br />
<syntaxhighlight lang="lua">local ganzzahl = -5<br />
local kommazahl = 0.008<br />
local zeichenkette = "Hello World"<br />
local schalter = true<br />
local nichts = nil -- diese Zeile kann man sich im Grunde genommen sparen, da jede nicht deklarierte Variable automatisch den Wert nil hat</syntaxhighlight><br />
<br />
Längere Strings mit mehreren Zeilenumbrüchen können in einer vereinfachten Weise zugewiesen werden. Dies funktioniert so ähnlich wie bei Kommentaren. Anstelle von Anführungszeichen verwendet man [[ als Anfangs- und ]] als Endmarkierung des Strings.<br />
<syntaxhighlight lang="lua">local text = [[Willkommen auf unserem Server.<br />
Bitte halte Dich an die Regeln.<br />
MfG die Administration]]</syntaxhighlight><br />
Alternativ kann in einem String, der in doppelten Anführungszeichen (") eingeschlossen ist, folgende Steuerzeichen enthalten:<br />
;\n<br />
:Entspricht einem Zeilenumbruch.<br />
;\t<br />
:Entspricht einem Tabulator.<br />
;\"<br />
:Wird verwendet, um doppelte Anführungszeichen in einem String, der von doppelten Anführungszeichen eingeschlossen ist, darzustellen, ohne dass der Interpreter diese fälschlicherweise als Stringende auffasst.<br />
;\'<br />
:Wie \", nur gilt dies in Strings, die von einfachen Anführungszeichen eingeschlossen sind.<br />
;\\<br />
:Entspricht einem Backslash (\)<br />
<br />
====Mehrere====<br />
Man kann in einer Zeile mehrere Variablen deklarieren, indem man sie mit Kommas voneinander trennt. Die Variablentypen können dabei alle unterschiedlich sein. Hier mal ein Beispiel:<br />
<syntaxhighlight lang="lua">local frucht, anzahl, reif = "apfel", 4, true</syntaxhighlight><br />
''local'' darf dabei nur einmal am Zeilenanfang stehen und bewirkt, dass alle dahinter aufgelisteten Variablen lokal werden.<br><br />
Sollten links neben dem Gleichheitszeichen mehr Variablenbezeichner stehen als rechts Werte, so bleiben die überschüssigen Variablen ''nil''. Im umgekehrten Fall werden überschüssige Werte rechts einfach ignoriert.<br />
<br />
Der Unterstrich (_) kann verwendet werden, wenn ein Wert auf der rechten Seite ignoriert werden soll.<br />
<syntaxhighlight lang="lua">local _, farbe = 7, "blau"</syntaxhighlight><br />
Dabei wird der Wert 7 komplett ignoriert und der Variable farbe der Wert "blau" zugewiesen. Diese Methode wird erst Sinn ergeben, wenn wir uns mit Funktionen und deren Rückgabewerte beschäftigen. Ich wollte sie jedoch der Vollständigkeit halber hier schon einmal erwähnen.<br />
<br />
<br />
==Operatoren==<br />
===Arithmetische===<br />
Arithmetische Operatoren werden verwendet, um Berechnungen durchzuführen. Somit kann man entweder mit Variablen, festen Zahlen oder einer Mischung neue Werte berechnen oder verändern.<br><br />
Bei Berechnungen gilt stets: '''Punkt- vor Strichrechnung'''.<br />
<br><br><br />
;Plus (+)<br />
:Addiert zwei Werte miteinander.<br />
<syntaxhighlight lang="lua">local a, b = 3, 8<br />
local c = a + b -- a + b entspricht hier der Rechnung 3 + 8, c erhält nun also den Wert 11</syntaxhighlight><br />
;Minus (-)<br />
:Subtrahiert den zweiten vom ersten Wert.<br />
<syntaxhighlight lang="lua">local a, b = 3, 8<br />
local c = a - b -- a - b entspricht hier der Rechnung 3 - 8, c erhält nun also den Wert -5</syntaxhighlight><br />
;Mal (*)<br />
:Multipliziert zwei Werte miteinander.<br />
<syntaxhighlight lang="lua">local a, b = 3, 8<br />
local c = a * b -- a * b entspricht hier der Rechnung 3 * 8, c erhält nun also den Wert 24</syntaxhighlight><br />
;Geteilt (/)<br />
:Dividiert den ersten durch den zweiten Wert. Hierbei entsteht in den meisten Fällen eine Kommazahl!<br />
<syntaxhighlight lang="lua">local a, b = 3, 8<br />
local c = a / b -- a / b entspricht hier der Rechnung 3 / 8, c erhält nun also den Wert 0.375</syntaxhighlight><br />
<br><br />
;Modulo (%)<br />
:Ermittelt den Rest, der übrig bleibt, wenn man die erste Zahl durch die zweite teilt.<br />
:Der Modulo-Operator gehört zur Punktrechnung.<br />
<syntaxhighlight lang="lua">local a, b = 14, 3<br />
local c = a % b -- a % b entspricht hier der Rechnung 14 % 3, c erhält nun also den Wert 2, da 14 / 3 = 4 REST 2</syntaxhighlight><br />
;Minus (-) (als Vorzeichen)<br />
:Dient zur Darstellung einer negativen Zahl, also einer Zahl unter 0.<br />
<syntaxhighlight lang="lua">local a = -3 -- entspricht der Rechnung a = 0 - 3</syntaxhighlight><br />
;Hoch (^)<br />
:Potenziert die erste Zahl mit der zweiten.<br />
:Potenzen werden noch '''vor''' der Punktrechnung ausgerechnet.<br />
<syntaxhighlight lang="lua">local a, b = 3, 8<br />
local c = a ^ b -- a ^ b entspricht hier der Rechnung 3 ^ 8 (3<sup>8</sup>), c erhält nun also den Wert 6561</syntaxhighlight><br />
<br><br />
<br />
===Logische===<br />
Logische Operatoren werden Benutzt, um Werte miteinander zu vergleichen und mehrere Bedingungen zu verknüpfen. Wir werden genauer auf sie zurückkommen, wenn es um Bedingungen geht. Bis dahin reicht es, wenn man sich merkt, dass ein logischer Vergleich entweder ''true'' (wenn die Aussage wahr ist) oder ''false'' (wenn die Aussage falsch ist) ergibt.<br />
<br><br><br />
;Gleich (==)<br />
:Prüft, ob zwei Werte gleich sind.<br />
<syntaxhighlight lang="lua">local a = (5 == 5) -- a ist true, da die Aussage wahr ist<br />
local b = (5 == 8) -- b ist false, da die Aussage falsch ist</syntaxhighlight><br />
;Ungleich (~=)<br />
:Prüft, ob zwei Werte ungleich sind.<br />
<syntaxhighlight lang="lua">local a = (5 ~= 5) -- a ist false, da die Aussage falsch ist<br />
local b = (5 ~= 8) -- b ist true, da die Aussage wahr ist</syntaxhighlight><br />
;Größer als (>)<br />
:Prüft, ob der erste Wert größer als der zweite ist.<br />
<syntaxhighlight lang="lua">local a = (5 > 5) -- a ist false, da die Aussage falsch ist<br />
local b = (5 > 8) -- b ist false, da die Aussage falsch ist<br />
local c = (8 > 5) -- c ist true, da die Aussage wahr ist</syntaxhighlight><br />
;Größer als oder gleich (>=)<br />
:Prüft, ob der erste Wert größer als der zweite ist oder dem zweiten gleicht.<br />
<syntaxhighlight lang="lua">local a = (5 >= 5) -- a ist true, da die Aussage wahr ist<br />
local b = (5 >= 8) -- b ist false, da die Aussage falsch ist<br />
local c = (8 >= 5) -- c ist true, da die Aussage wahr ist</syntaxhighlight><br />
;Kleiner als (<)<br />
:Prüft, ob der erste Wert kleiner als der zweite ist.<br />
<syntaxhighlight lang="lua">local a = (5 < 5) -- a ist false, da die Aussage falsch ist<br />
local b = (5 < 8) -- b ist true, da die Aussage wahr ist<br />
local c = (8 < 5) -- c ist false, da die Aussage falsch ist</syntaxhighlight><br />
;Kleiner als oder gleich (<=)<br />
:Prüft, ob der erste Wert kleiner als der zweite ist oder dem zweiten gleicht.<br />
<syntaxhighlight lang="lua">local a = (5 <= 5) -- a ist true, da die Aussage wahr ist<br />
local b = (5 <= 8) -- b ist true, da die Aussage wahr ist<br />
local c = (8 <= 5) -- c ist false, da die Aussage falsch ist</syntaxhighlight><br />
<br><br />
;Und (and)<br />
:Verknüpft zwei Bedingungen miteinander.<br />
<syntaxhighlight lang="lua">local a = (true and false) -- a ist false, da nicht beide Aussagen wahr sind<br />
local b = (5 < 8) and (7 == 7) -- b ist true, da beide Aussagen wahr sind<br />
local c = (8 > 5) and (1 ~= 2) and (0 <= -7) -- c ist false, da die dritte Aussage falsch ist</syntaxhighlight><br />
;Oder (or)<br />
:Verknüpft zwei Bedingungen miteinander.<br />
<syntaxhighlight lang="lua">local a = (true or false) -- a ist true, da die erste Aussage wahr ist<br />
local b = (5 < 8) or (7 == 7) -- b ist true, da mindestens eine der Aussagen wahr ist<br />
local c = (8 > 5) or (1 ~= 2) or (0 <= -7) -- c ist true, da mindestens eine der Aussagen wahr ist</syntaxhighlight><br />
;Nicht (not)<br />
:Kehrt einen Booleanwert um.<br />
<syntaxhighlight lang="lua">local a = not true -- a ist false<br />
local b = not false -- b ist true<br />
local c = not (0 == 8) -- c ist true, da die Aussage falsch ist</syntaxhighlight><br />
<br><br />
<br />
===Sonstige===<br />
Lua hat noch zwei weitere Operatoren, die sich jedoch nicht in die oberen Gruppen eingliedern lassen.<br />
<br><br />
;Länge (#)<br />
:Steht für die Länge eines Strings oder einer Table.<br />
<syntaxhighlight lang="lua">local sprache = "deutsch"<br />
local laenge = #sprache -- laenge wird hier auf 7 gesetzt, da das Wort "deutsch" 7 Buchstaben hat</syntaxhighlight><br />
;Verknüpfung (..)<br />
:Verknüpft zwei Strings miteinander.<br />
<syntaxhighlight lang="lua">local geschlecht, alter = "männlich", "18"<br />
local satz = "Ich bin "..geschlecht.." und "..alter.." Jahre alt." -- weist satz den Wert "Ich bin männlich und 18 Jahre alt." zu</syntaxhighlight><br />
<br><br><br />
Natürlich können auch alle anderen Variablentypen mit- und untereinander verglichen werden.<br><br />
Der Längenoperator (#) sowie der Verknüpfungsoperator (..) sind nur für Strings gedacht, wobei der erste später noch bei Tables eine Rolle spielen wird und der zweite es nicht so genau nimmt mit den Variablentypen. Bei Booleans und ''nil'' jedoch führt er in jedem Fall zu einem Fehler. Wir kommen später noch darauf zu sprechen, wie man soetwas umgeht.<br><br />
Für Integer und Floats sind alle Vergleichsoperatoren und die arithmetischen verfügbar. Strings unterstützen nur die Vergleichsoperatoren, wobei man mit den größer/kleiner Operatoren zwei Strings nach dem Alphabet ordnen kann.<br />
<syntaxhighlight lang="lua">"a" < "b" -- ergibt true, da a vor b im Alphabet kommt</syntaxhighlight><br />
Strings, Booleans und ''nil'' kann man nur untereinander vergleichen, nicht miteinander. Miteinander führt in jedem Fall zu ''false''.<br />
<br />
<br />
==Bedingungen==<br />
===Einführung===<br />
Bedingungen sind dazu da, um bestimmte Anweisungen nur auszuführen, wenn ein bestimmter Sachverhalt gegeben ist.<br />
Ein Beispiel wäre, wenn ein Spieler einem anderen Spieler eine private Nachricht senden möchte. Dann kann er das natürlich nur tun, wenn der adressierte Spieler auch online ist.<br />
Also soll die Nachricht in einem solchen Fall gesendet werden, andernfalls dem Sender jedoch eine Fehlermeldung ausgegeben werden.<br />
<br />
===Syntax===<br />
Die Syntax einer Bedingung, die man übrigens auch „if-Statement“ (if = engl. für wenn) oder im Englischen „condition“ nennt, ist recht simpel.<br />
<syntaxhighlight lang="lua">if <bedingung> then<br />
-- Anweisung(en), die ausgeführt werden soll(en), wenn die Bedingung wahr (=true) ist<br />
end</syntaxhighlight><br />
Für <bedingung> darf hier jeder Audruck eingesetzt werden, der letztendlich irgendeinen Wert ergibt.<br />
Sollte <bedingung> ''nil'' oder ''false'' sein, so wird die Anweisung zwischen then und end nicht ausgeführt, andernfalls wird sie ausgeführt.<br />
<br />
===Else-Statement===<br />
Auf jedes if-Statement darf ein else-Statement (else = engl. für sonst) folgen. Dieses benötigt kein then und auch keine Bedingung, sondern wird ausgeführt, wenn die Bedingung des if-Statements ''nil'' oder ''false'' ist. Das else-Statement ist optional!<br />
<syntaxhighlight lang="lua">if <bedingung> then<br />
-- Anweisung(en), die ausgeführt werden soll(en), wenn die Bedingung erfüllt wird<br />
else<br />
-- Anweisung(en), die ausgeführt werden soll(en), wenn die Bedingung nicht erfüllt wird<br />
end</syntaxhighlight><br />
<br />
===Elseif-Statement===<br />
Das elseif-Statement ist ein spezielles Statement, was es erlaubt, einer unübersichtlichen Verschachtelung zu entgehen, indem es die Möglichkeit bietet, einem else-Statement auch eine Bedingung zu geben. Ein if-Statement darf beliebig viele elseif-Statements enthalten. Diese müssen jedoch zwischen dem if- und dem else-Statement (falls vorhanden) stehen. Für die Bedingung gilt hier das selbe, wie für das if-Statement. Wichtig ist, dass demnach auch hier ein then erforderlich ist. Genauso wie das else-Statement ist jedoch auch das elseif-Statement optional!<br />
<syntaxhighlight lang="lua">if <bedingung1> then<br />
-- Anweisung(en), die ausgeführt werden soll(en), wenn die Bedingung 1 erfüllt wird<br />
elseif <bedingung2> then<br />
-- Anweisung(en), die ausgeführt werden soll(en), wenn die Bedingung 2 erfüllt wird<br />
else<br />
-- Anweisung(en), die ausgeführt werden soll(en), wenn weder Bedingung 1 noch Bedingung 2 erfüllt werden<br />
end</syntaxhighlight><br />
<br />
===Bedingungen formulieren===<br />
Bei der Bedingung eines if-Statements muss nicht zwangsläufig ein Boolean herauskommen. Wie bereits erwähnt, ist die Bedingung immer dann wahr, wenn sie weder ''nil'' noch ''false'' ist.<br />
D.h., dass auch Werte wie 0, "Hallo" und 3.14159 als „wahr“ gelten. Natürlich ist das auch bei ''true'' der Fall.<br />
<br />
Um komplexere Bedingungen zu formulieren, werden auf jeden Fall die bereits aufgelisteten logischen Operatoren benötigt.<br />
Mit diesen kann man für jeden nur erdenklichen Fall eine Bedingung formulieren.<br />
<br />
Wenn logische (Vergleichs-)Operatoren (==, ~=, <, >, <=, >=) angewandt werden, kommt dabei immer ein Boolean raus, wie man auch schon an den gegebenen Beispielen erkennen kann.<br />
Verknüfungen (and, or) sind dazu gedacht, um z.B. zu überprüfen, ob mehrere oder wenigstens eine Bedingung von vielen erfüllt werden oder nicht. Der not-Operator ermöglicht es, zu überprüfen, ob eine Bedingung nicht erfüllt wird.<br />
<br />
Zu dem and- und dem or-Operator möchte ich an dieser Stelle noch etwas ergänzen. Der and-Operator wird zunächst einmal dazu verwendet, um herauszufinden, ob zwei Bedingungen gleichzeitig erfüllt sind. Der or-Operator wird dazu benutzt, um herauszufinden, ob eine von zweien oder beide Bedingungen erfüllt sind.<br />
<br />
Weder der and- noch der or-Operator geben aber zwangsläufig einen Boolean zurück.<br />
<syntaxhighlight lang="lua">local foo = wert1 and wert2</syntaxhighlight><br />
Sollte wert1 ''nil'' oder ''false'' sein, so entspricht dieser Ausdruck dem folgenden:<br />
<syntaxhighlight lang="lua">local foo = wert1</syntaxhighlight><br />
Ist wert1 weder ''nil'' noch ''false'', so entspricht der Ausdruck dem hier:<br />
<syntaxhighlight lang="lua">local foo = wert2</syntaxhighlight><br />
<br />
<br />
Bei or ist es ähnlich, nur umgekehrt.<br />
<syntaxhighlight lang="lua">local foo = wert1 or wert2</syntaxhighlight><br />
Sollte wert1 ''nil'' oder ''false'' sein, so entspricht dieser Ausdruck dem folgenden:<br />
<syntaxhighlight lang="lua">local foo = wert2</syntaxhighlight><br />
Ist wert1 weder ''nil'' noch ''false'', so entspricht der Ausdruck dem hier:<br />
<syntaxhighlight lang="lua">local foo = wert1</syntaxhighlight><br />
<br />
===Beispiele===<br />
====50-50-Chance====<br />
Dieses Beispiel simuliert einen Münzwurf. math.random() und print() sind standard Lua-Funktionen. Zum Thema Funktionen komme ich später. Für dieses Beispiel reicht es, wenn ihr wisst, dass math.random() eine Zufallszahl (float) zwischen 0 und 1 zurückgibt und print("text") den in den Klammern eingeschlossenen String in die Konsole ausgibt.<br />
<syntaxhighlight lang="lua">local zufall = math.random()<br />
if (zufall < 0.5) then<br />
print("Kopf")<br />
else<br />
print("Zahl")<br />
end</syntaxhighlight><br />
====Der Nutzen von elseif====<br />
Im Folgenden wollen wir herausfinden, ob eine Zahl positiv, negativ oder 0 ist. Dazu möchte ich zuerst ein Beispiel ohne und danach eines mit elseif zeigen, um meine Aussage, dass elseif Verschachtelungen spart, zu verifizieren.<br />
<syntaxhighlight lang="lua">local zahl = 14<br />
<br />
--ohne elseif<br />
if (zahl < 0) then<br />
print("Die Zahl ist negativ.")<br />
else<br />
if (zahl == 0) then<br />
print("Die Zahl entspricht 0.")<br />
else<br />
print("Die Zahl ist positiv.")<br />
end<br />
end<br />
<br />
--mit elseif<br />
if (zahl < 0) then<br />
print("Die Zahl ist negativ.")<br />
elseif (zahl == 0) then<br />
print("Die Zahl entspricht 0.")<br />
else<br />
print("Die Zahl ist positiv.")<br />
end</syntaxhighlight><br />
Je komplexer das ganze if-Statement, desto nützlicher wird elseif sein.<br />
====Eingebettetes Pseudo-if-Statement====<br />
In vielen Script- und Programmiersprachen gibt es ein gekürztes if-Statement. In Javascript z.B. geht das wie folgt:<br />
<syntaxhighlight lang="lua">var nachricht = "Du benutzt zurzeit " + (ie ? "den Internet Explorer" : "einen guten Browser") + ".";</syntaxhighlight><br />
Wir gehen dabei davon aus, dass in der Variable ie ein Boolean gespeichert ist, der ''true'' ist, wenn der Benutzer den Internet Explorer benutzt, ansonsten ''false''.<br />
Diese Art von eingebetteten if-Statements gibt es noch in vielen anderen Sprachen, unter anderen in PHP, Java und C(++). In meinem Beispiel kann man sich das ? als then und den : als else vorstellen. Dann sollte es eigentlich nicht allzu schwer sein, diese Art von if-Statement zu verstehen.<br />
<br />
So direkt gibt es das bei Lua nicht, aber mit and und or kann man sich ein Konstrukt bauen, welches auf die gleiche Weise funktioniert. Dazu werde ich einfach mal das obere Beispiel in Lua umwandeln, auch, wenn Lua eigentlich nicht viel mit Browsern am Hut hat.<br />
<syntaxhighlight lang="lua">local nachricht = "Du benutzt zurzeit "..(ie and "den Internet Explorer" or "einen guten Browser").."."</syntaxhighlight><br />
Zuerst ist das and an der Reihe. Es schmeißt den String "den Internet Explorer" raus, wenn ie ''false'' (oder ''nil'') ist und zurück bleibt auf jeden Fall ''false'' (oder ''nil''). Das wird dann vom or rausgeschmissen und zurück bleibt "einen guten Browser".<br />
Wenn ie weder ''false'' noch ''nil'' ist, schmeißt and die Vairable ie raus und zurück bleibt "den Internet Explorer". Da dieser String weder ''false'' noch ''nil'' ist, wird er vom or beibelassen und "einen guten Browser" rausgeschmissen.<br />
Entschuldigt meine Ausdrucksweise mit dem rausschmeißen, aber das schien mir die beste Möglichkeit, diese Methode verständlich zu erklären.<br />
<br />
<br />
==Tabellen==<br />
===Einführung===<br />
Tabellen sind spezielle Variablen, die mehrere Werte enthalten können.<br />
Damit wir Tabellen verwenden können, führe ich nun erst einmal den Variablentyp „table“ ein. Mit einer table-Variable kann man ersteinmal kaum Operationen durchführen. Dazu benötigt man Funktionen, zu denen wir aber erst später kommen.<br />
<br />
===Definition===<br />
Um eine Variable als (leere) table zu definieren, benutzt man diesen Ausdruck:<br />
<syntaxhighlight lang="lua">local tabelle = {}</syntaxhighlight><br />
<br />
Ohne Funktionen macht das noch recht wenig Sinn. Um einer Tabelle direkt mehrere Werte zuzuweisen, schreibt man diese einfach durch Kommata getrennt zwischen die geschweiften Klammern.<br />
<syntaxhighlight lang="lua">local tabelle1 = { "Apfel", 14, 3.14159, true }</syntaxhighlight><br />
Eine table kann alle möglichen Typen von Variablen enthalten. So zum Beispiel auch andere Tabellen.<br />
<syntaxhighlight lang="lua">local tabelle2 = { 1, { 1.25, 1.5, 1.75 }, 2, { 2.25, 2.5, 2.75 } }</syntaxhighlight><br />
<br />
Um nun auf die Elemente einer table zugreifen zu können, benutzt man Indizes (Indizes ist der Plural von Index). Jedes Element in einer table hat einen Index. Wenn man die Tabellen so definiert, wie ich es gemacht habe, so wird jedem Element ein integer als Index zugewiesen, wobei das erste Element die 1 als Index bekommt, das zweite die 2 usw.<br />
Der ungefähre Wert von Pi (3.14159) in der oberen Tabelle hat den Index 3. Um anhand eines Indizes ein Element einer Tabelle abzufragen, schreibt man den Index einfach in eckigen Klammern hinter den Tabellennamen.<br />
tabelle1[3] entspricht also dem Wert 3.14159.<br />
Wenn das Element der Tabelle selbst noch eine Tabelle ist, wie z.B. das Element mit dem index 2 aus tabelle2, dann setzt man die Indizes einfach hintereinander. Der Wert 2.25 ist demnach in tabelle2[4][1] gespeichert.<br />
<br />
===Ganzzahlige Indizes===<br />
Um gezielt bestimmten Indizes einen Wert zuzuweisen, kann man folgende Schreibweise verwenden:<br />
<syntaxhighlight lang="lua">local auskunft = { [11] = "elf", [88] = "achtundachtzig", [0] = "null" }</syntaxhighlight><br />
Dabei spielt es keine Rolle, in welcher Reihenfolge die Indizes einen Wert zugewiesen bekommen und es spiel auch keine Rolle, ob die Indizes positiv oder negativ sind.<br />
Es muss jedoch beachtet werden, dass etwas wie { [1] = "eins", "zwei" } dem Index 1 den Wert "zwei" zuweisen würde, da Lua immer bei 1 anfängt zu zählen, egal, ob der Scripter den Index 1 bereits definiert hat.<br />
<br />
===Zeichenketten als Indizes===<br />
Ein Index kann auch ein String sein. Dazu verwendet man folgende Schreibweise:<br />
<syntaxhighlight lang="lua">lua konstanten = { ["pi"] = 3.14159, ["e"] = 2.71828 }</syntaxhighlight><br />
Ansprechen kann man diese Werte genauso wie bei integer-Indizes. konstanten["pi"] ist also 3.14159.<br />
<br />
Eine Besonderheit bei Zeichenketten als Index ist, dass es eine vereinfachte Schreibweise gibt. Sowohl bei der Definition als auch bei der Abfrage der Elemente. Das obige Beispiel kann auch so realisiert werden:<br />
<syntaxhighlight lang="lua">lua konstanten = { pi = 3.14159, e = 2.71828 }</syntaxhighlight><br />
Zum Abfragen der Elemente kann man die Schreibweise konstanten.pi bzw. konstanten.e verwenden.<br />
Man sollte aber bedenken, dass Schlüsselwörter wie z.B. if oder local als Indizes besser mit ["if"] und ["local"] definiert werden.<br />
<br />
===Beliebige Indizes===<br />
Ein Index muss nicht unbedingt ein integer oder ein string sein. Genauer gesagt kann ein Index ein beliebiger Wert (außer ''nil'') sein.<br />
Somit wäre z.B. auch das möglich:<br />
<syntaxhighlight lang="lua">local tabelle = { [true] = "wahr", [3.14159] = "pi", [0] = 1, 123 }</syntaxhighlight><br />
Die Zahl 123 hätte hier übrigens den Index 1.<br />
<br />
===Einzelzuweisungen===<br />
Man muss nicht immer alle Werte einer table auf einmal definieren. Jedes Tabellenelement lässt sich wie eine normale Variable behandeln.<br />
<syntaxhighlight lang="lua">local tabelle = {}<br />
tabelle[true] = "wahr"<br />
tabelle.pi = 3.14159<br />
tabelle[2] = { 1, 2, 3 }<br />
tabelle[2][0] = 0</syntaxhighlight><br />
Jedes undefinierte Element hat - genauso wie jede undefinierte Variable - den Wert ''nil''.<br />
<br />
===Verlinkungen===<br />
<syntaxhighlight lang="lua">local tabelle1 = { 1, 2, 3 }<br />
local tabelle2 = tabelle1<br />
tabelle1[1] = 4</syntaxhighlight><br />
In der zweiten Zeile dieses Beispiels wird die tabelle1 nicht in die Variable tabelle2 kopiert, sondern tabelle2 verweist ab sofort auf tabelle1. Am Ende des Codes wäre also tabelle2[1] auch 4, obwohl es nicht explizit zugewiesen wurde.<br />
<br />
Um eine Tabelle zu kopieren, könnt ihr euch die Useful Function [[table.copy]] aus der Wiki kopieren und diese dazu verwenden.<br />
<br />
<br />
==Schleifen==<br />
===Einführung===<br />
Schleifen verwendet man immer dann, wenn man eine oder mehrere Anweisungen mehr als einmal direkt hintereinander ausführen möchte oder wenn man eine oder mehrere Anweisungen für jedes Element einer table ausführen möchte.<br />
Es gibt drei verschiedene Arten von Schleifen. Diese werde ich jetzt hier einzeln vorstellen.<br />
<br />
===While-Schleife===<br />
Die while-Schleife wiederholt eine oder mehrere Anweisungen solange, bis eine bestimmte Bedingung nicht mehr erfüllt wird.<br />
Die Syntax ist die folgende:<br />
<syntaxhighlight lang="lua">while [bedingung] do<br />
-- Anweisung(en)<br />
end</syntaxhighlight><br />
<br />
Beispiel:<br />
<syntaxhighlight lang="lua">local zahl = 10<br />
while (zahl >= 0) do<br />
print(zahl)<br />
zahl = zahl - 1<br />
end</syntaxhighlight><br />
Das Beispiel gibt nacheinander alle Zahlen von 10 bis 0 aus. Nach der Schleife hat zahl dann den Wert -1.<br />
<br />
===Repeat-Until-Schleife===<br />
Die repeat-until-Schleife wiederholt eine oder mehrere Anweisungen solange, bis eine bestimmte Bedingung erfüllt ist. Sie führt diese Anweisung(en) aber in jedem Fall einmal aus.<br />
Die Syntax lautet:<br />
<syntaxhighlight lang="lua">repeat<br />
-- Anweisung(en)<br />
until [bedingung]</syntaxhighlight><br />
<br />
Das obere Beispiel lässt sich hiermit wie folgt realisieren:<br />
<syntaxhighlight lang="lua">local zahl = 10<br />
repeat<br />
print(zahl)<br />
zahl = zahl - 1<br />
until (zahl < 0)</syntaxhighlight><br />
<br />
<br />
===For-Schleife===<br />
Es gibt zwei verschiedene for-Schleifen. Einmal die einfache numerische for-Schleife und zum Anderen die generische for-Schleife, mit der man u.a. alle Elemente einer table durchlaufen kann. Mit der generischen for-Schleife kann man noch ganz andere wesentlich komplexere Operationen durchführen, die ich hier aber nicht erklären werde, da sie auch - zumindest beim Scripten für MTA - nicht wirklich benötigt werden.<br />
====Numerisch====<br />
Syntax:<br />
<syntaxhighlight lang="lua">for [laufvariable], [maximum], [schrittweite] do<br />
-- Anweisung(en)<br />
end</syntaxhighlight><br />
Die Laufvariable wird nach jedem Durchlauf der Schleife um die Schrittweite erhöht, bis sie größer oder gleich dem Maximum ist. Alle drei Werte müssen numerisch sein, d.h. ein integer oder ein float. Die Schrittweite kann auch weggelassen werden. Sie ist dann automatisch 1.<br />
Unser Beispiel von oben sähe mit einer for-Schleife so aus:<br />
<syntaxhighlight lang="lua">for i=10, 0, -1 do<br />
print(i)<br />
end</syntaxhighlight><br />
Die Variable i ist nur innerhalb der Schleife verfügbar. Damit sie auch nach der Schleife noch verfügbar ist, muss man sie schon vor der Schleife deklarieren.<br />
====Generisch====<br />
Die generische for-Schleife wird hauptsächlich dazu verwendet, um tables zu durchlaufen. Ich werde sie daher auch nur in diesem Zusammenhang erläutern.<br />
Die Syntax für den Fall, dass man eine table durchlaufen will, ist:<br />
<syntaxhighlight lang="lua">for [index], [wert] in pairs([tabelle]) do<br />
-- Anweisung(en)<br />
end</syntaxhighlight><br />
Diese Schleife geht durch alle Elemente der Tabelle und führt die Anweisungen somit für alle Elemente der Tabelle aus, wobei Index jedes Mal dem aktuellen Index des Tabellenelements und Wert jedes Mal dem aktuellen Wert des Tabellenelements entspricht.<br />
Anstelle von pairs() kann man auch ipairs() nehmen, wenn man nur alle ganzzahligen Indizes durchlaufen möchte.<br />
Hier mal ein Beispiel:<br />
<syntaxhighlight lang="lua">local tabelle = { eins = 1, "hallo", pi = 3.14159 }<br />
<br />
-- mit pairs<br />
for index, wert in pairs(tabelle) do<br />
print(tostring(index).."="..tostring(wert)..", ")<br />
end<br />
-- Ausgabe: "eins=1, 1=hallo, pi=3.14159, "<br />
<br />
-- mit ipairs<br />
for index, wert in ipairs(tabelle) do<br />
print(tostring(index).."="..tostring(wert)..", ")<br />
end<br />
-- Ausgabe: "1=hallo, "</syntaxhighlight><br />
tostring() ist übrigens eine Funktion, die eine beliebige Variable in einen string umwandelt. Wenn man Variablen mit einem string verknüpfen will und sich nicht sicher ist, ob diese Variablen string sind oder nicht, sollte man auf jeden Fall diese Funktion verwenden, da ansonsten Fehler auftreten können. (Lua gibt einen Error aus, wenn man z.B. soetwas versucht: "Hallo "..nil..".")<br />
<br />
===Schleifenabbruch===<br />
Mit dem Schlüsselwort break kann man eine Schleife sofort abbrechen.<br />
Hier ein kurzes Beispiel dazu:<br />
<syntaxhighlight lang="lua">local zahl = 10<br />
while (true) do<br />
print(zahl)<br />
zahl = zahl - 1<br />
if (zahl < 0) then<br />
break<br />
end<br />
end</syntaxhighlight><br />
Diese Schleife würde auch alle Zahlen von 10 bis 0 nacheinander ausgeben, nur dass der Abbruch manuell erfolgt, wenn zahl negativ wird. Ohne diese Bedingung würde die Schleife endlos laufen.<br />
<br />
<br />
==Funktionen==<br />
===Einführung===<br />
Funktionen sind im Grunde genommen Anweisungsblöcke, die - meist in Abhängigkeit von übergebenen Werten - mehrmals an unterschiedlichen Orten im Script bzw. zu unterschiedlichen Zeiten ausgeführt werden sollen.<br />
Da eine Funktion - sofern sie mehr als einmal ausgeführt werden soll bzw. mehr als einmal benötigt wird - auch in einer Variable gespeichert werden kann, kann man den Variablentyp function einführen, der in Lua auch tatsächlich existiert.<br />
Funktionen können Werte übergeben bekommen und auch Werte zurückgeben.<br />
<br />
===Definition===<br />
Die allgemeine Syntax für das Definieren einer Funktion ist die folgende:<br />
<syntaxhighlight lang="lua">function [funktionsname]([parameterliste])<br />
-- Anweisung(en)<br />
end</syntaxhighlight><br />
<br />
Ein Beispiel für eine Funktion, die das Quadrat einer Zahl zurückgibt, wäre:<br />
<syntaxhighlight lang="lua">function quadrat(zahl)<br />
return zahl * zahl<br />
end</syntaxhighlight><br />
<br />
Alternativ kann eine Funktion übrigens auch so einer Variable zugewiesen werden:<br />
<syntaxhighlight lang="lua">quadrat = function (zahl) return zahl * zahl end</syntaxhighlight><br />
<br />
===Rückgabewerte===<br />
return wird verwendet, um die Funktion einen Wert zurückgeben zu lassen. Nach einem return-Befehl bricht die Funktion alle Tätigkeiten ab und ist beendet.<br />
Um einen Rückgabewert verwenden zu können, müssen wir aber ersteinmal wissen, wie man eine Funktion dazu bringt, die Anweisungen, die sie enthält, auszuführen.<br />
Das geht allgemein mit funktionsname(parameterliste).<br />
Als Beispiel für unsere quadrat-Funktion:<br />
<syntaxhighlight lang="lua">local vier = quadrat(2)</syntaxhighlight><br />
<br />
Wenn wir quadrat(2) ausführen, dann wird der obrige Code ausgeführt, wobei die Variable zahl den Wert 2 zugewiesen bekommt. zahl ist dabei jedoch nur innerhalb der Funktion definiert.<br />
Die Variable vier bekommt nun den Wert 2 * 2, also 4 zugewiesen.<br />
<br />
<syntaxhighlight lang="lua">local vier = quadrat</syntaxhighlight><br />
würde die Funktion quadrat in die Variable vier kopieren. Man könnte nun also auch vier(2) aufrufen, um 4 zu bekommen.<br />
<br />
Eine Funktion kann auch mehrere Funktionswerte zurückgeben. Das ist vor allem dann sinnvoll, wenn es sich um Positionen handelt, was bei MTA ja nicht selten vorkommt.<br />
Beispiel:<br />
<syntaxhighlight lang="lua">function berechnungen(zahl1, zahl2)<br />
return zahl1 + zahl2, zahl1 - zahl2, zahl1 * zahl2, zahl1 / zahl2<br />
end<br />
<br />
local summe, differenz, produkt, division = berechnungen(5, 10)</syntaxhighlight><br />
Damit wird summe = 15, differenz = 5, produkt = 50 und division = 2.<br />
<br />
===Lua Standardfunktionen===<br />
Funktionen wie tostring, print und math.random sind Standardfunktionen von Lua. Eine komplette Liste aller Lua Standardfunktionen bekommt ihr auf der [http://www.lua.org/manual/5.1/#index offiziellen Lua Webseite] (Englisch).<br />
<br />
Die Standard-string-Funktionen erlauben eine besondere Syntax, die ich hier kurz erläutern möchte, da sie von vielen erfahrenen Scriptern genutzt wird und es hilfreich ist, wenn man etwas damit anfangen kann.<br />
<syntaxhighlight lang="lua">local name = "Firzen Polas"<br />
local laenge = string.len(name)</syntaxhighlight><br />
Dieser Code weist der Variable laenge die Länge des strings "Firzen Polas", also 12, zu.<br />
Alternativ kann man auch den folgenden Code verwenden:<br />
<syntaxhighlight lang="lua">local name = "Firzen Polas"<br />
local laenge = name:len()</syntaxhighlight><br />
Vorraussetzung ist, dass die Variable vor dem Doppelpunkt ein string ist. Bei den math- und table-Funktionen funktioniert dies nicht.<br />
<br />
===Rekursive Funktionen===<br />
Rekursive Funktionen sind eine effektive Alternative zu Schleifen - zumindest in manchen seltenen Fällen. Das berühmteste Beispiel ist das Berechnen einer Fakultät.<br />
Zur Information: n! (sprich: n Fakultät) bezeichnet das Produkt aller Ganzzahlen von n bis 1, also quasi 1*2*3*4*...*n.<br />
Beispiel: 3! = 1 * 2 * 3 = 6<br />
<syntaxhighlight lang="lua">function fakultaet(zahl)<br />
if (zahl > 0) then<br />
return zahl * fakultaet(zahl - 1)<br />
else<br />
return 1<br />
end<br />
end</syntaxhighlight><br />
Mit Schleife sähe das so aus:<br />
<syntaxhighlight lang="lua">function fakultaet(zahl)<br />
if (zahl == 0) then<br />
return 1<br />
end<br />
for i=zahl-1, 1, -1 do<br />
zahl = zahl * i<br />
end<br />
return zahl<br />
end</syntaxhighlight><br />
<br />
===Variable Parameterzahl===<br />
Manchmal benötigt eine Funktion nicht zwingend eine bestimmte Anzahl von Parametern oder soll eine variable Anzahl an Parametern akzeptieren.<br />
Dies lässt sich realisieren mit drei Punkten am Ende der Parameterliste.<br />
<syntaxhighlight lang="lua">function aufsummieren(...)<br />
local parameter = {...}<br />
local summe = 0<br />
for _, zahl in pairs(parameter)<br />
summe = summe + tonumber(zahl)<br />
end<br />
return summe<br />
end</syntaxhighlight><br />
... entspricht dabei innerhalb der Funktion der Parameterliste als normale Liste.<br />
D.h., wenn man aufsummieren(1, 2, 3, 4) aufruft, dann wird parameter = {1, 2, 3, 4}.<br />
<br />
<br />
==Fragen, Anregungen, Kritik==<br />
Sollten noch irgendwelche Fragen offen sein, so könnt ihr jederzeit in unserem [irc://irc.gtanet.com/#mta.german IRC Channel] oder in unserem [http://mtasa.ath.cx/wbblite/ Forum] vorbeischauen und eure Fragen dort loswerden.<br />
Außerdem haben wir in unserem IRC Channel einen Lua Bot, an dem ihr Funktionen, die auf den standard Lua Funktionen basieren, ausprobieren könnt.<br />
<br />
Anregungen und Kritik nehme ich dort auch entgegen. Alternativ könnt ihr diese hier in die Diskussion schreiben.<br />
Falls ihr Fehler findet, behebt diese bitte oder gebt mir bescheid.<br />
<br />
Ich hoffe, das Tutorial konnte euch weiterhelfen. Demnächst wird es noch ein weiteres Tutorial geben, was auf MTA spezialisiert ist und grundlegende Techniken und Möglichkeiten erklärt.</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=GetBoundKeys&diff=19741GetBoundKeys2009-05-26T01:10:38Z<p>Flobu: </p>
<hr />
<div>__NOTOC__<br />
{{Client function}}<br />
Returns a list of key names that are bound to the specified game [[Control names|control]] or console command.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
table getBoundKeys ( string command/control )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''command/control:''' the name of a game control or a console command. See the [[control names]] page for valid controls.<br />
<br />
===Returns===<br />
If one or more keys are bound to the specified control or console command, a table is returned containing the names and them states of all the bound keys. If no keys are bound or an invalid name was passed, returns ''false''.<br />
<br />
==Example==<br />
This code adds a command handler with which you can check out the keybinds for any game control. As an example, typing "/keys forwards" would list all the keys which you can press to make the player walk forward.<br />
<syntaxhighlight lang="lua"><br />
function keysCommand ( command, controlName )<br />
if not controlName then -- make sure they specified a control name<br />
outputChatBox ( "No control name specified", 255, 0, 0 )<br />
return<br />
end<br />
local keys = getBoundKeys ( controlName ) -- get the keys bound to this control<br />
if not keys then -- make sure the control name is valid and any keys are bound to it<br />
outputChatBox ( "No keys bound to " .. controlName, 255, 0, 0 )<br />
return<br />
end<br />
outputChatBox ( "Keys bound to " .. controlName .. ":", 0, 255, 0 )<br />
for keyName, state in pairs(keys) do<br />
outputChatBox ( keyName, 0, 255, 0 )<br />
end<br />
end<br />
<br />
addCommandHandler ( "keys", keysCommand )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Client input functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=GetBoundKeys&diff=19740GetBoundKeys2009-05-26T01:09:14Z<p>Flobu: </p>
<hr />
<div>__NOTOC__<br />
{{Client function}}<br />
Returns a list of key names that are bound to the specified game [[Control names|control]] or console command.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
table getBoundKeys ( string command/control )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''command/control:''' the name of a game control or a console command. See the [[control names]] page for valid controls.<br />
<br />
===Returns===<br />
If one or more keys are bound to the specified control or console command, a table is returned containing the names of all the bound keys and them states. If no keys are bound or an invalid name was passed, returns ''false''.<br />
<br />
==Example==<br />
This code adds a command handler with which you can check out the keybinds for any game control. As an example, typing "/keys forwards" would list all the keys which you can press to make the player walk forward.<br />
<syntaxhighlight lang="lua"><br />
function keysCommand ( command, controlName )<br />
if not controlName then -- make sure they specified a control name<br />
outputChatBox ( "No control name specified", 255, 0, 0 )<br />
return<br />
end<br />
local keys = getBoundKeys ( controlName ) -- get the keys bound to this control<br />
if not keys then -- make sure the control name is valid and any keys are bound to it<br />
outputChatBox ( "No keys bound to " .. controlName, 255, 0, 0 )<br />
return<br />
end<br />
outputChatBox ( "Keys bound to " .. controlName .. ":", 0, 255, 0 )<br />
for keyName, state in pairs(keys) do<br />
outputChatBox ( keyName, 0, 255, 0 )<br />
end<br />
end<br />
<br />
addCommandHandler ( "keys", keysCommand )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Client input functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=OnVehicleStartExit&diff=19735OnVehicleStartExit2009-05-24T20:45:53Z<p>Flobu: /* Example */</p>
<hr />
<div>__NOTOC__ <br />
{{Server event}}<br />
This event is triggered when a player starts to exit a vehicle. This event can be used to cancel exit, if necessary.<br />
<br />
==Parameters== <br />
<syntaxhighlight lang="lua"><br />
player exitingPlayer, int seat, player jacked<br />
</syntaxhighlight> <br />
<br />
*'''exitingPlayer''': A player element representing the player who is starting to exit a vehicle<br />
*'''seat''': An integer representing the seat in which the player is exiting from<br />
*'''jacked''': A player element representing who is jacking<br />
<br />
==Source==<br />
The [[event system#Event source|source]] of this event is the [[vehicle]] in which a player began to exit.<br />
<br />
===Canceling===<br />
If this event is [[Event system #Canceling|canceled]], the player will not exit the vehicle.<br />
<br />
==Example== <br />
This example locks a player inside a police vehicle if he is a policeman.<br />
<syntaxhighlight lang="lua"><br />
policeVehicles { [598]=true,[596]=true,[597]=true,[599]=true }<br />
policeSkins { [280]=true,[281]=true,[282]=true,[283]=true,[284]=true,[285]=true,[286]=true }<br />
<br />
function exitVehicle ( thePlayer, seat, jacked ) --when a player enters a vehicle<br />
if ( policeVehicles[getVehicleID ( source )] ) and ( policeSkins[getPlayerSkin ( thePlayer )] ) then -- if the vehicle is one of 4 police cars, and the skin is a police skin<br />
cancelEvent()<br />
outputChatBox ( "You're the cop! Don't exit the car!", thePlayer ) --and tell the player why<br />
end<br />
end<br />
addEventHandler ( "onVehicleStartExit", getRootElement(), exitVehicle ) -- add an event handler for onVehicleStartExit<br />
</syntaxhighlight><br />
<br />
{{See also/Server event|Vehicle events}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=OnVehicleStartExit&diff=19728OnVehicleStartExit2009-05-24T00:20:06Z<p>Flobu: </p>
<hr />
<div>__NOTOC__ <br />
{{Server event}}<br />
This event is triggered when a player starts to exit a vehicle. This event can be used to cancel exit, if necessary.<br />
<br />
==Parameters== <br />
<syntaxhighlight lang="lua"><br />
player exitingPlayer, int seat, player jacked<br />
</syntaxhighlight> <br />
<br />
*'''exitingPlayer''': A player element representing the player who is starting to exit a vehicle<br />
*'''seat''': An integer representing the seat in which the player is exiting from<br />
*'''jacked''': A player element representing who is jacking<br />
<br />
==Source==<br />
The [[event system#Event source|source]] of this event is the [[vehicle]] in which a player began to exit.<br />
<br />
===Canceling===<br />
If this event is [[Event system #Canceling|canceled]], the player will not exit the vehicle.<br />
<br />
==Example== <br />
This example locks a player inside a police vehicle if he is a policeman.<br />
<syntaxhighlight lang="lua"><br />
policeVehicles { [598]=true,[596]=true,[597]=true,[599]=true }<br />
policeSkins { [280]=true,[281]=true,[282]=true,[283]=true,[284]=true,[285]=true,[286]=true }<br />
<br />
function exitVehicle ( thePlayer, seat, jacked ) --when a player enters a vehicle<br />
if ( policeVehicles[getVehicleID ( source )] ) and ( policeSkins[getPlayerSkin ( thePlayer )] ) then -- if the vehicle is one of 4 police cars, and the skin is a police skin<br />
cancelEvent()<br />
outputChatBox ( "You're the cop! Don't exit the car!", thePlayer ) --and tell the player why<br />
end<br />
end<br />
addEventHandler ( "onVehicleStartExit", getRootElement(), exitVehicle ) -- add an event handler for onVehicleStarExit<br />
</syntaxhighlight><br />
<br />
{{See also/Server event|Vehicle events}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=SetPedAimTarget&diff=19714SetPedAimTarget2009-05-22T13:22:18Z<p>Flobu: /* See Also */</p>
<hr />
<div>__NOTOC__<br />
{{Client function}}<br />
This function allows you to set a ped's aim target to a specific point.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool setPedAimTarget ( ped thePed, float x, float y, float z )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''thePed:''' The ped whose target you want to set.<br />
*'''x:''' The x coordinate of the aim target point.<br />
*'''y:''' The y coordinate of the aim target point.<br />
*'''z:''' The z coordinate of the aim target point.<br />
<br />
===Returns===<br />
Returns ''true'' if the function was successful, ''false'' otherwise.<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
function createPedAndsetHisAimTarget ()<br />
createPed (0, 0, 0, 5 ) -- create a ped, who looks like cj, in the middle of the map<br />
setPedAimTarget ( ped, 10, 10, 5 ) -- set the ped's target to a point in North-East<br />
end<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Client ped functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Template:Client_ped_functions&diff=19713Template:Client ped functions2009-05-22T13:21:32Z<p>Flobu: </p>
<hr />
<div>{{New feature|3|1.0|<br />
*[[canPedBeKnockedOffBike]]<br />
*[[createPed]]<br />
*[[doesPedHaveJetPack]]<br />
*[[getPedAnimation]]<br />
*[[getPedArmor]]<br />
*[[getPedBonePosition]]<br />
*[[getPedClothes]]<br />
*[[getPedContactElement]]<br />
*[[getPedControlState]]<br />
*[[getPedOccupiedVehicle]]<br />
*[[getPedRotation]]<br />
*[[getPedSimplestTask]]<br />
*[[getPedSkin]]<br />
*[[getPedStat]]<br />
*[[getPedTarget]]<br />
*[[getPedTargetStart]]<br />
*[[getPedTargetEnd]]<br />
*[[getPedTargetRange]]<br />
*[[getPedTargetCollision]]<br />
*[[getPedTask]]<br />
*[[getPedVoice]]<br />
*[[getPedAmmoInClip]]<br />
*[[getPedTotalAmmo]]<br />
*[[getPedWeapon]]<br />
*[[getPedWeaponSlot]]<br />
*[[isPedChoking]]<br />
*[[isPedDoingGangDriveby]]<br />
*[[isPedDoingTask]]<br />
*[[isPedDucked]]<br />
*[[isPedHeadless]]<br />
*[[isPedInVehicle]]<br />
*[[isPedInWater]]<br />
*[[isPedOnGround]]<br />
*[[isPedOnFire]]<br />
*[[setPedAimTarget]]<br />
*[[setPedAnimation]]<br />
*[[setPedCameraRotation]]<br />
*[[setPedCanBeKnockedOffBike]]<br />
*[[setPedControlState]]<br />
*[[setPedDoingGangDriveby]]<br />
*[[setPedHeadless]]<br />
*[[setPedLookAt]]<br />
*[[setPedOnFire]]<br />
*[[setPedRotation]]<br />
*[[setPedSkin]]<br />
*[[setPedVoice]]<br />
*[[setPedWeaponSlot]]<br />
}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=SetPedAimTarget&diff=19712SetPedAimTarget2009-05-22T13:13:59Z<p>Flobu: New page: __NOTOC__ {{Client function}} This function allows you to set a ped's aim target to a specific point. ==Syntax== <syntaxhighlight lang="lua"> bool setPedAimTarget ( ped thePed, float x, float y, float ...</p>
<hr />
<div>__NOTOC__<br />
{{Client function}}<br />
This function allows you to set a ped's aim target to a specific point.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool setPedAimTarget ( ped thePed, float x, float y, float z )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''thePed:''' The ped whose target you want to set.<br />
*'''x:''' The x coordinate of the aim target point.<br />
*'''y:''' The y coordinate of the aim target point.<br />
*'''z:''' The z coordinate of the aim target point.<br />
<br />
===Returns===<br />
Returns ''true'' if the function was successful, ''false'' otherwise.<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
function createPedAndsetHisAimTarget ()<br />
createPed (0, 0, 0, 5 ) -- create a ped, who looks like cj, in the middle of the map<br />
setPedAimTarget ( ped, 10, 10, 5 ) -- set the ped's target to a point in North-East<br />
end<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Ped functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=OnResourcePreStart&diff=19689OnResourcePreStart2009-05-20T20:26:34Z<p>Flobu: </p>
<hr />
<div>{{Server event}}<br />
__NOTOC__<br />
This event is triggered before a resource is loaded.<br />
<br />
'''Important:''' If you attach this event to the root element it will called when ''any'' resource starts, not just the resource your script is running inside. As such, most of the time you will want to check that the resource passed to this event matches your resource (compare with the value returned by [[getThisResource]]) before doing anything. Alternatively you can attach the event to [[getResourceRootElement]]([[getThisResource]]()).<br />
<br />
==Parameters==<br />
<syntaxhighlight lang="lua"><br />
resource startingResource<br />
</syntaxhighlight> <br />
<br />
*'''startingResource''': The resource that is starting<br />
<br />
==Source==<br />
The [[event system#Event source|source]] of this event is the root [[element]] in the resource that is starting.<br />
<br />
==Cancel effect==<br />
<br />
==Example==<br />
This code will output the name of any resource that is starting.<br />
<syntaxhighlight lang="lua"><br />
function displayStartingRes ( res )<br />
outputChatBox ( "Resource " .. getResourceName(res) .. " is starting", getRootElement(), 255, 255, 255 )<br />
end<br />
addEventHandler ( "onPreResourceStart", getRootElement(), displayStartingRes )<br />
</syntaxhighlight><br />
<br />
{{See also/Server event|Resource events}}<br />
<br />
[[Category: Incomplete]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Changes_in_1.0&diff=19669Changes in 1.02009-05-19T20:25:52Z<p>Flobu: fix some mistakes</p>
<hr />
<div>This page outlines the major and fundamental changes when upgrading from dp2.x to 1.0.<br />
<br />
==Client==<br />
===General===<br />
* The settings menu is now much more advanced and allows for more in depth changes, such as the addition of a '''Video''' tab which allows you to set the resolution<br />
<br />
===Console commands===<br />
The console commands now use CVARS. This essentially means that the standard commands that are built into MTA now exhibit a different syntax.<br />
<br />
Whereas in dp2 you may have done:<br />
chat_font 2<br />
<br />
In 1.0 you would perform a command that mimics C:<br />
chat_font = 2<br />
<br />
This applies to all inbuilt commands, except for those that may interface with a server (e.g. ''nick'' or ''me'').<br />
<br />
===Chatbox===<br />
The chatbox has had minor changes in 1.0. In particular, the text now displays an animation when a new line appears, and the ''Page Up'' and ''Page Down'' keys can be used to scroll the chat.<br />
<br />
===Host Game===<br />
This useful addition allows you to quickly start a game without having to run the MTA Server executable. It is fully functional and based upon the local.conf.<br />
<br />
===Joypad support===<br />
From 1.0, users can use their joypad/controller ingame. The keys for your joypad can be configured in the '''Binds''' tab, and advanced configuration such as analog keys can be configured in the '''Controls''' tab.<br />
<br />
===Map Editor===<br />
The Map Editor is now functional as of 1.0. This is assuming you have the map editor installed. Please see the [[Editor|Editor manual]] for details.<br />
<br />
==Server==<br />
The interface of the server is largely the same as dp2.x, there have, however been various tweaks<br />
<br />
===Server config===<br />
If upgrading from dp2, you should also add any missing variables to your config:<br />
* '''fpslimit''': This sets the FPS limit on your server.<br />
* '''donotbroadcastlan''': This sets whether the server can broadcast to Local Area Network servers<br />
<br />
===Commands===<br />
The commands of the server console are mostly the same, with the exception of:<br />
* '''refresh''' - Previously the refresh command would refresh ''all'' resources. Now it only detects new resources that are in your resources directory<br />
* '''refreshall''' - This new command mimics the previous functioning of refresh, and refreshes all resources - even those which are loaded already.<br />
* '''loadmodule''' - Modules can now be loaded using this command without them being set in the server config.<br />
<br />
==Resources==<br />
Many of the default resources have been changed or updated, and new ones have also been added.<br />
<br />
* Resource '''realdriveby''' has been added. This will facilitate the driveby mode in vehicles<br />
* Resource '''freeroam''' has been added.<br />
* Resource '''parachute''' has been added, which facilitates parachutes from single player.<br />
* Resource '''race''' has undergone many changes and is now much more stable and functional.<br />
<br />
==Scripting==<br />
Much of the scripting interface has changed in 1.0. Almost all resources will need updating in order to function, although the extent of this varies between scripts.<br />
<br />
===Camera functions===<br />
The camera functions have been completely overhauled. Scripters using the camera functions</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=ExecuteSQLQuery&diff=19482ExecuteSQLQuery2009-05-12T18:37:57Z<p>Flobu: </p>
<hr />
<div>__NOTOC__<br />
{{Server function}}<br />
<br />
This function executes an arbitrary SQL query and returns the result rows if there are any. It allows parameter binding for security (SQL injection is rendered impossible).<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua"><br />
table executeSQLQuery(string query [, var param1 [, var param2 ...]])<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''query:''' An SQL query. Positions where parameter values will be inserted are marked with a "?".<br />
<br />
===Optional Arguments===<br />
*'''paramX:''' A variable number of parameters. These must be strings or numbers - it is important to make sure they are of the correct type. Also, the number of parameters passed must be equal to the number of "?" characters in the query string.<br />
String parameters are automatically escaped by adding a backslash (\) before ' and \ characters.<br />
<br />
===Returns===<br />
Returns a table with the result of the query if it was a SELECT query, or ''false'' if otherwise. In case of a SELECT query the result table may be empty (if there are no result rows). The table is of the form:<br />
<br />
<syntaxhighlight lang="lua"><br />
{<br />
{ colname1=value1, colname2=value2, ... },<br />
{ colname1=value3, colname2=value4, ... },<br />
...<br />
}<br />
</syntaxhighlight><br />
<br />
==Example==<br />
This example defines a console command that shows the ID's and names of all registered (stored in database) players that have more than the specified amount of money.<br />
<br />
<syntaxhighlight lang="lua"><br />
function listPlayersWithMoreMoneyThan(thePlayer, command, amount)<br />
local players = executeSQLQuery("SELECT id, name FROM players WHERE money > ?", tonumber(amount))<br />
outputConsole("Players with more money than " .. amount .. ":", thePlayer)<br />
for i, playerdata in ipairs(players) do<br />
outputConsole(playerdata.id .. ": " .. playerdata.name, thePlayer)<br />
end<br />
end<br />
<br />
addCommandHandler("richplayers", listPlayersWithMoreMoneyThan)<br />
</syntaxhighlight><br />
<br />
<br />
This example shows the amount of money a certain registered player has.<br />
<br />
<syntaxhighlight lang="lua"><br />
function showPlayerMoney(thePlayer, command, playerName)<br />
local result = executeSQLQuery("SELECT money FROM players WHERE name=?", playerName)<br />
if(#result == 0) then<br />
outputConsole("No player named " .. playerName .. " is registered.", thePlayer)<br />
else<br />
outputConsole("Money amount of player " .. playerName .. " is " .. result[1].money, thePlayer)<br />
end<br />
end<br />
addCommandHandler("playermoney", showPlayerMoney)<br />
</syntaxhighlight><br />
<br />
Notice the lack of single quotes around the "?" in this example, even though it represents a string. executeSQLQuery will see that the playerName variable is a string and take care of the correct execution of the query by itself.<br />
<br />
The advantage of using executeSQLQuery is that it is immune to users trying to exploit the query with an SQL injection attack. playerName may contain special characters like ', " or -- that will not influence the query, unlike the older approach where playerName would be concatenated into the query string.<br />
<br />
==See Also==<br />
{{Registry_functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=SetVehicleLightState&diff=19162SetVehicleLightState2009-04-15T19:23:17Z<p>Flobu: </p>
<hr />
<div>{{Server client function}}<br />
__NOTOC__<br />
This function sets the state of the light on the vehicle.<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua">bool setVehicleLightState ( vehicle theVehicle, int light, int state )</syntaxhighlight><br />
<br />
==Required Arguments==<br />
*'''theVehicle:''' A handle to the [[vehicle]] that you wish to change the light state of.<br />
*'''light:''' A whole number determining the individual light. (0 - 3)<br />
*'''state:''' A whole number determining the new state of the light. ''0'' represents normal lights, and ''1'' represents broken lights.<br />
<br />
===Returns===<br />
Returns ''true'' if the light state was set successfully, ''false'' if invalid arguments were passed to the function.<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
newcar = createVehicle ( 520, 1024, 1024, 1024 ) -- create a new vehicle<br />
state = setVehicleLightState ( newcar, 0, 1 ) -- break the left front light<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Vehicle functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=SetVehicleLightState&diff=19161SetVehicleLightState2009-04-15T19:21:25Z<p>Flobu: </p>
<hr />
<div>{{Server client function}}<br />
__NOTOC__<br />
This function sets the state of the light on the vehicle.<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua">bool setVehicleLightState ( vehicle theVehicle, int light, int state )</syntaxhighlight><br />
<br />
==Required Arguments==<br />
*'''theVehicle:''' A handle to the [[vehicle]] that you wish to change the light state of.<br />
*'''light:''' A whole number determining the individual light. (0 - 3)<br />
*'''state:''' A whole number determining the new state of the light. ''0'' represents normal lights, and ''1'' represents broken lights.<br />
<br />
===Returns===<br />
Returns ''true'' if the light state was set, ''false'' if invalid arguments were passed to the function.<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
newcar = createVehicle ( 520, 1024, 1024, 1024 ) -- create a new vehicle<br />
state = setVehicleLightState ( newcar, 0, 1 ) -- break the left front light<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Vehicle functions}}</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=IsMTAWindowActive&diff=18678IsMTAWindowActive2009-03-16T13:49:19Z<p>Flobu: </p>
<hr />
<div>__NOTOC__ <br />
{{Client function}}<br />
This function returns whether the any system windows that take focus are active. This includes the chatbox input, console window, main menu and transferbox.<br />
To get the status of the debug view, see [[isDebugViewActive]].<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool isMTAWindowActive ()<br />
</syntaxhighlight> <br />
<br />
===Returns===<br />
Returns ''true'' if the focus is on the MTA window, ''false'' if isn't.<br />
<br />
==Example== <br />
This example does...<br />
<syntaxhighlight lang="lua"><br />
--This line does...<br />
blabhalbalhb --abababa<br />
--This line does this...<br />
mooo<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{GUI_functions}}<br />
[[Category:Needs Example]]</div>Flobuhttps://wiki.multitheftauto.com/index.php?title=Vehicle_IDs&diff=18118Vehicle IDs2009-01-06T17:05:20Z<p>Flobu: </p>
<hr />
<div>==Introduction==<br />
This is a list of GTA:SA's vehicle ID numbers, as listed in the vehicles.ide file. These vehicle ID numbers are used for several vehicle scripting functions.<br />
<br />
==2-Door and Compact cars==<br />
<table border="1" class="unnamed1"><br />
<tr><th>Name</th><th>ID</th><td></td><th>Name</th><th>ID</th></tr><tr><td>Alpha</td><td>602</td><td></td><td>Hustler</td><td>545</td></tr><tr><td>Blista Compact</td><td>496</td><td> </td><td>Majestic</td><td>517</td></tr><tr><td>Bravura</td><td>401</td><td> </td><td>Manana</td><td>410</td></tr><tr><td>Buccaneer</td><td>518</td><td> </td><td>Picador</td><td>600</td></tr><tr><td>Cadrona</td><td>527</td><td> </td><td>Previon</td><td>436</td></tr><tr><td>Club</td><td>589</td><td> </td><td>Stafford</td><td>580</td></tr><tr><td>Esperanto</td><td>419</td><td> </td><td>Stallion</td><td>439</td></tr><tr><td>Feltzer</td><td>533</td><td> </td><td>Tampa</td><td>549</td></tr><tr><td>Fortune</td><td>526</td><td> </td><td>Virgo</td><td>491</td></tr><tr><td>Hermes</td><td>474</td><td> </td><td> </td><td> </td></tr></table><br />
<br />
== 4-Door and Luxury cars==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th>Name</th><th>ID</th></tr><tr><td>Admiral</td><td>445</td><td> </td><td>Oceanic</td><td>467</td></tr><tr><td>Damaged Glendale</td><td>604</td><td> </td><td>Premier</td><td>426</td></tr><tr><td>Elegant</td><td>507</td><td> </td><td>Primo</td><td>547</td></tr><tr><td>Emperor</td><td>585</td><td> </td><td>Sentinel</td><td>405</td></tr><tr><td>Euros</td><td>587</td><td> </td><td>Stretch</td><td>409</td></tr><tr><td>Glendale</td><td>466</td><td> </td><td>Sunrise</td><td>550</td></tr><tr><td>Greenwood</td><td>492</td><td> </td><td>Tahoma</td><td>566</td></tr><tr><td>Intruder</td><td>546</td><td> </td><td>Vincent</td><td>540</td></tr><tr><td>Merit</td><td>551</td><td> </td><td>Washington</td><td>421</td></tr><tr><td>Nebula</td><td>516</td><td> </td><td>Willard</td><td>529</td></tr></table><br />
<br />
==Aircraft==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th><br />
Name</th><th>ID</th></tr><tr><td>Andromada</td><td>592</td><td> </td><td><br />
Nevada</td><td>553</td></tr><tr><td>AT-400</td><td>577</td><td> </td><td><br />
<br />
News Chopper</td><td>488</td></tr><tr><td>Beagle</td><td>511</td><td> </td><td><br />
Police Maverick</td><td>497</td></tr><tr><td>Cargobob</td><td>548</td><td> </td><td><br />
Raindance</td><td>563</td></tr><tr><td>Cropduster</td><td>512</td><td> </td><td><br />
<br />
Rustler</td><td>476</td></tr><tr><td>Dodo</td><td>593</td><td> </td><td><br />
Seasparrow</td><td>447</td></tr><tr><td>Hunter</td><td>425</td><td> </td><td><br />
Shamal</td><td>519</td></tr><tr><td>Hydra</td><td>520</td><td> </td><td><br />
<br />
Skimmer</td><td>460</td></tr><tr><td>Leviathan</td><td>417</td><td> </td><td><br />
Sparrow</td><td>469</td></tr><tr><td>Maverick</td><td>487</td><td> </td><td><br />
Stuntplane</td><td>513</td></tr></table><br />
<br />
==Bikes==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th>Name</th><th>ID</th></tr><tr><td>BF-400</td><td>581</td><td> </td><td>Mountain Bike</td><td>510</td></tr><tr><td>Bike</td><td>509</td><td> </td><td>NRG-500</td><td>522</td> </tr><tr><td>BMX</td><td>481</td><td> </td><td>PCJ-600</td><td>461</td></tr><tr><td>Faggio</td><td>462</td><td> </td><td>Pizza Boy</td><td>448</td></tr><tr><td>FCR-900</td><td>521</td><td> </td><td>Sanchez</td><td> 468</td></tr><tr><td>Freeway</td><td>463</td><td> </td><td>Wayfarer</td><td>586</td></tr></table><br />
<br />
==Boats==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th></tr><tr><td>Coastguard</td><td>472</td></tr><tr><td>Dinghy</td><td>473</td></tr><tr><td>Jetmax</td><td>493</td></tr><tr><td>Launch</td><td>595</td></tr><tr><td>Marquis</td><td>484</td></tr><tr><td>Predator</td><td>430</td></tr><tr><td>Reefer</td><td>453</td></tr><tr><td>Speeder</td><td>452</td></tr><tr><td>Squalo</td><td>446</td></tr><tr><td>Tropic</td><td>454</td></tr></table><br />
<br />
==Civil Servant / Public Transportation==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th>Name</th><th>ID</th></tr><tr><td>Baggage</td><td>485</td><td> </td><td>Tram</td><td>449</td></tr><tr><td>Brown Streak Engine**</td><td>538</td><td> </td><td>Utility Van</td><td>552</td></tr><tr><td>Bus</td><td>431</td><td> </td><td> </td><td> </td></tr><tr><td>Cabbie</td><td>438</td><td> </td><td> </td><td> </td></tr><tr><td>Coach</td><td>437</td><td> </td><td> </td><td> </td></tr><tr><td>Freight</td><td>537</td><td> </td><td> </td><td> </td></tr><tr><td>Sweeper</td><td>574</td><td> </td><td> </td><td> </td></tr><tr><td>Taxi</td><td>420</td><td> </td><td> </td><td> </td></tr><tr><td>Towtruck</td><td>525</td><td> </td><td> </td><td> </td></tr><tr><td>Trashmaster</td><td>408</td><td> </td><td> </td><td> </td></tr></table><br />
<br />
==Government Vehicles==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th>Name</th><th>ID</th></tr><tr><td>Ambulance</td><td>416</td><td> </td><td>Police Car (Los Santos)</td><td>596</td></tr><tr><td>Barracks</td><td>433</td><td> </td><td>Police Car (San Fierro)</td><td>597</td></tr><tr><td>Enforcer</td><td>427</td><td> </td><td>Police Ranger</td><td>599</td></tr><tr><td>FBI Rancher</td><td>490</td><td> </td><td>Rhino</td><td>432</td></tr><tr><td>FBI Truck</td><td>528</td><td> </td><td>S.W.A.T.</td><td>601</td></tr><tr><td>Fire Truck</td><td>407</td><td> </td><td>Securicar</td><td>428</td></tr><tr><td>Fire Truck (Ladder)</td><td>544</td><td> </td><td> </td><td> </td></tr><tr><td>HPV1000</td><td>523</td><td> </td><td> </td><td> </td></tr><tr><td>Patriot</td><td>470</td><td> </td><td> </td><td> </td></tr><tr><td>Police Car (Las Venturas)</td><td>598</td><td> </td><td> </td><td> </td></tr></table><br />
<br />
==Heavy and Utility Trucks==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th>Name</th><th>ID</th></tr><tr><td>Benson</td><td>499</td><td> </td><td>Hotdog</td><td>588</td></tr><tr><td>Black Boxville</td><td>609</td><td> </td><td>Linerunner</td><td>403</td></tr><tr><td>Boxville</td><td>498</td><td> </td><td>Linerunner (From "Tanker Commando")</td><td>514</td></tr><tr><td>Cement Truck</td><td>524</td><td> </td><td>Mr. Whoopee</td><td>423</td></tr><tr><td>Combine Harvester</td><td>532</td><td> </td><td>Mule</td><td>414</td></tr><tr><td>DFT-30</td><td>578</td><td> </td><td>Packer</td><td>443</td></tr><tr><td>Dozer</td><td>486</td><td> </td><td>Roadtrain</td><td>515</td></tr><tr><td>Dumper</td><td>406</td><td> </td><td>Tractor</td><td>531</td></tr><tr><td>Dune</td><td>573</td><td> </td><td>Yankee</td><td>456</td></tr><tr><td>Flatbed</td><td>455</td><td> </td><td> </td><td> </td></tr></table><br />
<br />
==Light Trucks and Vans==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th>Name</th><th>ID</th></tr><tr><td>Berkley's RC Van</td><td>459</td><td> </td><td>Sadler</td><td>543</td></tr><tr><td>Bobcat</td><td>422</td><td> </td><td>Tug</td><td>583</td></tr><tr><td>Burrito</td><td>482</td><td> </td><td>Walton</td><td>478</td></tr><tr><td>Damaged Sadler</td><td>605</td><td> </td><td>Yosemite</td><td>554</td></tr><tr><td>Forklift</td><td>530</td><td> </td><td> </td><td> </td></tr><tr><td>Moonbeam</td><td>418</td><td> </td><td> </td><td> </td></tr><tr><td>Mower</td><td>572</td><td> </td><td> </td><td> </td></tr><tr><td>News Van</td><td>582</td><td> </td><td> </td><td> </td></tr><tr><td>Pony</td><td>413</td><td> </td><td> </td><td> </td></tr><tr><td>Rumpo</td><td>440</td><td> </td><td> </td><td> </td></tr></table><br />
<br />
==Lowriders==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th></tr><tr><td>Blade</td><td>536</td></tr><tr><td>Broadway</td><td>575</td></tr><tr><td>Remington</td><td>534</td></tr><tr><td>Savanna</td><td>567</td></tr><tr><td>Slamvan</td><td>535</td></tr><tr><td>Tornado</td><td>576</td></tr><tr><td>Voodoo</td><td>412</td></tr></table><br />
<br />
==Muscle Cars==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th></tr><tr><td>Buffalo</td><td>402</td></tr><tr><td>Clover</td><td>542</td></tr><tr><td>Phoenix</td><td>603</td></tr><tr><td>Sabre</td><td>475</td></tr></table><br />
<br />
==Trains==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th></tr><br />
<tr><td>Freight</td><td>537</td></tr><br />
<tr><td>Brown Streak</td><td>538</td></tr><br />
<tr><td>Flat Freight</td><td>569</td></tr><br />
<tr><td>Box Freight</td><td>590</td></tr></table><br />
<br />
==RC Vehicles==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th></tr><tr><td>RC Bandit</td><td>441</td></tr><tr><td>RC Baron</td><td>464</td></tr><tr><td>RC Goblin</td><td>501</td></tr><tr><td>RC Raider</td><td>465</td></tr><tr><td>RC Tiger</td><td>564</td></tr></table><br />
<br />
==Recreational==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th>Name</th><th>ID</th></tr><tr><td>Bandito</td><td>568</td><td> </td><td>Monster 3</td><td>557</td></tr><tr><td>BF Injection</td><td>424</td><td> </td><td>Quadbike</td><td>471</td></tr><tr><td>Bloodring Banger</td><td>504</td><td> </td><td>Sandking</td><td>495</td></tr><tr><td>Caddy</td><td>457</td><td> </td><td>Vortex</td><td>539</td></tr><tr><td>Camper</td><td>483</td><td> </td><td> </td><td> </td></tr><tr><td>Journey</td><td>508</td><td> </td><td> </td><td> </td></tr><tr><td>Kart</td><td>570</td><td> </td><td> </td><td> </td></tr><tr><td>Mesa</td><td>500</td><td> </td><td> </td><td> </td></tr><tr><td>Monster</td><td>444</td><td> </td><td> </td><td> </td></tr><tr><td>Monster 2</td><td>556</td><td> </td><td> </td><td> </td></tr></table><br />
<br />
==Street Racers==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th><td> </td><th>Name</th><th>ID</th></tr><tr><td>Banshee</td><td>429</td><td> </td><td>Infernus</td><td>411</td></tr><tr><td>Bullet</td><td>541</td><td> </td><td>Jester</td><td>559</td></tr><tr><td>Cheetah</td><td>415</td><td> </td><td>Stratum</td><td>561</td></tr><tr><td>Comet</td><td>480</td><td> </td><td>Sultan</td><td>560</td></tr><tr><td>Elegy</td><td>562</td><td> </td><td>Super GT</td><td>506</td></tr><tr><td>Flash</td><td>565</td><td> </td><td>Turismo</td><td>451</td></tr><tr><td>Hotknife</td><td>434</td><td> </td><td>Uranus</td><td>558</td></tr><tr><td>Hotring Racer</td><td>494</td><td> </td><td>Windsor</td><td>555</td></tr><tr><td>Hotring Racer 2</td><td>502</td><td> </td><td>ZR-350</td><td>477</td></tr><tr><td>Hotring Racer 3</td><td>503</td><td> </td><td> </td><td> </td></tr></table><br />
<br />
==SUVs and Wagons==<br />
<table border="1" class="unnamed1"><tr><th>Name</th><th>ID</th></tr><tr><td>Huntley</td><td>579</td></tr><tr><td>Landstalker</td><td>400</td></tr><tr><td>Perennial</td><td>404</td></tr><tr><td>Rancher</td><td>489</td></tr><tr><td>Rancher (From "Lure")</td><td>505</td></tr><tr><td>Regina</td><td>479</td></tr><tr><td>Romero</td><td>442</td></tr><tr><td>Solair</td><td>458</td></tr></table><br />
<br />
==Trailers==<br />
<table border="1" class="unnamed1"><tr><th width="218">Name</th><th width="24">ID</th></tr><tr><td>Baggage Trailer (covered)</td><td>606</td></tr><tr><td>Baggage Trailer (Uncovered)</td><td>607</td></tr><tr><td>Farm Trailer</td><td>610</td></tr><tr><td>Freight Train Boxcar**</td><td>590</td></tr><tr><td>Freight Train Flatbed**</td><td>569</td></tr><tr><td>"Street Clean" Trailer</td><td>611</td></tr><tr><td>Trailer (From "Tanker Commando")(*PRONE TO CRASHES*)</td><td>584</td></tr><tr><td>Trailer (Stairs)</td><td>608</td></tr><tr><td>Trailer 1</td><td>435</td></tr><tr><td>Trailer 2</td><td>450</td></tr><tr><td>Trailer 3</td><td>591</td></tr></table><br />
<br />
==Misc==<br />
<table border="1" class="unnamed1"><tr><th width="218">Name</th><th width="24">ID</th></tr><tr><td>RC Cam (flower pot)</td><td>594</td></table><br />
<br />
<br />
[[it:ID Veicoli]]</div>Flobu