Quote:
Originally Posted by Hezzy002
There are no "consequences", though.. The server is experiencing no more strain than if you were to use attrs, they're handled in exactly the same way, just natively in <insert language Graal's servers are written in> instead of GS2, and considering that it hardly uses any CPU resources, it would be bound at most by the lookup speed of the server's drives and so would attrs..
Other than that, the syntax is better than attr's, it requires less work to get it to be self-documenting, it's easier for the scripter, it doesn't require casting to a string to work correctly with things like arrays, there's no 223 character limit, and you can use more than 30 should you desire to. I don't see any of the consequences you're talking about, period.
I mean, I could be wrong, what consequences are you talking about?
|
The syncing is automatically done by the server, and doesn't require you to sync the data with everyone. There is a server option that allows you to do that however.
The limitations of using an ATTR can be avoided with a proper design, and writing functions to retrieve and parse the information from it.
If the data is too large, it should be requested as needed not loaded ahead for convenience.
Class: player_shared_data
PHP Code:
//#CLIENTSIDE
function setHealth(hp, mp, maxhp, maxmp) {
// Store health in attribute
player.attr[4] = hp SPC maxhp SPC mp SPC maxmp;
}
// Retrieve HP from Attr
function getHP(pl) {
return pl.attr[4].tokenize()[0];
}
// Retrieve MP from Attr
function getMP(pl) {
return pl.attr[4].tokenize()[2];
}
// Retrieve Stats from Attr
// Store Stats in Object for Easier Access
function updateStats(pl) {
temp.tokens = pl.attr[4].tokenize();
if (temp.tokens.size() == 4) {
pl.hp = temp.tokens[0];
pl.maxhp = temp.tokens[1];
pl.mp = temp.tokens[2];
pl.maxmp = temp.tokens[3];
}
}
Usage:
PHP Code:
this.join("player_shared_data");
//#CLIENTSIDE
function onCreated() {
// Give Random Health to People
temp.hp = int(random(0, 5));
temp.maxhp = 5;
temp.mp = int(random(0, 5));
temp.maxhp = 5;
setHealth(temp.hp, temp.mp, temp.maxhp, temp.maxmp);
// Wait a sec...
sleep(1);
// Loop through Players
for (temp.pl: players) {
// Update Player Health Variables
updateStats(temp.pl);
// Show HP and MP on Players
temp.pl.chat = format("HP: %d/%d MP: %d/%d", temp.pl.hp, temp.pl.maxhp, temp.pl.mp, temp.pl.maxmp);
}
}
Other scripters then just need to join the class to the script they need it in, and call the functions you defined. You can then easily document in that script what attribute is being used for what and how.
Code that's documented is much more valuable to other scripters than code that is just written a way that self-documents itself.
If the server can do it on it's own, let the server do it for you instead of re-creating the wheel.