Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 01:02 PM.


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