CreateResource: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Added an example.)
Line 15: Line 15:


==Example==  
==Example==  
This page does not have an example
This example creates a new resource named what the player specified. The command is "/new-resource <name>".
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--add an example here.
function createNewResource ( source, command, resourceName ) -- Define the source and add a resourceName argument.
if ( resourceName ) then -- Check if they entered a resource name, and if they did...
local resourceName = tostring ( resourceName ) -- Convert the name into a string.
local newResource = createResource ( resourceName ) -- Create the new resource.
if ( newResource ) then -- Check if the resource has been created, if so then...
outputChatBox ( "New resource created succcessfully.", source, 255, 0, 0 ) -- Output it's done.
else -- If the resource wasn't made successfully then...
outputChatBox ( "An un-expected error occured.", source, 255, 0, 0 ) -- Output it failed.
end
else -- If they didn't enter a resource name...
outputChatBox ( "Please specify a name for your new resource.", source, 255, 0, 0 ) -- Tell them to specify a name.
end
end
addCommandHandler ( "new-resource", createNewResource ) -- Make it trigger when somebody types "/new-resource <name>".
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Resource_functions}}
{{Resource_functions}}
[[Category:Needs_Example]]

Revision as of 20:33, 23 February 2010

This function creates an empty resource.

Syntax

resource createResource ( string resourceName )

Required Arguments

  • resourceName: The name of the new resource.

Returns

Returns true if the resource has been created successfully, false otherwise.

Example

This example creates a new resource named what the player specified. The command is "/new-resource <name>".

function createNewResource ( source, command, resourceName ) -- Define the source and add a resourceName argument.
	if ( resourceName ) then -- Check if they entered a resource name, and if they did...
		local resourceName = tostring ( resourceName ) -- Convert the name into a string.
		local newResource = createResource ( resourceName ) -- Create the new resource.
			if ( newResource ) then -- Check if the resource has been created, if so then...
				outputChatBox ( "New resource created succcessfully.", source, 255, 0, 0 ) -- Output it's done.
			else -- If the resource wasn't made successfully then...
				outputChatBox ( "An un-expected error occured.", source, 255, 0, 0 ) -- Output it failed.
			end
	else -- If they didn't enter a resource name...
		outputChatBox ( "Please specify a name for your new resource.", source, 255, 0, 0 ) -- Tell them to specify a name.
	end
end
addCommandHandler ( "new-resource", createNewResource ) -- Make it trigger when somebody types "/new-resource <name>".

See Also