Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   shorter way? (https://forums.graalonline.com/forums/showthread.php?t=76269)

Angel_Light 08-14-2007 04:12 AM

shorter way?
 
is there a shorter way to do this?

PHP Code:

  if ( player.dir == 0) {
    if ( 
tiletype( int( this.x), int(this.y-1)) != 22)
      goto( 
int(this.x), int(this.y-1));
  }
  
  else if ( 
player.dir == 1) {
    if ( 
tiletype( int(this.x-1), int(this.y)) != 22)
      goto( 
int(this.x-1), int(this.y));
  }
  
  else if ( 
player.dir == 2) {
    if ( 
tiletype( int(this.x), int(this.y+1)) != 22)
      goto( 
int(this.x), int(this.y+1));
  }
  
  else if ( 
player.dir == 3) {
    if ( 
tiletype( int(this.x+1), int(this.y)) != 22)
      goto( 
int(this.x+1), int(this.y));
  } 


DustyPorViva 08-14-2007 04:19 AM

Yes, with vecx/y :)

PHP Code:

for (i=0;i<4;i++) {
  if (
player.dir==i && tiletype(int(this.x+vecx(player.dir)), int(this.y+vecx(player.dir))) != 22) {
     goto(
int(this.x+vecx(player.dir)), int(this.y+vecx(player.dir)))
  }
} 


Angel_Light 08-14-2007 04:35 AM

Your amazing ^^

EDIT : Works great except it moves in diagonals XD fix?

Chompy 08-14-2007 04:31 PM

PHP Code:

for(temp.i = 0; i < 4; i ++) {
  if (
player.dir == i) {
    
temp.tx = int(this.x + (i==1?-1:(i==3?1:0));
    
temp.ty = int(this.y + (i==0?-1:(i==2?1:0));
    if (
tiletype(tx, ty) != 22) {
      goto(
tx, ty);
    }
  }
} 

PHP Code:

temp.a = {
  { 
0,-1},
  {-
1, 0},
  { 
0, 1},
  { 
1, 0}
};
temp.b = player.dir;
if (
tiletype(int(this.x + a[b][0], this.y + a[b][1])) != 22) {
  goto(
int(this.x + a[b][0], this.y + a[b][1]);
} 

dunno if they work (no vecx/y used ;o)

xXziroXx 08-14-2007 05:25 PM

PHP Code:

for (i=0;i<4;i++) {
  if (
player.dir==i && tiletype(int(this.x+vecy(player.dir)), int(this.y+vecx(player.dir))) != 22) {
     goto(
int(this.x+vecy(player.dir)), int(this.y+vecx(player.dir)))
  }
} 


coreys 08-14-2007 07:18 PM

lol
everyone has their own way.

Chompy 08-14-2007 08:27 PM

PHP Code:

for (i=0;i<4;i++) {
  if (
player.dir == i && tiletype(int(this.x+vecy(i)), int(this.y+vecx(i)) != 22)
     goto(
int(this.x+vecy(i)), int(this.y+vecx(i)));
} 

wee..?

zokemon 08-15-2007 01:06 AM

I fail to see the need for a loop here...
PHP Code:

if (tiletype(int(this.x + vecx(player.dir)), int(this.y + vecy(player.dir))) != 22)
  goto(
int(this.x + vecx(player.dir)), int(this.y + vecy(player.dir)); 


Chompy 08-15-2007 01:37 AM

Zero comes and saves the cpu/lag time again!

DustyPorViva 08-15-2007 02:10 AM

Quote:

Originally Posted by zokemon (Post 1340092)
I fail to see the need for a loop here...
PHP Code:

if (tiletype(int(this.x + vecx(player.dir)), int(this.y + vecy(player.dir))) != 22)
  goto(
int(this.x + vecx(player.dir)), int(this.y + vecy(player.dir)); 


Hmm, very good point! I completely missed that.

zokemon 08-15-2007 08:28 AM

:p


All times are GMT +2. The time now is 10:18 PM.

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