GetResourceState: Difference between revisions

From Multi Theft Auto: Wiki
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 fake function is for use with blah & blah and does blahblahblabhalbhl
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 getResourceStart ( resource res )  
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 -->
*'''argumentName:''' description
*'''res:''' The resource you wish to get the name of.
 
<!-- 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 -->
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if blah, ''false'' otherwise. <br \>
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 does...
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">
--This line does...
function getState( player, command, sz )
blabhalbalhb --abababa
if sz then
--This line does this...
local bFound = false
mooo
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]] -- leave this unless you complete the function
--[[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 [-]
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


--