CopyResource: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server function}} This function copies a specified resource with a new name. ==Syntax== <syntaxhighlight lang="lua"> bool copyResource ( resource theResource, string newResourceName ) ...)
 
(→‎Example: added)
Line 17: Line 17:
==Example==
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--TODO
-- This script can backup your resource with a easy command! /backupresource [resourcename]
function backupResource (player,command,resourcetobackup) -- start the function
  if (resourcetobackup) and (getResourceFromName(resourcetobackup)) then -- check if the resource is exist
    copyResource (getResourceFromName(resourcetobackup),resourcetobackup .. "_backup") -- copy the resource and give it the name [resource]_backup
    outputChatBox ("Resource " .. resourcetobackup .. " succesfully backed up!",player,255,0,0,false) -- say it's OK!
  else -- if it isn't exist
    outputChatBox ("Resource can't be backed up! (don't forget the parameters!)",player,255,0,0,false) -- say it isn't exist!
  end
end
addCommandHandler ("backupresource",backupResouce) -- add command
</syntaxhighlight>
</syntaxhighlight>



Revision as of 15:13, 5 May 2010

This function copies a specified resource with a new name.

Syntax

bool copyResource ( resource theResource, string newResourceName )

Required Arguments

  • theResource: the resource which is going to be copied
  • newResourceName: the name that the copied resource will receive

Returns

Returns true if the resource was copied successfully, false otherwise.

Example

-- This script can backup your resource with a easy command! /backupresource [resourcename]
function backupResource (player,command,resourcetobackup) -- start the function
  if (resourcetobackup) and (getResourceFromName(resourcetobackup)) then -- check if the resource is exist
    copyResource (getResourceFromName(resourcetobackup),resourcetobackup .. "_backup") -- copy the resource and give it the name [resource]_backup
    outputChatBox ("Resource " .. resourcetobackup .. " succesfully backed up!",player,255,0,0,false) -- say it's OK!
  else -- if it isn't exist
    outputChatBox ("Resource can't be backed up! (don't forget the parameters!)",player,255,0,0,false) -- say it isn't exist!
  end
end
addCommandHandler ("backupresource",backupResouce) -- add command

See Also