Hey peeps;
I was thinking today that something like this may be fun. A little mix of jQuery and GS2.
The idea is to have a standard framework that would make GS2 more accessible to the newer scripters around here, and at the same time, introduce a level of standards to the way things are done with GScript.
Class: gquery
PHP Code:
// gQuery
// By Robin
// June 2009
function onCreated() {
this._player = NULL;
}
public function g(pl) {
this.find(pl);
return this;
}
public function find(pl) {
temp.plr = findplayerbycommunityname(pl);
if (plr == NULL)
for (temp.i = 0; i < allplayerscount; i++)
if (allplayers[i].nick == pl && allplayers[i].level.length() > 0)
plr = allplayers[i];
if (plr == NULL)
this.log("Player" SPC pl SPC "not found");
else
this._player = plr;
return this;
}
public function nick(str) {
if (this._player != NULL)
this._player.nick = str;
else
this.log("Please select player");
return this;
}
public function warp(dlvl,dx,dy) {
if (this._player != NULL)
this._player.setlevel2(dlvl,dx,dy);
else
this.log("Please select player");
return this;
}
function log(msg) {
echo("gQuery: " + msg);
}
//#CLIENTSIDE
function g(pl) {
this._player = pl;
return this;
}
function warp(lvl, dx, dy) {
triggerserver("gui", "-gQuery", "warp", this._player, lvl, {dx, dy});
return this;
}
function nick(str) {
triggerserver("gui", "-gQuery", "nick", this._player, str);
return this;
}
Weapon: -gQuery
PHP Code:
// gQuery
// By Robin
// June 2009
function onCreated() {
join("gquery");
}
function onActionServerside() {
switch (params[0]) {
case "warp":
g(params[1])
.warp(params[2], params[3][0], params[3][1]);
break;
case "nick":
g(params[1])
.nick(params[2]);
break;
}
}
Here's a real world example:
PHP Code:
// Sends a user to jail
function onCreated() {
join("gquery");
g("Paradoxical")
.warp("jail.nw", 30, 30)
.nick("jailed");
}
It would even work clientside
PHP Code:
//#CLIENTSIDE
// Sends a user to jail
function onCreated() {
join("gquery");
g("Paradoxical")
.warp("jail.nw", 30, 30)
.nick("jailed");
}
No script changes and it works both ways!
Really what I need is constructive comments and future improvements, ideas and bug reports. I think this could be good for the newer scripters to get a grips with working with a programming language and help with the great transition from clientside to serverside.
So, thoughts, comments, flames, bring it on!