CreateResource: Difference between revisions
No edit summary |
m (→See Also) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server function}} | {{Server function}} | ||
This function creates an empty resource. | This function creates an new, empty resource. This creates a directory matching the name you specify on disk, then creates an empty meta.xml file with a <meta> element in it. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
resource createResource ( string resourceName ) | resource createResource ( string resourceName [, string organizationalDir ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[Resource]]}} | |||
===Required Arguments=== | |||
*'''resourceName:''' The name of the new resource. This should be a valid file name. It's recommended that you do not have spaces or non-ASCII characters in resource names. | |||
=== | ===Optional Arguments=== | ||
*''' | {{OptionalArg}} | ||
* '''organizationalDir''': A string containing the path where the resource should be created (e.g. "[gamemodes]/[amx]"). | |||
===Returns=== | ===Returns=== | ||
Returns '' | Returns the [[resource]] element of the new resource if successful, ''false'' otherwise. This could fail if the resource name already is in use, if a directory already exists with the name you've specified (but this isn't a valid resource) or if the name you specify isn't valid. It could also fail if the disk was full or for other similar reasons. | ||
==Example== | ==Example== | ||
This | This example creates a new resource named what the player specified. The command is "/new-resource <name>". | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
--add | 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|server}} | ||
Latest revision as of 22:46, 6 September 2024
This function creates an new, empty resource. This creates a directory matching the name you specify on disk, then creates an empty meta.xml file with a <meta> element in it.
Syntax
resource createResource ( string resourceName [, string organizationalDir ] )
OOP Syntax Help! I don't understand this!
- Method: Resource(...)
Required Arguments
- resourceName: The name of the new resource. This should be a valid file name. It's recommended that you do not have spaces or non-ASCII characters in resource names.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- organizationalDir: A string containing the path where the resource should be created (e.g. "[gamemodes]/[amx]").
Returns
Returns the resource element of the new resource if successful, false otherwise. This could fail if the resource name already is in use, if a directory already exists with the name you've specified (but this isn't a valid resource) or if the name you specify isn't valid. It could also fail if the disk was full or for other similar reasons.
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
- addResourceConfig
- addResourceMap
- callRemote
- copyResource
- createResource
- deleteResource
- getResourceACLRequests
- getResourceInfo
- getResourceLastStartTime
- getResourceLoadFailureReason
- getResourceLoadTime
- getResourceMapRootElement
- getResourceOrganizationalPath
- getResources
- isResourceArchived
- isResourceProtected
- refreshResources
- removeResourceFile
- renameResource
- restartResource
- setResourceInfo
- startResource
- stopResource
- updateResourceACLRequest
- Shared
- abortRemoteRequest
- call
- fetchRemote
- getResourceConfig
- getResourceDynamicElementRoot
- getResourceExportedFunctions
- getResourceFromName
- getResourceName
- getResourceRootElement
- getResourceState
- getThisResource
- getRemoteRequests
- getRemoteRequestInfo