Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Experiment[GS1] (https://forums.graalonline.com/forums/showthread.php?t=73525)

DustyPorViva 04-16-2007 10:18 PM

Experiment[GS1]
 
This is more of an experiment that people might want to dissect more than slap on their server, especially since it's GS1 and made completely offline with no online testing. It's a baddy I made, but I was messing around and worked it around 8 directions. It chooses it's direction while chasing the player depending on what point in the 8 directions around itself that the player is closest to. The benefit of this over going directly in the players direction is that it can maneuver around walls a bit easier because it's x and y movement are separated. Anyways, maybe it's a technique that could be used more frequently, even though the movement looks unnatural.

PHP Code:

// NPC made by Dusty

function customize() {
  
showcharacter;             // Initializes the NPC as a character
  
setcharprop #1,sword1.png; // Sword image
  
setcharprop #2,shield1.png;// Shield image
  
setcharprop #3,head19.png; // Head image
  
setcharprop #C0,black;     // Skin color
  
setcharprop #C1,black;     // Coat color
  
setcharprop #C2,black;     // Sleeve color
  
setcharprop #C3,black;     // Shoe color
  
setcharprop #C4,black;     // Belt color
  
this.walkspeed=.15;        // Wandering walk speed
  
this.chasespeed=.3;        // Chasing speed
  
swordpower=1;              // I hope it's obvious
  
shieldpower=1;             // See the above
  
hearts=3;                  // See the above
  
this.dir=int(random(0,8)); // Sets a random direction, if you want otherwise, set it 0-7
}

function 
setgani() {
  
tokenize walk walk sword hurt dead// Respective gani's for each mode in order
  
if (!strequals(#m(-1),#t(this.mode))) setcharani #t(this.mode),; // Sets the gani if the new gani is not the current one
}

if (
created) {
  
customize();
  
dontblock;
  
this.directions=8;
  
this.dirgo={0,-1,-1,-1,-1,0,-1,1,0,1,1,1,1,0,1,-1};
  
setarray this.onwall,2;

  
timeout=0.05;
}

if (
timeout) {
  
// WANDERING MODE
  
if (this.mode==0) {
    
x+=this.dirgo[this.dir*2]*this.walkspeed;
    
y+=this.dirgo[1+this.dir*2]*this.walkspeed;
    
dir=getdir(this.dirgo[this.dir*2],this.dirgo[1+this.dir*2]);
    if (
onwall(x+1.5+this.dirgo[this.dir*2],y+2+this.dirgo[1+this.dir*2])) this.dir=(this.dir-1)%8;
    
this.delta={(playerx+1.5)-(x+1.5),(playery+2)-(y+2),(this.delta[0]^2+this.delta[1]^2)^.5};
    if (
getdir(this.delta[0],this.delta[1])==dir && this.delta[2]<15this.mode=1;
  }
  
// SEEK AND DESTROY MODE
  
if (this.mode==1) {
    
this.dist=1000;
    for (
i=0;i<this.directions;i++) {
      
this.x=x+1.5+this.dirgo[i*2];
      
this.y=y+2+this.dirgo[1+i*2];
      
this.delta={(playerx+1.5)-this.x,(playery+2)-this.y,(this.delta[0]^2+this.delta[1]^2)^.5};
      if (
this.delta[2]<this.dist) {
        
this.dist=this.delta[2];
        
this.dir=i;
      }
    }
    
this.x=x+1.5+this.dirgo[this.dir*2];
    
this.y=y+2+this.dirgo[1+this.dir*2];
    
this.dist=(((playerx+1.5)-this.x)^2+((playery+2)-this.y)^2)^.5;
    if (
this.dist<=2this.mode=2;
    
dir=getdir(this.dirgo[this.dir*2],this.dirgo[1+this.dir*2]);
    
this.dx=this.dirgo[this.dir*2]*this.chasespeed;
    
this.dy=this.dirgo[1+this.dir*2]*this.chasespeed;
    
this.onwall[0]=onwall2(x+1.5+this.dx*4,y+1.25,.05,.95);
    
this.onwall[1]=onwall2(x+.75,y+2+this.dy*4,.9,.05);

    if (
this.onwall[0]==0x+=this.dx;
    if (
this.onwall[1]==0y+=this.dy;
  }
  
// ATTACK MODE
  
if (this.mode==2) {
    if (
strequals(#m(-1),idle)) this.mode=1;
  
}
  
// HURT MODE
  
if (this.mode==3) {
    if (
this.timer>0this.timer-=0.05;
    else 
this.mode=1;
  }
  
setgani();
  if (
this.mode<4timeout=0.05;
}

if (
wa**** && hearts>&& this.mode<3) {
  
hearts-=playerswordpower/2;
  if (
hearts>0) {
    
this.timer=1// Sets the timer for how long he remains immobile when hurt
    
this.mode=3;
  } else 
this.mode=4;



smirt362 04-16-2007 10:45 PM

I can't seem to hurt him.

I've even tried insulting his mother, nothing works :[

Novo 04-16-2007 11:08 PM

Put a //#CLIENTSIDE at the top?

The timeout is too small for serverside: It doesn't do any timeout.

Gambet 04-16-2007 11:09 PM

Quote:

Originally Posted by Novo (Post 1300518)
Put a //#CLIENTSIDE at the top?

The timeout is too small for serverside: It doesn't do any timeout.



It automatically adjusts if you make it too fast for serverside (it'll do the timeout, it just won't be 0.05).

middo 04-23-2007 01:07 AM

PHP Code:

if (wa**** 

what is this? :oo:

DustyPorViva 04-23-2007 01:11 AM

was . hit, dumb censor.


All times are GMT +2. The time now is 09:01 PM.

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