GetResourceState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Improved the example)
Line 27: Line 27:
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>''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function getState( player, command, sz )
function getState( player, command, resourceName )
if sz then
if resourceName then
local bFound = false
local resource = getResourceFromName( resourceName )
local resourceTable = getResources() -- get a table of resources
if resource then
outputChatBox( "Resource State: " .. resourceName .. " is currently " .. getResourceState( resource ) .. ".", player, 0, 0, 255 )
for resourceKey, resourceValue in ipairs( resourceTable ) do
else
-- iterate through the table and output each resource's name
outputChatBox( "Error: No resource with name " .. resourceName .. " exists.", player, 255, 0, 0 )
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
end
else
else
outputChatBox( "Error: You did not specify a resource to check", player, 255, 0, 0 )
outputChatBox( "Syntax: " .. command .. " [resource name]", player, 255, 0, 0 )
end
end
end
end

Revision as of 14:56, 7 May 2010

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, resourceName )
	if resourceName then
		local resource = getResourceFromName( resourceName )
		if resource then
			outputChatBox( "Resource State: " .. resourceName .. " is currently " .. getResourceState( resource ) .. ".", player, 0, 0, 255 )
		else
			outputChatBox( "Error: No resource with name " .. resourceName .. " exists.", player, 255, 0, 0 )
		end
	else
		outputChatBox( "Syntax: " .. command .. " [resource name]", player, 255, 0, 0 )
	end
end

addCommandHandler( "state", getState )

See Also