Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-24-2009, 02:16 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
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!
__________________

Reply With Quote
  #2  
Old 06-24-2009, 02:25 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
That is one horrible syntax to look at.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 06-24-2009, 02:29 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Quote:
Originally Posted by Robin View Post
constructive comments and future improvements
Quote:
Originally Posted by xXziroXx View Post
That is one horrible syntax to look at.
Did I miss a meeting?
__________________

Reply With Quote
  #4  
Old 06-24-2009, 02:40 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Robin View Post
Did I miss a meeting?
I fail to see how I weren't being constructive in my last post.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #5  
Old 06-24-2009, 02:54 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Quote:
Originally Posted by xXziroXx View Post
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
__________________

Reply With Quote
  #6  
Old 06-24-2009, 07:46 AM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich
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.
Reply With Quote
  #7  
Old 06-26-2009, 01:51 AM
Paradoxical Paradoxical is offline
Professional Programmer
Join Date: Jun 2009
Posts: 10
Paradoxical is on a distinguished road
Send a message via AIM to Paradoxical Send a message via MSN to Paradoxical
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.
Attached Files
File Type: zip gQuery.zip (30.4 KB, 131 views)
__________________
-Zachary Trant


"In the middle of difficulty, lies oppertunity."
-Albert Einstein
Reply With Quote
  #8  
Old 06-26-2009, 02:40 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
That's absolutely awesome! =o <3
__________________

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 09:26 PM.


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