Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-16-2007, 10:18 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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;

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 09:18 AM.


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