GetResourceState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Improved example)
 
(15 intermediate revisions by 10 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
__NOTOC__
This fake function is for use with blah & blah and does blahblahblabhalbhl
This function returns the state of a given resource


==Syntax==  
==Syntax==
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string getResourceStart ( resource )  
string getResourceState ( resource theResource )  
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''theResource:''' The resource you wish to get the state of.
*'''argumentName:''' description
{{OOP||[[resource]]:getState|state}}
 
<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===
{{OptionalArg}}  
*'''argumentName2:''' description
*'''argumentName3:''' description
 
===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
If successful returns a string with the resource state in it, ''false'' otherwise.
Returns ''true'' if blah, ''false'' otherwise. <br \>
The state can be one of:
- false on fail
*'''loaded'''
*'''running'''
*'''starting'''
*'''stopping'''
*'''failed to load''' - Use [[getResourceLoadFailureReason]] to find out why it failed.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example returns the state of a given resource. Syntax: ''/state <Resource Name>''
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function getState( player, command, resourceName )
blabhalbalhb --abababa
if not resourceName then
--This line does this...
outputChatBox( "Syntax: " .. command .. " [resource name]", player, 255, 0, 0 )
mooo
return
end
local resource = getResourceFromName( resourceName )
if not resource then
outputChatBox( "Error: No resource with name " .. resourceName .. " exists.", player, 255, 0, 0 )
return
end
local state = getResourceState( resource )
outputChatBox( "Resource " .. resourceName .. " is " .. state, player, 0, 0, 255 )
end
 
addCommandHandler( "state", getState )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Resource functions}}
{{FunctionArea_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function

Latest revision as of 18:10, 21 March 2024

This function returns the state of a given resource

Syntax

string getResourceState ( resource theResource ) 

Required Arguments

  • theResource: The resource you wish to get the state of.

OOP Syntax Help! I don't understand this!

Method: resource:getState(...)
Variable: .state


Returns

If successful returns a string with the resource state in it, false otherwise. The state can be one of:

Example

This example returns the state of a given resource. Syntax: /state <Resource Name>

function getState( player, command, resourceName )
	if not resourceName then
		outputChatBox( "Syntax: " .. command .. " [resource name]", player, 255, 0, 0 )
		return
	end
	local resource = getResourceFromName( resourceName )
	if not resource then
		outputChatBox( "Error: No resource with name " .. resourceName .. " exists.", player, 255, 0, 0 )
		return
	end
	local state = getResourceState( resource )
	outputChatBox( "Resource " .. resourceName .. " is " .. state, player, 0, 0, 255 )
end

addCommandHandler( "state", getState )

See Also