https://wiki.multitheftauto.com/api.php?action=feedcontributions&user=Thecoolser&feedformat=atomMulti Theft Auto: Wiki - User contributions [en]2024-03-28T09:05:47ZUser contributionsMediaWiki 1.39.3https://wiki.multitheftauto.com/index.php?title=DestroyElement&diff=38671DestroyElement2014-01-29T04:03:07Z<p>Thecoolser: destroyElement</p>
<hr />
<div>هذه الوظيفة تقوم بازالة العنصر<br />
<br />
==تركيب الجملة== <br />
<syntaxhighlight lang="lua"><br />
bool destroyElement ( element elementToDestroy )<br />
</syntaxhighlight> <br />
<br />
===الفراغات المطلوبة=== <br />
*'''elementToDestroy:''' العنصر الذي تريد ازالتة<br />
<br />
<br />
<br />
==مثال==<br />
'''مثال 1'''<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 />
'''مثال 2'''<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 (getElementModel(v) == modelID) then<br />
destroyElement(v)<br />
end<br />
end<br />
end<br />
<br />
destroyVehiclesOfModel(445)<br />
</syntaxhighlight><br />
<br />
'''مثال 3'''<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 />
'''مثال 4'''<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 />
==انظر ايضا الى==<br />
{{Element functions}}</div>Thecoolser