GetResourceState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 6: Line 6:
<!-- 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 -->
<!-- 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 getResourceState ( resource res )  
string getResourceState ( resource theResource )  
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''res:''' The resource you wish to get the name of.
*'''theResource:''' The resource you wish to get the name of.


===Returns===
===Returns===

Revision as of 13:36, 5 September 2008

This function returns the state of a given resource

Syntax

string getResourceState ( resource theResource ) 

Required Arguments

  • theResource: 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