ToggleObjectRespawn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added to the needs example category)
(Fix oop def)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Needs Example}}
{{Client function}}
{{Client function}}


Line 9: Line 8:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool toggleObjectRespawn( object theObject, bool respawn )
bool toggleObjectRespawn ( object theObject, bool respawn )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||[[object]]:toggleRespawn}}
===Required Arguments===
===Required Arguments===
*'''theObject''': The object you want to toggle the respawn from
*'''theObject''': the object you want to toggle the respawn from
*'''respawn ''': A bool denoting whether we want to enable (''true'') or disable (''false'') respawning
*'''respawn ''': a bool denoting whether we want to enable (''true'') or disable (''false'') respawning


===Returns===
===Returns===
Returns ''true'' when the it was changed successfully, or ''false'' otherwise.
* ''true'' when the it was changed successfully.
 
* ''false'' otherwise.
==Requirements==
{{Requirements|n/a|1.4}}


==Example==
==Example==
This example adds command ''tos'' that toggles respawn of all the objects.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Todo
local respawn = false
addCommandHandler("tos",
function ()
for i, object in pairs(getElementsByType("object")) do
toggleObjectRespawn(object, not respawn)
end
outputChatBox("Object respawning " .. (respawn and "disabled" or "enabled"))
respawn = not respawn
end)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Client_object_functions}}
{{Client_object_functions}}

Latest revision as of 07:23, 17 August 2021

This function is used to toggle if an object should respawn after it got destroyed

Syntax

bool toggleObjectRespawn ( object theObject, bool respawn )

OOP Syntax Help! I don't understand this!

Method: object:toggleRespawn(...)


Required Arguments

  • theObject: the object you want to toggle the respawn from
  • respawn : a bool denoting whether we want to enable (true) or disable (false) respawning

Returns

  • true when the it was changed successfully.
  • false otherwise.

Example

This example adds command tos that toggles respawn of all the objects.

local respawn = false
addCommandHandler("tos",
	function ()
		for i, object in pairs(getElementsByType("object")) do
			toggleObjectRespawn(object, not respawn)
		end
		outputChatBox("Object respawning " .. (respawn and "disabled" or "enabled"))
		respawn = not respawn
	end)

See Also