Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   jQuery-like chained standard framework? (https://forums.graalonline.com/forums/showthread.php?t=86505)

Robin 06-24-2009 02:16 AM

jQuery-like chained standard framework?
 
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.0allplayerscounti++)
      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(lvldxdy) {
  
triggerserver("gui""-gQuery""warp"this._playerlvl, {dxdy});
  return 
this;
}

function 
nick(str) {
  
triggerserver("gui""-gQuery""nick"this._playerstr);
  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"3030)
     .
nick("jailed");
  } 

It would even work clientside

PHP Code:

  //#CLIENTSIDE
  // Sends a user to jail
  
function onCreated() {
    
join("gquery");
    
g("Paradoxical")
     .
warp("jail.nw"3030)
     .
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!

xXziroXx 06-24-2009 02:25 AM

That is one horrible syntax to look at.

Robin 06-24-2009 02:29 AM

Quote:

Originally Posted by Robin (Post 1501255)
constructive comments and future improvements

Quote:

Originally Posted by xXziroXx (Post 1501258)
That is one horrible syntax to look at.

Did I miss a meeting? :(

xXziroXx 06-24-2009 02:40 AM

Quote:

Originally Posted by Robin (Post 1501259)
Did I miss a meeting? :(

I fail to see how I weren't being constructive in my last post.

Robin 06-24-2009 02:54 AM

Quote:

Originally Posted by xXziroXx (Post 1501261)
I fail to see how I weren't being constructive in my last post.

Saying it has a horrible syntax without giving a reason is failing to be constructive.

It is modeled on the jQuery syntax:

PHP Code:

  jQuery('blockquote').each(function(el) {
    
alert(jQuery(this).text());
  }); 

I was thinking of implementing an each function

PHP Code:

  g(allplayers).in("osl.nw").each(function(pl) {
    
g(pl)
     .
warp("jail.nw"3030)
     .
nick("jailed for lack of constructive critisicm");
  }); 

I'm not sure if it would work like that but it looks like it might =o

Actually, keep up the mean Ziro, I'm getting some good ideas :O

Seich 06-24-2009 07:46 AM

That's actually a pretty nice idea and I like how it looks. My only idea was the .each thing you already thought of >_< I will try to come up with something new though.

Paradoxical 06-26-2009 01:51 AM

1 Attachment(s)
Aaaaaaand, drumroll please...

I've redone and documented the script, so me and Robin are pleased to give you gQuery 2.0!

Simply open the .gs2 file in notepad and paste it in the class "gquery" on your server, use the weapon at the start of this post to interface with it.

The documentation is done by doxygen, and I have included the html for those who want it on their hard-drive, simply run the index.html in the html folder of the .zip to view it.

For those who don't want the documentation as a hard copy, delete it after extracting the .zip, I'll be editing this post in a few minutes to include a link to it hosted by Robin.

Robin 06-26-2009 02:40 AM

That's absolutely awesome! =o <3


All times are GMT +2. The time now is 01:04 AM.

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