Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-14-2009, 02:33 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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 View Post
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!
__________________
Quote:

Last edited by fowlplay4; 12-14-2009 at 04:00 AM..
Reply With Quote
  #2  
Old 12-14-2009, 03:19 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
I didn't know you could edit variables of offline players, this is quite awesome. Nice work .
__________________
Reply With Quote
  #3  
Old 12-14-2009, 03:34 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by cbk1994 View Post
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #4  
Old 12-14-2009, 03:53 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by cbk1994 View Post
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)
__________________
Quote:
Reply With Quote
  #5  
Old 12-14-2009, 03:54 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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()
Reply With Quote
  #6  
Old 12-14-2009, 03:58 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Stefan View Post
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.
__________________
Quote:

Last edited by fowlplay4; 12-14-2009 at 04:12 AM..
Reply With Quote
  #7  
Old 12-14-2009, 04:36 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Nice. You've been cranking out sweet scripts for some time now! Thanks.
Reply With Quote
  #8  
Old 12-14-2009, 05:30 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Ooo, nice, I didn't know you could manipulate players offline either, will definitely be using this.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #9  
Old 07-24-2012, 11:42 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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();
  }

__________________
Quote:
Reply With Quote
  #10  
Old 07-27-2012, 02:45 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
How would I use this to remove an offline players weapon? I can't figure out how.
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #11  
Old 07-27-2012, 03:02 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Astram View Post
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");
__________________
Quote:
Reply With Quote
  #12  
Old 07-27-2012, 11:33 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Quote:
Originally Posted by fowlplay4 View Post
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.
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #13  
Old 07-28-2012, 12:04 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Astram View Post
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(); 
  } 

__________________
Quote:
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:53 PM.


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