Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 04-16-2007, 10:45 PM
smirt362 smirt362 is offline
Tee Hee
smirt362's Avatar
Join Date: Feb 2005
Location: Texas
Posts: 2,101
smirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant future
Send a message via AIM to smirt362 Send a message via MSN to smirt362
I can't seem to hurt him.

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

Don Hertzfeldt <3

Last edited by smirt362; 04-16-2007 at 10:58 PM..
Reply With Quote
  #3  
Old 04-16-2007, 11:08 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Put a //#CLIENTSIDE at the top?

The timeout is too small for serverside: It doesn't do any timeout.
Reply With Quote
  #4  
Old 04-16-2007, 11:09 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Novo View Post
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).
Reply With Quote
  #5  
Old 04-23-2007, 01:07 AM
middo middo is offline
VHE Monkey
middo's Avatar
Join Date: Aug 2002
Location: California
Posts: 327
middo is on a distinguished road
Send a message via AIM to middo
PHP Code:
if (wa**** 
what is this?
Reply With Quote
  #6  
Old 04-23-2007, 01:11 AM
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
was . hit, dumb censor.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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


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