Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Offline Player Manipulation (https://forums.graalonline.com/forums/showthread.php?t=134257294)

fowlplay4 12-14-2009 02:33 AM

Offline Player Manipulation
 
Allows you to view and edit variables and the values of offline players while providing compatibility methods to edit them if they're already online.

PHP Code:

function findplayer2(acct) {
  
// Check if Player Online
  
temp.obj findplayer(acct);
  if (
temp.obj.level == NULL) {
    
// Create Player Object
    
temp.obj = new TServerPlayer(@acct);
  }
  return 
temp.obj;
}

function 
getPlayerVar(acct, var) {
  
// Get Player Object
  
temp.obj findplayer2(acct);
  
temp.val makevar("temp.obj." @ var);
  
// Destroy Player Object
  
if (temp.obj.level == NULLtemp.obj.destroy();
  
// Return Value
  
return temp.val;
}

function 
editPlayerVar(acct, var, value) {
  
// Get Player Object
  
temp.obj findplayer2(acct);
  
// Check for Array of Variables and Values
  
if (var.type() == && var.size() == value.size()) {
    
// Change Values
    
for (temp.v: var) {
      
makevar("temp.obj." @ var) = value[0+temp.i];
      
temp.i++;
    }
  } else {
    
// Change Single Value
    
makevar("temp.obj." @ var) = value;
  }
  
// Save Account File
  
if (temp.obj.level == NULL) {
    
temp.obj.saveaccount();
    
temp.obj.destroy();
  }


Some example usage..

PHP Code:

function onCreated() {
  
// Accessing Player Variables
  
echo(findplayer2("fowlplay4").account); // Echos fowlplay4
  
echo(getPlayerVar("fowlplay4""account")); // Echos -2144485044 on Zodiac
  // Multiple Variable Value Edit
  
editPlayerVar("fowlplay4", {"client.a""client.b"}, {12});
  
// Single Variable Value Edit
  
editPlayerVar("fowlplay4""client.c"3);


Important Note when using findplayer2:

Quote:

Originally Posted by Stefan (Post 1544225)
You need to call destroy() on the player object after you have used it, when you do new TServerPlayer() it is not automatically destroyed like TStaticVars()

Enjoy! :)

cbk1994 12-14-2009 03:19 AM

I didn't know you could edit variables of offline players, this is quite awesome. Nice work :).

Tigairius 12-14-2009 03:34 AM

Quote:

Originally Posted by cbk1994 (Post 1544213)
I didn't know you could edit variables of offline players, this is quite awesome. Nice work :).

I thought I explained that to you ages ago.

Anyways, nice job Jerret, it's a good contribution.

fowlplay4 12-14-2009 03:53 AM

Quote:

Originally Posted by cbk1994 (Post 1544213)
I didn't know you could edit variables of offline players, this is quite awesome. Nice work :).

Found the saveaccount function today in the new serverside_scriptfunctions.txt

You can even join your classes to it, treat it like an online object, and save it when you're done with it too. (No more trivial edits with /open on scammer's accounts :3)

Admins 12-14-2009 03:54 AM

Nice script.
One problem which needs to be solved: you need to call destroy() on the player object after you have used it, when you do new TServerPlayer() it is not automatically destroyed like TStaticVars()

fowlplay4 12-14-2009 03:58 AM

Quote:

Originally Posted by Stefan (Post 1544225)
Nice script.
One problem which needs to be solved: you need to call destroy() on the player object after you have used it, when you do new TServerPlayer() it is not automatically destroyed like TStaticVars()

Edited my functions, they destroy properly now.

WhiteDragon 12-14-2009 04:36 AM

Nice. You've been cranking out sweet scripts for some time now! Thanks.

coreys 12-14-2009 05:30 AM

Ooo, nice, I didn't know you could manipulate players offline either, will definitely be using this.

fowlplay4 07-24-2012 11:42 PM

Stefan added a findplayer2 (which now accepts both account and community names) function, which kind of breaks my code snippet.

I've since used this code instead of my findplayer2 function:

PHP Code:

function onCreated() {
  
// Load Player
  
temp.pl findplayer(acct);
  
temp.offline temp.pl == NULL;
  
temp.pl temp.offline ? new TServerPlayer(@acct) : temp.pl;
  
// Manipulate player object...
  // Save and destroy
  
if (temp.offline) {
    
temp.pl.saveaccount();
    
temp.pl.destroy();
  }



Astram 07-27-2012 02:45 AM

How would I use this to remove an offline players weapon? I can't figure out how.

fowlplay4 07-27-2012 03:02 AM

Quote:

Originally Posted by Astram (Post 1700200)
How would I use this to remove an offline players weapon? I can't figure out how.

After you have the player loaded (assuming using temp.pl for the player object):

temp.pl.removeweapon("Weapon Name");

Astram 07-27-2012 11:33 PM

Quote:

Originally Posted by fowlplay4 (Post 1700201)
After you have the player loaded (assuming using temp.pl for the player object):

temp.pl.removeweapon("Weapon Name");

Sorry for asking, but I don't really understand your main script too much. If you could explain how I could use this in removing a players weapon I'd be glad. Basically I just don't know where to put this chunk of script :P.

fowlplay4 07-28-2012 12:04 AM

Quote:

Originally Posted by Astram (Post 1700271)
Sorry for asking, but I don't really understand your main script too much. If you could explain how I could use this in removing a players weapon I'd be glad. Basically I just don't know where to put this chunk of script :P.

After the player object is found/loaded:

PHP Code:

function onCreated() { 
  
// Load Player
  
temp.acct "fowlplay4";
  
temp.pl findplayer(acct); 
  
temp.offline temp.pl == NULL
  
temp.pl temp.offline ? new TServerPlayer(@acct) : temp.pl
  
// Manipulate player object... 
  
temp.pl.removeweapon("Weapon Name");
  
// Save and destroy 
  
if (temp.offline) { 
    
temp.pl.saveaccount(); 
    
temp.pl.destroy(); 
  } 




All times are GMT +2. The time now is 08:14 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.