GetResourceState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 10: Line 10:


===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 -->
*'''res:''' The resource you wish to get the name of.
*'''res:''' The resource you wish to get the name of.


===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 a string with the resource state in it. <br \>
The state can be one of:
- false on fail
*'''loaded'''
*'''running'''


==Example==  
==Example==  
<section class="server" name="Server" show="true">
<section class="server" name="Server" show="true">
<!-- Explain what the example is in a single sentance -->
This example returns the state of a given resource. Syntax: ''/state <Resource Name>''
This example returns the state of a given resource. Syntax: ''/state <Resource Name>''
<!-- 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">
function getState( player, command, sz )
function getState( player, command, sz )

Revision as of 13:14, 28 March 2008

This function returns the state of a given resource

Syntax

string getResourceState ( resource res ) 

Required Arguments

  • res: The resource you wish to get the name of.

Returns

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

  • loaded
  • running

Example

Click to collapse [-]
Server

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

function getState( player, command, sz )
	if sz then
		local bFound = false
		local resourceTable = getResources() -- get a table of resources
	
		for resourceKey, resourceValue in ipairs( resourceTable ) do
			-- iterate through the table and output each resource's name
			local name = getResourceName( resourceValue )
			if string.lower( name ) == string.lower( sz ) then
				outputChatBox( "Resource State: " .. name .. " is currently " .. getResourceState( resourceValue ), player, 0, 0, 255 )
				bFound = true
				break
			end
		end
	
		if bFound ~= true then
			outputChatBox( "Error: No resource found named: " .. sz, player, 255, 0, 0 )
		end
	else
		outputChatBox( "Error: You did not specify a resource to check", player, 255, 0, 0 )
	end
end

addCommandHandler( "state", getState )

See Also