https://wiki.multitheftauto.com/api.php?action=feedcontributions&user=MistaC87&feedformat=atomMulti Theft Auto: Wiki - User contributions [en]2024-03-29T05:12:53ZUser contributionsMediaWiki 1.39.3https://wiki.multitheftauto.com/index.php?title=SetPlayerMoney&diff=15821SetPlayerMoney2008-02-17T01:14:40Z<p>MistaC87: /* Example */ Added new example.</p>
<hr />
<div>__NOTOC__<br />
{{Server function}}<br />
Sets a player's money to a certain value, regardless of current player money. It should be noted that setting negative values does not work and in fact gives the player large amounts of money.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"> bool setPlayerMoney ( player thePlayer, int amount ) </syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''thePlayer:''' Which player to set the money of<br />
*'''amount:''' A whole integer specifying the new amount of money the player will have<br />
<br />
===Returns===<br />
Returns ''true'' if the money was added, or ''false'' if invalid parameters were passed.<br />
<br />
==Example== <br />
'''Example 1:''' This example sets the player's money to the desired amount when he types "setcash" in console.<br />
<syntaxhighlight lang="lua"><br />
function setCash ( thePlayer, command, amount ) -- when the setcash function is called<br />
setPlayerMoney ( thePlayer, tonumber(amount) ) -- change player's money to the desired amount<br />
end<br />
addCommandHandler ( "setcash", setCash ) -- add a command handler for setcash<br />
</syntaxhighlight><br />
'''Example 2:''' This gives all players the amount of 1337 money when "leet" is typed in console.<br />
<syntaxhighlight lang="lua"><br />
function leetmoney()<br />
setPlayerMoney( getRootElement(), 1337 )<br />
end<br />
addCommandHandler("leet", leetmoney)<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Player functions}}</div>MistaC87https://wiki.multitheftauto.com/index.php?title=DestroyElement&diff=15819DestroyElement2008-02-17T00:44:35Z<p>MistaC87: /* Example */ Added new example.</p>
<hr />
<div>__NOTOC__<br />
{{Server client function}}<br />
This function destroys an [[element]] and all elements withinn it in the hierarchy (its children, the children of those children etc). [[player|Player]] elements cannot be destroyed using this function. A player can only be removed from the hierarchy when they quit or are kicked. The root element also cannot be destroyed, however, passing the root as an argument will wipe all elements from the server, except for the players and clients, which will become direct descendants of the root node, and other elements that cannot be destroyed, such as resource root elements.<br />
<br />
Players are not the only elements that cannot be deleted. This list also includes remote clients and console elements.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool destroyElement ( element elementToDestroy )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''elementToDestroy:''' The element you wish to destroy. <br />
<br />
===Returns===<br />
Returns ''true'' if the element was destroyed successfully, ''false'' if either the element passed to it was invalid or it could not be destroyed for some other reason (for example, clientside destroyElement can't destroy serverside elements).<br />
<br />
==Example==<br />
'''Example 1:''' This example would destroy every element in the map, with the exception of players and the root element itself.<br />
<syntaxhighlight lang="lua"><br />
-- Find the root element (the element that contains all others)<br />
root = getRootElement ()<br />
-- Destroy all its children, except players.<br />
destroyElement ( root )<br />
</syntaxhighlight><br />
<br />
'''Example 2:''' This example destroys all vehicles of the specified model:<br />
<syntaxhighlight lang="lua"><br />
function destroyVehiclesOfModel(modelID)<br />
-- get a table of all the vehicles that exist and loop through it<br />
local vehicles = getElementsByType("vehicle")<br />
for i,v in ipairs(vehicles) do<br />
-- if the vehicle's ID is the one provided, destroy it<br />
if (getVehicleID(v) == modelID) then<br />
destroyElement(v)<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
'''Example 3:''' This example allows creation of claymores, which trigger and explode. When they explode, the colshape and object for the claymore are destroyed.<br />
<syntaxhighlight lang="lua">function createClaymore ( x,y,z, creator )<br />
local claymoreObject = createObject ( 1945, x, y, z - 1, 0, 0, 90 ) -- create an object which looks like a claymore<br />
local claymoreCol = createColSphere ( x, y, z, 1 ) -- create a col sphere with radius 1<br />
setElementData ( claymoreCol, "object", claymoreObject ) -- store the object of the claymore<br />
setElementData ( claymoreCol, "creatorPlayer", creator ) -- store the person who created it<br />
addEventHandler ( "onColShapeHit", claymoreCol, claymoreHit ) -- add an event handler to the colshape<br />
end<br />
<br />
function claymoreHit ( thePlayer, matchingDimension )<br />
-- retrieve the object associated to the claymore, and who created it<br />
local claymoreObject = getElementData ( source, "object" )<br />
local claymoreCreator = getElementData ( source, "creatorPlayer" )<br />
-- get the position of the claymore<br />
local x,y,z = getElementPosition ( source )<br />
createExplosion ( x,y,z, 12, claymoreCreator ) -- create an explosion, associated to the creator, of a small size at the col's position<br />
-- remove the event handler for the colshape<br />
removeEventHandler ( "onColShapeHit", source, claymoreHit )<br />
-- destroy the claymore object, and the col shape so it doesn't trigger again.<br />
destroyElement ( claymoreObject )<br />
destroyElement ( source )<br />
end<br />
</syntaxhighlight><br />
'''Example 4:''' This example destroys all vehicles, regardless of ID, name, etc:<br />
<syntaxhighlight lang="lua"><br />
function allvehiclesaredoomed()<br />
-- get a table of all the vehicles that exist and loop through it<br />
vehicles = getElementsByType("vehicle")<br />
for i,v in ipairs(vehicles) do<br />
-- destroy every vehicle.<br />
destroyElement(v)<br />
end<br />
end<br />
--The command handler below will destroy all vehicles once<br />
--you enter /vdoom in the chat box or vdoom in the game console.<br />
addCommandHandler("vdoom", allvehiclesaredoomed)<br />
--This is very useful if you use the freeroam resource and some<br />
--heartless players start spawn spamming.<br />
--You can also set it on a timer to have your server clear all<br />
--vehicles ever 60 minutes, (1 hour). Timer below:<br />
setTimer(allvehiclesaredoomed, 3600000, 0)<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Element functions}}</div>MistaC87