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 == NULL) temp.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() == 3 && 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"}, {1, 2});
// Single Variable Value Edit
editPlayerVar("fowlplay4", "client.c", 3);
}
Important Note when using findplayer2:
Quote:
Originally Posted by Stefan
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!