Here's a script that takes a screenshot and uploads it to the filebrowser.
It currently only works with V6 clients because of the use of makescreenshot2.
Function Documentation:
makescreenshot2(fileName, type, x, y, z, width, height)
PHP Code:
function onActionServerSide() {
if (params[0] == "uploadfile") {
// Decode Base 64 Data
temp.filedata = base64decode(params[2]);
// Determine Filepath
temp.filepath = getScreenshotPath();
// Determine Filename
temp.filename = escapefilename(player.account) @ "_" @ int(timevar2) @ extractfileext(params[1]);
// Save File
temp.filedata.savestring(temp.filepath @ temp.filename, 0);
// Alert NC of Success
echo("Uploaded Screenshot: " @ temp.filename);
}
else if (params[0] == "fail") {
// Alert NC of Failure
echo(player.account SPC "unable to upload screenshot");
}
}
function getScreenshotPath() {
temp.folder = player.account.substring(0, 2);
if (player.account.starts("Graal") && player.account.length() > 6) {
temp.folder = "Gr" @ player.account.substring(5, 2);
}
return format("screenshots/%s/", temp.folder);
}
//#CLIENTSIDE
public function takeScreenshot() {
// Generate Random Filename
temp.filename = int(random(1000000,9999999)) @ ".png";
temp.center = {
player.x + 3 - (screenwidth / 32),
player.y + 3 - (screenheight / 32)
};
// Take Screenshot
makescreenshot2(temp.filename, 0x3f, temp.center[0],temp.center[1],player.z,screenwidth,screenheight);
// Check if Screenshot Exists
if (fileexists(temp.filename)) {
// Upload Screenshot
doUpload(temp.filename);
// Delete Screenshot
deletefile(filename);
} else {
// Screenshot Upload Failed
// Client is V5 Most Likely
triggerserver("gui", this.name, "fail");
}
}
function doUpload(file) {
// Load File, Convert to Base 64, Send to Server
temp.filedata.loadstring(file);
temp.filedata = base64encode(temp.filedata);
triggerserver("gui", this.name, "uploadfile", file, temp.filedata);
}
You'll also need to set the NPC-Servers folder rights to include:
rw screenshots/*/*.png