Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Warp Limiter (https://forums.graalonline.com/forums/showthread.php?t=68922)

Yen 09-24-2006 06:58 PM

Warp Limiter
 
I felt I should contribute something. :)
This is just a quick NPC that limits warpto rights.
For example, if you don't want those pesky LATs warping to test levels, quests, dungeons, ect. you can prevent it with this sytem.

PHP Code:

function onActionServerside() {
  switch (
params[0]) {
    case 
"toplayer":
      
this.nolevelwarp params[2];
      for (
temp.checkwarpthis.nolevelwarp) {
        if (
temp.checkwarp.starts("*")) {
          if (
findplayer(params[1]).level.pos(temp.checkwarp.substring(1)) >= 0) {
            
player.chat "Warping to this level is prohibited.";
            
setlevel2(params[3],params[4],params[5]);
            break;
          }
        }
        else {
          if (
findplayer(params[1]).level == temp.checkwarp) {
            
player.chat "Warping to this level is prohibited.";
            
setlevel2(params[3],params[4],params[5]);
            break;
          }
        }
      }
    break;
    case 
"returnfrom":
      
setlevel2(params[1],params[2],params[3]);
    break;
  }
}
//#CLIENTSIDE
function onCreated() {
  
/* Set limits here.
    this.nolevelwarp = {"level1.nw","*level",};
      prevents warping to these levels
    this.nopositionwarp = {"level1.nw","*level"};
      prevents warping to x/y in these levels
    this.includeplayers = true/false;
      if true, disables warping to other players in limited levels

      entries beginning with * will limit warping to any level with that word in it's name.
       (i.e. "*overworld" disables warping to any level that contains 'overworld' in it's name)
      all other entries will look for the exact level
       (i.e. "stafflevel.nw" disables warping to the level 'stafflevel.nw')
  */ 
  
this.nolevelwarp = {"*dungeon","yenarea.nw"};
  
this.nopositionwarp = {"*dungeon"};
  
this.includeplayers true;
  
/* Don't change anything below this line. */
}

function 
onPlayerChats() {
  if (
player.chat.starts("warpto")) {
    
this.lastx player.x;
    
this.lasty player.y;
    
this.lastlevel player.level;
    
this.tokens player.chat.tokenize();
    switch (
WarpType()) {
      case 
"toplayer":
        if (
this.includeplayerstriggerserver("gui",name,"toplayer",player.chat.substring(7),this.nolevelwarp,this.lastlevel,this.lastx,this.lasty);
      break;
      case 
"tolevel":
        for (
temp.checkwarpthis.nolevelwarp) {
          if (
temp.checkwarp.starts("*")) {
            if (
this.tokens[3].pos(temp.checkwarp.substring(1)) >= 0) {
              
player.chat "Warping to this level is prohibited.";
              
scheduleevent(.1,"ReturnLevel",this.lastx,this.lasty,this.lastlevel);
              break;
            }
          }
          else {
            if (
this.tokens[3] == temp.checkwarp) {
              
player.chat "Warping to this level is prohibited.";
              
scheduleevent(.1,"ReturnLevel",this.lastx,this.lasty,this.lastlevel);
              break;
            }
          }
        }
      break;
      case 
"toposition":
        for (
temp.checkwarpthis.nopositionwarp) {
          if (
temp.checkwarp.starts("*")) {
            if (
player.level.pos(temp.checkwarp.substring(1)) >= 0) {
              
player.chat "Warping in this level is prohibited.";
              
scheduleevent(.1,"ReturnPos",this.lastx,this.lasty);
              break;
            }
          }
          else {
            if (
player.level == temp.checkwarp) {
              
player.chat "Warping in this level is prohibited.";
              
scheduleevent(.1,"ReturnPos",this.lastx,this.lasty);
              break;
            }
          }
        }
      break;
    }
  }
}

function 
onReturnPos(rx,ry) {
  
player.rx;
  
player.ry;
}

function 
onReturnLevel(rx,ry,rl) {
  
triggerserver("gui",name,"returnfrom",rl,rx,ry);
}

function 
WarpType() {
  switch (
this.tokens.size()) {
    case 
4:
      if (
this.tokens[1] >= && this.tokens[2] >= && this.tokens[3].pos(".nw") >= 0) return "tolevel";
    case 
3:
      if (
this.tokens[1] >= && this.tokens[2] >= 0) return "toposition";
    case 
2:
      return 
"toplayer";
  }



Angel_Light 09-24-2006 07:16 PM

XD Awesome Yen.

Twinny 09-28-2006 07:03 AM

Shouldn't the no level checks all be done serverside? =S

Yen 09-28-2006 02:31 PM

It could be, but there's not much reason.
You don't expect your staff to be hacking, so if they do hack their way past the clientside check you may as well fire them.

Come to think of it, I could also do the 'warpto player' level check clientside..

ApothiX 09-29-2006 02:51 PM

Might be better if you passed the tokens as a param to WarpType instead of relying on them to be parsed before you call the function (and hope nothing else parses them in between)


All times are GMT +2. The time now is 05:17 PM.

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