GetResourceState: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(Added a description and example. May need a list of returns) |
||
Line 2: | Line 2: | ||
__NOTOC__ | __NOTOC__ | ||
<!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | ||
This | This function returns the state of a given reesource | ||
==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 --> | <!-- 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 | string getResourceState ( resource res ) | ||
</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 --> | <!-- 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. | ||
===Returns=== | ===Returns=== | ||
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | <!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | ||
Returns | Returns a string with the resource state in it. <br \> | ||
- false on fail | - false on fail | ||
==Example== | ==Example== | ||
<section class="server" name="Server" show="true"> | |||
<!-- Explain what the example is in a single sentance --> | <!-- Explain what the example is in a single sentance --> | ||
This example | 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 --> | <!-- 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 ) | ||
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 ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{Resource functions}} | {{Resource functions}} | ||
[[Category:Incomplete]] | --[[Category:Incomplete]] |
Revision as of 00:59, 7 January 2008
This function returns the state of a given reesource
Syntax
string getResourceState ( resource res )
Required Arguments
- res: The resource you wish to get the name of.
Returns
Returns a string with the resource state in it.
- false on fail
Example
Click to collapse [-]
ServerThis 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
- abortRemoteRequest
- call
- fetchRemote
- getResourceConfig
- getResourceDynamicElementRoot
- getResourceExportedFunctions
- getResourceFromName
- getResourceName
- getResourceRootElement
- getResourceState
- getThisResource
- getRemoteRequests
- getRemoteRequestInfo
--