https://wiki.multitheftauto.com/api.php?action=feedcontributions&user=The+Ex&feedformat=atomMulti Theft Auto: Wiki - User contributions [en]2024-03-28T13:45:24ZUser contributionsMediaWiki 1.39.3https://wiki.multitheftauto.com/index.php?title=LoadMapData&diff=24375LoadMapData2010-08-18T18:44:42Z<p>The Ex: /* Example */</p>
<hr />
<div>{{Server function}}<br />
__NOTOC__<br />
This function is intended to load data from a loaded XML file into the element tree. This could be used for loading an external map, or part of another map.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
element loadMapData ( xmlnode node, element parent ) <br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''node:''' The node that you wish to load into the [[element tree]].<br />
*'''parent:''' The node you wish to be the parent of the new map data.<br />
<br />
===Returns===<br />
Returns an [[element]] object that corresponds to the root of the new data added, i.e. an element that represents the ''node'' xmlnode passed to the function. Returns ''false'' if the arguments are invalid.<br />
<br />
==Example== <br />
This example is a function that you could use to load an arbitary [[Map Files|map file]] into the [[element tree]].<br />
<syntaxhighlight lang="lua"><br />
function loadMapFile ( filename )<br />
node = getResourceConfig ( filename )<br />
-- Check if the file was loaded ok<br />
if ( node ) then<br />
-- Load the loaded xml file into the element tree<br />
loadMapData ( node, getRootElement() )<br />
-- Unload the xml file again<br />
xmlUnloadFile ( node )<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Map_functions}}</div>The Exhttps://wiki.multitheftauto.com/index.php?title=OnClientPedDamage&diff=24373OnClientPedDamage2010-08-18T12:22:16Z<p>The Ex: /* Example */</p>
<hr />
<div>__NOTOC__<br />
{{Client event}}<br />
<br />
This event is triggered whenever a [[ped]] is damaged.<br />
<br />
==Parameters==<br />
<syntaxhighlight lang="lua"><br />
element attacker, int weapon, int bodypart [, float loss ]<br />
</syntaxhighlight> <br />
<br />
*'''attacker''': A [[player]] [[element]] representing the attacker or [[vehicle]] [[element]] (when a ped falls of a bike).<br />
*'''weapon''': An integer representing the weapon ID the attacker used<br />
*'''bodypart''': An integer representing the bodypart the ped was damaged<br />
{{BodyParts}}<br />
*'''loss''': A float representing the percentage of health the ped lost.<br />
<br />
==Source==<br />
The [[event system#Event source|source]] of this event is the [[ped]] that got damaged<br />
<br />
==Cancel effect==<br />
If this event is [[Event system#Canceling|canceled]], then any damaging effects to the ped will cease.<br />
<br />
==Example== <br />
This example cancels any damage done to peds<br />
<syntaxhighlight lang="lua"><br />
function cancelPedDamage ( attacker )<br />
cancelEvent() -- cancel any damage done to peds<br />
end<br />
addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
===Client ped events===<br />
{{Client_ped_events}}<br />
===Client event functions===<br />
{{Client_event_functions}}</div>The Exhttps://wiki.multitheftauto.com/index.php?title=SetTrafficLightsLocked&diff=24347SetTrafficLightsLocked2010-08-12T11:54:56Z<p>The Ex: /* Example */</p>
<hr />
<div>__NOTOC__<br />
{{Server client function}}<br />
Toggles whether you want the traffic lights to be locked. If the lights are locked, it means they won't change unless you do [[setTrafficLightState]].<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua"><br />
bool setTrafficLightsLocked ( bool toggle )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''toggle''': A [[bool]] indicating whether you want the traffic lights to change automatically, or not<br />
<br />
===Returns===<br />
Returns ''true'' if the successful, ''false'' otherwise.<br />
<br />
==Example==<br />
This example toggles traffic lights between 'locked' and 'unlocked'.<br />
<br />
<syntaxhighlight lang="lua"><br />
function toggleTrafficLights()<br />
if areTrafficLightsLocked() then -- See if traffic lights are currently locked<br />
setTrafficLightsLocked(false) -- unlock traffic lights if they are currently locked<br />
else<br />
setTrafficLightsLocked(true) -- lock traffic lights if they are not locked<br />
end<br />
end<br />
-- add command handler for command which toggles lights<br />
addCommandHandler("toggletrafficlights",toggleTrafficLights)<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{World_functions}}<br />
<br />
[[Category:Needs_Example]]</div>The Exhttps://wiki.multitheftauto.com/index.php?title=AreTrafficLightsLocked&diff=24346AreTrafficLightsLocked2010-08-12T11:27:18Z<p>The Ex: /* Example */</p>
<hr />
<div>__NOTOC__<br />
{{Server client function}}<br />
Gets whether the traffic lights are currently locked or not. If the lights are locked, it means they won't change unless you do [[setTrafficLightState]].<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua"><br />
bool areTrafficLightsLocked ( )<br />
</syntaxhighlight><br />
<br />
===Returns===<br />
Returns ''true'' the traffic lights are currently locked, ''false'' otherwise.<br />
<br />
==Example==<br />
This example toggles traffic lights between 'locked' and 'unlocked'.<br />
<br />
<syntaxhighlight lang="lua"><br />
function toggleTrafficLights()<br />
if areTrafficLightsLocked() then -- See if traffic lights are currently locked<br />
setTrafficLightsLocked(false) -- unlock traffic lights if they are currently locked<br />
else<br />
setTrafficLightsLocked(true) -- lock traffic lights if they are not<br />
end<br />
end<br />
-- add command for toggling traffic lights<br />
addCommandHandler("toggletrafficlights",toggleTrafficLights)<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{World_functions}}<br />
<br />
[[Category:Needs_Example]]</div>The Exhttps://wiki.multitheftauto.com/index.php?title=GuiGridListSetItemText&diff=24322GuiGridListSetItemText2010-08-09T20:15:13Z<p>The Ex: /* Required Arguments */</p>
<hr />
<div>{{Client function}}<br />
__NOTOC__<br />
This function changes the text of a gridlist item.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool guiGridListSetItemText ( element gridList, int rowIndex, int columnIndex, string text, bool section, bool number )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''gridList:''' The grid list element<br />
*'''rowIndex:''' Row ID<br />
*'''columnIndex:''' Column ID<br />
*'''text:''' The text you want to put in (does NOT accept numbers, use tostring() for that)<br />
*'''section:''' Determines if the item is a section<br />
*'''number:''' Tells whether the text item is a number value or not (used for sorting)<br />
<br />
===Returns===<br />
Returns ''true'' if the item text was set successfully, ''false'' otherwise.<br />
<br />
==Example== <br />
This example creates a player list on the right of the screen and fills it<br />
<syntaxhighlight lang="lua"><br />
function clientsideResourceStart ()<br />
local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) -- Create the grid list<br />
local column = guiGridListAddColumn( playerList, "Player", 0.85 ) -- Create a 'players' column in the list<br />
if ( column ) then -- If the column was successfully created<br />
for id, playeritem in ipairs(getElementsByType("player")) do <br />
--Loop through all the players, adding them to the table<br />
local row = guiGridListAddRow ( playerList )<br />
guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false )<br />
end<br />
end<br />
end<br />
addEventHandler ( "onClientResourceStart", getResourceRootElement(), clientsideResourceStart )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{GUI functions}}</div>The Exhttps://wiki.multitheftauto.com/index.php?title=EngineLoadTXD&diff=24317EngineLoadTXD2010-08-09T20:01:08Z<p>The Ex: /* Syntax */</p>
<hr />
<div>{{Client function}}<br />
__NOTOC__<br />
This function loads a RenderWare Texture Dictionary (TXD) file into GTA. The texture dictionary can then be used to provide textures.<br />
<br />
This is a client side function. Be sure to transfer your TXD file by including it in the meta file.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
txd engineLoadTXD ( string txd_file, [ bool filteringEnabled = true ] ) <br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''txd_file:''' The [[filepath]] to the txd file you want to load<br />
<br />
===Optional Arguments===<br />
*'''filteringEnabled:''' Texture filtering<br />
<br />
===Returns===<br />
Returns a [[TXD]] if the file was loaded, ''false'' otherwise.<br />
<br />
==Example== <br />
'''Example 1:''' This example loads a combination of a custom DFF and TXD file to replace the Euros vehicle in-game. The collisions are embedded inside the DFF file.<br />
<syntaxhighlight lang="lua"><br />
outputChatBox ( "> replacing the euros vehicle" )<br />
<br />
txd = engineLoadTXD ( "data/euros.txd" )<br />
engineImportTXD ( txd, 587 )<br />
dff = engineLoadDFF ( "data/euros.dff", 587 )<br />
engineReplaceModel ( dff, 587 )<br />
</syntaxhighlight><br />
<br />
<br />
'''Example 2:''' This example loads a combination of custom DFF, TXD and COL files to replace an in-game model of a set of floors.<br />
<syntaxhighlight lang="lua"><br />
outputChatBox ( "> loading floor objects" )<br />
txd_floors = engineLoadTXD ( "models/office_floors.txd" )<br />
engineImportTXD ( txd_floors, 3781 )<br />
col_floors = engineLoadCOL ( "models/office_floors.col" )<br />
dff_floors = engineLoadDFF ( "models/office_floors.dff", 0 )<br />
engineReplaceCOL ( col_floors, 3781 )<br />
engineReplaceModel ( dff_floors, 3781 )<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Engine_functions}}</div>The Exhttps://wiki.multitheftauto.com/index.php?title=ExecuteSQLInsert&diff=24312ExecuteSQLInsert2010-08-09T19:47:23Z<p>The Ex: /* Example */</p>
<hr />
<div>__NOTOC__<br />
{{Server function}}<br />
This function adds a row in the database.<br />
<br />
The SQLite database contains globally stored data and can be used by scripts to store and retrieve data in a structured manner.<br />
<br />
The executed SQL query is the following:<br />
<br />
<syntaxhighlight lang="lua">[sql]INSERT INTO <table> <columns> VALUES <values></syntaxhighlight><br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool executeSQLInsert ( string tableName, string values, ( [string columns] ) )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''tableName:''' The name of the table you want to modify.<br />
*'''values:''' The values that need to be inserted for each field in the table. The ' character is used to specify a value and , is used as a delimiter for multiple values (e.g. '' 'value1','value2','value3' ''. The value order corresponds to either the default column order in the table, or the optional column argument (see below). <br />
<br />
===Optional Arguments===<br />
*'''columns:''' The columns where the values will be stored into. This corresponds with the given value order (your first column will be set to the first specified value, the second column to the second value, ...) and should be separated by the , delimiter.<br />
<br />
===Returns===<br />
The function returns ''true'' on success, and ''false'' on failure.<br />
<br />
==Example==<br />
This example creates a SQL table when a map loads, and stores info about a player to that database when he spawns.<br />
<syntaxhighlight lang="lua"><br />
function onMapLoad ()<br />
-- create our table, if it doesn't already exist<br />
executeSQLCreateTable ( "players", "clothes_head_texture TEXT, clothes_head_model TEXT, player TEXT" )<br />
end<br />
addEventHandler ( "onGamemodeMapStart", getRootElement(), onMapLoad )<br />
<br />
function addInfoToSQL( theSpawnpoint, theTeam ) <br />
local sourcename = getPlayerName ( source ) -- get the player's name<br />
<br />
-- try to retrieve the player data from the db<br />
result = executeSQLSelect ( "players", "player", "player = '" .. sourcename .. "'" )<br />
if ( result == false ) then -- see if any data was found at all<br />
outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source )<br />
executeSQLInsert ( "players", "'none', 'none', '" .. sourcename .. "'" )<br />
else<br />
outputChatBox ( "Welcome back " .. sourcename .. "!", source )<br />
executeSQLUpdate ( "players", "clothes_head_texture = 'hairgreen', clothes_head_model = 'somehead'",<br />
"player = '" .. sourcename .. "'" )<br />
end <br />
<br />
-- get the clothes data for the player<br />
result = executeSQLSelect ( "players", "clothes_head_texture, clothes_head_model", "player = '" .. sourcename .. "'" )<br />
outputChatBox ( "Your head texture is " .. result[1].clothes_head_texture )<br />
outputChatBox ( "Your head model is " .. result[1]['clothes_head_model'] ) <br />
end<br />
addEventHandler ( "onPlayerSpawn", getRootElement(), addInfoToSQL)<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Registry_functions}}</div>The Ex