Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-22-2006, 11:32 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
NPC baddy

I'm making an NPC baddy again. This time, I am using the classic system, so it's a bit different. Anyway, I'm having trouble damaging it. So far, the only sure fire way to do it is to shoot him. I originally didn't put the wa****, wasshot, etc in the timeout, but I decided to try it to make it easier to hit him.
No luck.
Any ideas/suggestions? (other than taking the sleep() command out of when the baddy is hit, that wouldn't change this, and I do plan to take it out and replace it with a timeout once I have everything working right. I also plan to add some better AI).
PHP Code:
// NPC Enemy made by Excalibur
//Ceverous, first fight
//#CLIENTSIDE
function onCreated()
{
  
// Character attributes
  
showcharacter();
  
headimg "darkdemon13-head4.mng";
  
colors[0] = "orange";
  
colors[1] = "gray";
  
colors[2] = "gray";
  
colors[3] = "black";
  
colors[0] = "black";
  
nick "?????";
  
shieldimg "darkman-shield.gif";
  
bodyimg "bodysage2.mng";
  
swordimg "dronan-sword.gif";
  
shieldpower 1;
  
swordpower 2;
  
hearts 5;
  
dir 2;
  
setcharani("idle",NULL);
  
//position
  
x+=.5;
  
//sight radius
  
this.sightradius 10;
  
//speed
  
this.speed .6;
  
//cut scene
  
setani("idle",NULL);
  
freezeplayer(3);
  
player.chat "It's been YOU!";
  
sleep(.1);
  
chat "Ha ha ha! Welcome to the party!";
  
//timeout
  
setTimer(.05);
}
function 
onTimeout()
{
  function 
onWa****()
  {
    
this.mode 2;
    
this.damage player.swordpower/2;
  }
  function 
onWasShot()
  {
    
this.mode 2;
    
this.damage clientr.bowpower/2;
  }
  function 
onExploded()
  {
    
this.mode 2;
    
this.damage clientr.bombpower/2;
  }
  function 
onWaspelt()
  {
    
setcharani("sword",NULL);
    
this.mode 2;
    
this.damage=0;
  }
  if(
this.mode 0)
  {
    
setcharani("idle",NULL);
    
setTimer(.05);
  }
  
/*Modes
  *0)Idle
  *1)Chasing/attacking
  *2)Hurt
  *3)Dead
  **********/
  
if(hearts<=0)
  {
    
hearts 0;
    
this.mode 3;
  }
  if((
abs(player.x-x)^2+abs(player.y-y)^2)^.5<=this.sightradius)
  {
    
this.mode 1;
  }
  if(
this.mode==1)
  {
    
setcharani("walk",NULL);
    if(
abs(player.x-x)>abs(player.y-y))
    {
      
//direction should be 1 or 3
      
if(player.x>x)
      {
        
dir 3;
        
//move
        
if(!onwall(x+this.speed,y+.5) && !onwall(x+this.speed,y+2.5))
        {
          
x+=this.speed;
        }
      }
      else
      {
        
dir 1;
        
//move
        
if(!onwall(x-this.speed,y+.5) && !onwall(x-this.speed,y+2.5))
        {
          
x-=this.speed;
        }
      }
    }
    else
    {
      
//direction is 0 or 2
      
if(player.y>y)
      {
        
dir 2;
        
//move
        
if(!onwall(x,y+this.speed) && !onwall(x+2,y+this.speed))
        {
          
y+=this.speed;
        }
      }
      else
      {
        
dir 0;
        
//move
        
if(!onwall(x,y-this.speed) && !onwall(x+2,y-this.speed))
        {
          
y-=this.speed;
        }
      }
    }
    if((
abs(player.x-x)^2+abs(player.y-y)^2)^.5<=3)
    {

      if(
this.hit==1)
      {
        
setcharani("sword",NULL);
        
this.hit 0;
        
setTimer(.45);
      }
      else
      {
        
this.hit 1;
        
setTimer(random(.05,.3));
      }
    }
    else
    {
      
setTimer(.05);
    }
  }
  if(
this.mode==2)
  {
    
hearts-=this.damage;
    if(
this.damage>0)
    {
      
setcharani("hurt",NULL);
    }
    else
    {
      
this.damage 0;
    }
    if(
player.x>x)
    {
      for(
this.0this.i<3this.i++)
      {
        if(!
onwall(x-1,y+.5) && !onwall(x-1,y+2.5))
        {
          
x-=1;
        }
        else
        {
          
chat "Ugh";
        }
        
sleep(.05);
      }
    }
    else if(
player.x<x)
    {
      for(
this.0this.i<3this.i++)
      {
        if(!
onwall(x+1,y+.5) && !onwall(x+1,y+2.5))
        {
          
x+=1;
        }
        else
        {
          
chat "Ugh";
        }
        
sleep(.05);
      }
    }
    else if(
player.y>y)
    {
      for(
this.0this.i<3this.i++)
      {
        if(!
onwall(x,y+1) && !onwall(x+2,y+1))
        {
          
y+=1;
        }
        else
        {
          
chat "Ugh";
        }
        
sleep(.05);
      }
    }
    else if(
player.y>y)
    {
      for(
this.0this.i<3this.i++)
      {
        if(!
onwall(x,y-1) && !onwall(x+2,y-1))
        {
          
y-=1;
        }
        else
        {
          
chat "Ugh";
        }
        
sleep(.05);
      }
    }
    
setTimer(.5);
    
this.mode 1;
  }
  if(
this.mode==3)
  {
    
setcharani("dead",NULL);
    
chat "This isn't over, " player.nick ", your gift's in the throne room!";
    
client.unlock 1;
    
hearts 5;
    
this.mode 0;
    
setTimer(10);
  }
}
function 
onWa****()
{
  
this.mode 2;
  
this.damage player.swordpower/2;
  
setTimer(.05);
}
function 
onWasShot()
{
  
this.mode 2;
  
this.damage clientr.bowpower/2;
  
setTimer(.05);
}
function 
onExploded()
{
  
this.mode 2;
  
this.damage clientr.bombpower/2;
  
setTimer(.05);
}
function 
onWaspelt()
{
  
setcharani("sword",NULL);
  
this.mode 2;
  
this.damage=0;
  
setTimer(.05);

Reply With Quote
  #2  
Old 01-04-2007, 06:48 AM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
I'm trying to do some movement...not working.
How do you use move(), and am I using the scripts right...and wil this make it easier to attack the baddy?
PHP Code:
  if(this.mode==1)
  {
    
setcharani("walk",NULL);
    if(!
onwall(x+1+vecx(dir)*this.speed,y+1.5+vecy(dir)*this.speed))
    {
      
x=x+1+vecx(dir)*this.speed;
      
y=y+1.5+vecy(dir)*this.speed;
    }
    if(
abs(player.x-x)>abs(player.y-y))
    {
      
//direction should be 1 or 3
      
if(player.x>x)
      {
        
dir 3;
      }
      else
      {
        
dir 1;
      }
    }
    else
    {
      
//direction is 0 or 2
      
if(player.y>y)
      {
        
dir 2;
      }
      else
      {
        
dir 0;
      }
    }
    if((
abs(player.x-x)^2+abs(player.y-y)^2)^.5<=3)
    {

      if(
this.hit==1)
      {
        
setcharani("sword",NULL);
        
this.hit 0;
        
setTimer(.45);
      }
      else
      {
        
this.hit 1;
        
setTimer(random(.05,.3));
      }
    }
    else
    {
      
setTimer(.05);
    }
  } 
Reply With Quote
  #3  
Old 01-04-2007, 06:59 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
move(x,y,time,options);

x = move how far from current position horizontally

y = move how far from current position vertically

time = time it takes to get from starting point to ending point

options = cachtype(0,1,2) blockcheck(4) eventwhendone(8) applydir(16)

blockcheck = test to see if the tile is blocking or not
eventwhendone = stops moving after one movement. other wise the NPC
will move forever in that direction.
applydir = if the the char current gani has 4 dir it will apply it when it moves


Here's a NPC I use for a townsfolk randomly move

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
onTimeOut();
}

function 
onTimeOut() {
  
temp.rx random(-3,3);
  
temp.ry random(-3,3);
  
temp.r  random(3,5);
  
temp.rr random(0,5);
  
setcharani("walk",NULL);
  
move(rx,ry,r,4+8+16);
  
sleep(r);
  
setcharani("idle",NULL);
  
setTimer(rr);

I have more stuff in the script of course but there is the movement part. Also remember the movement is still in the Quadrent IV (Grid Wise)
__________________
Deep into the Darkness peering...
Reply With Quote
  #4  
Old 01-04-2007, 09:50 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
Thanks, that helped a lot.
Moves a lot smoother now, although I still can't find a way to hit him x_X
full script below.
PHP Code:
// NPC Enemy made by Excalibur
//Ceverous, first fight
//#CLIENTSIDE
function onPlayerenters()
{
  
// Character attributes
  
showcharacter();
  
headimg "darkdemon13-head4.mng";
  
colors[0] = "orange";
  
colors[1] = "gray";
  
colors[2] = "gray";
  
colors[3] = "black";
  
colors[4] = "black";
  
nick "?????";
  
shieldimg "darkman-shield.gif";
  
bodyimg "bodysage2.mng";
  
swordimg "dronan-sword.gif";
  
shieldpower 1;
  
swordpower 2;
  
hearts 5;
  
dir 2;
  
setcharani("idle",NULL);
  
//position
  
x+=.5;
  
//sight radius
  
this.sightradius 10;
  
//speed
  
this.speed .5;
  
//cut scene
  
setani("idle",NULL);
  
freezeplayer(3);
  
player.chat "It's been YOU!";
  
sleep(.1);
  
chat "Ha ha ha! Welcome to the party!";
  
//timeout
  
setTimer(.05);
}
function 
onTimeout()
{
  function 
onWa****()
  {
    
this.mode 2;
    
this.damage player.swordpower/2;
  }
  function 
onWasShot()
  {
    
this.mode 2;
    
this.damage clientr.bowpower/2;
  }
  function 
onExploded()
  {
    
this.mode 2;
    
this.damage clientr.bombpower/2;
  }
  function 
onWaspelt()
  {
    
setcharani("sword",NULL);
    
this.mode 2;
    
this.damage=0;
  }
  if(
this.mode 0)
  {
    
setcharani("idle",NULL);
    
setTimer(.05);
  }
  
/*Modes
  *0)Idle
  *1)Chasing/attacking
  *2)Hurt
  *3)Dead
  **********/
  
if(hearts<=0)
  {
    
hearts 0;
    
this.mode 3;
  }
  if((
abs(player.x-x)^2+abs(player.y-y)^2)^.5<=this.sightradius)
  {
    
this.mode 1;
  }
  if(
this.mode==1)
  {
    
setcharani("walk",NULL);
    
//set movement w/ trig
    
if(player.x>&& abs(player.x-x)>1)
    {
      
this.modx 1;
    }
    else if(
player.x<&& abs(player.x-x)>1)
    {
      
this.modx = -1;
    }
    else
    {
      
this.modx 0;
    }
    if(
player.y>&& abs(player.y-y)>1)
    { 
      
this.mody 1;
    }
    else if(
player.y<&& abs(player.y-y)>1)
    {
      
this.mody = -1;
    }
    else
    {
      
this.mody 0;
    }
    
//My wall check
    
if(onwall(x,y) || onwall(x,y+3) || onwall(x+1,y) || onwall(x+1,y+3) || onwall(x+2,y) || onwall(x+2,y+3) || onwall(x,y) || onwall(x,y+1.5) || onwall(x+1,y) || onwall(x+1,y+1.5) || onwall(x+2,y) || onwall(x+2,y+1.5))
    {
      if(
this.scount==0)
      {
        
shootball();
      }
      else
      {
        if(
this.scount<=5)
        {
           
this.scount 0;
        }
      }
      
this.scount++;
      
move(this.speed*this.modx*.3,this.speed*this.mody*.3,1,4+8+16);
    }
    else
    {
      
move(this.speed*this.modx,this.speed*this.mody,1,4+8+16);
    }
    if((
abs(player.x-x)^2+abs(player.y-y)^2)^.5<=3)
    {
      if(
this.hit==1)
      {
        
setcharani("sword",NULL);
        
this.hit 0;
        
setTimer(.45);
      }
      else
      {
        
this.hit 1;
        
setTimer(random(.05,.3));
      }
    }
    else
    {
      
setTimer(.05);
    }
  }
  if(
this.mode==2)
  {
    
hearts-=this.damage;
    if(
this.damage>0)
    {
      
setcharani("hurt",NULL);
    }
    else
    {
      
this.damage 0;
    }
    if(
player.x>x)
    {
      for(
this.0this.i<3this.i++)
      {
        if(!
onwall(x-1,y+.5) && !onwall(x-1,y+2.5))
        {
          
x-=1;
        }
        else
        {
          
chat "Ugh";
        }
        
sleep(.05);
      }
    }
    else if(
player.x<x)
    {
      for(
this.0this.i<3this.i++)
      {
        if(!
onwall(x+1,y+.5) && !onwall(x+1,y+2.5))
        {
          
x+=1;
        }
        else
        {
          
chat "Ugh";
        }
        
sleep(.05);
      }
    }
    else if(
player.y>y)
    {
      for(
this.0this.i<3this.i++)
      {
        if(!
onwall(x,y+1) && !onwall(x+2,y+1))
        {
          
y+=1;
        }
        else
        {
          
chat "Ugh";
        }
        
sleep(.05);
      }
    }
    else if(
player.y>y)
    {
      for(
this.0this.i<3this.i++)
      {
        if(!
onwall(x,y-1) && !onwall(x+2,y-1))
        {
          
y-=1;
        }
        else
        {
          
chat "Ugh";
        }
        
sleep(.05);
      }
    }
    
setTimer(.5);
    
this.mode 1;
  }
  if(
this.mode==3)
  {
    
setcharani("dead",NULL);
    
chat "This isn't over, " player.nick ", your gift's in the throne room!";
    
client.unlock 1;
    
hearts 5;
    
this.mode 0;
    
setTimer(10);
  }
}
function 
onWa****()
{
  
this.mode 2;
  
this.damage player.swordpower/2;
  
setTimer(.05);
}
function 
onWasShot()
{
  
this.mode 2;
  
this.damage clientr.bowpower/2;
  
setTimer(.05);
}
function 
onExploded()
{
  
this.mode 2;
  
this.damage clientr.bombpower/2;
  
setTimer(.05);
}
function 
onWaspelt()
{
  
setcharani("sword",NULL);
  
this.mode 2;
  
this.damage=0;
  
setTimer(.05);

edit: made movement cleaner near walls

Last edited by excaliber7388; 01-04-2007 at 10:11 PM..
Reply With Quote
  #5  
Old 01-04-2007, 10:23 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
One thing, I've never seen a function inside a function >_>

Ah, instead of all the onwall detection you could of used an algorithm, or onwall2( x , y , width, height)

and, may I edit the script? I'll post it if I get it to work :O
__________________
Reply With Quote
  #6  
Old 01-04-2007, 10:48 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
Quote:
Originally Posted by Chompy View Post
One thing, I've never seen a function inside a function >_>

Ah, instead of all the onwall detection you could of used an algorithm, or onwall2( x , y , width, height)

and, may I edit the script? I'll post it if I get it to work :O
Of course.
I plan to add more.
I want 'smart' baddies.
The functions within the timeout are there because I was testing to see if it would work.
I believe I put them outside of the timeout as well.
Reply With Quote
  #7  
Old 01-05-2007, 09:39 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Quote:
Originally Posted by Chompy View Post
One thing, I've never seen a function inside a function >_>
That is actually quite common and most of my complex script. I originally thought that until my scripting teacher corrected me XP Anyways, for the hitting thing I have one idea not sure it will work though here it is

PHP Code:
//#CLIENTSIDE

etc...

function 
onTimeOut() {
random(1,2);
if (
player.x in |this.x-1;,this+3| && player.y in |this.y-1,this.y+3| && player.ani == "Attack Gani" && == "1") {
function 
hurtNPC(amount,type,force);
}
else if (
player.x in |this.x-1;,this+3| && player.y in |this.y-1,this.y+3| && player.ani == "Attack Gani" && == "2") {
function 
dmgplayer(amount);
}
setTimer(0.05):

the random thing is like if the player hit's or misses the baddy.
__________________
Deep into the Darkness peering...
Reply With Quote
  #8  
Old 01-06-2007, 10:34 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
It's detecting the Was Hit() function, but it isn't detecting the player.swordpower variable, and for some reason, even if I set it to a normal number, it still does not work, unlike the bomb and bow, which will do damage (in fact, the bomb does too much, I have to set a limit of some sort on the explosion detection).
Reply With Quote
  #9  
Old 01-07-2007, 12:57 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Angel_Light View Post
That is actually quite common and most of my complex script. I originally thought that until my scripting teacher corrected me XP Anyways, for the hitting thing I have one idea not sure it will work though here it is

PHP Code:
//#CLIENTSIDE

etc...

function 
onTimeOut() {
random(1,2);
if (
player.x in |this.x-1;,this+3| && player.y in |this.y-1,this.y+3| && player.ani == "Attack Gani" && == "1") {
function 
hurtNPC(amount,type,force);
}
else if (
player.x in |this.x-1;,this+3| && player.y in |this.y-1,this.y+3| && player.ani == "Attack Gani" && == "2") {
function 
dmgplayer(amount);
}
setTimer(0.05):

the random thing is like if the player hit's or misses the baddy.
That just looks weird with 'function' >_>
It would work wihtout 'function' <_<
__________________
Reply With Quote
  #10  
Old 01-07-2007, 07:49 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Quote:
Originally Posted by Chompy View Post
That just looks weird with 'function' >_>
It would work wihtout 'function' <_<
???
__________________
Deep into the Darkness peering...
Reply With Quote
  #11  
Old 01-07-2007, 08:51 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
yeah... i generally do

PHP Code:
function somefunction()
{
  if (
condition)
    
doanotherfunction();

You don't need to write 'function someFunction();' to call a function, just 'someFunction();

I think the original comment was about the fact excal had function wa****() inside a function ontimeout() ....

Last edited by Twinny; 01-07-2007 at 09:08 AM..
Reply With Quote
  #12  
Old 01-10-2007, 02:56 AM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
The old gs1 baddy used wa****, why wouldn't it work on this one?
Reply With Quote
  #13  
Old 01-10-2007, 11:20 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Quote:
Originally Posted by Twinny View Post
yeah... i generally do
You don't need to write 'function someFunction();' to call a function, just 'someFunction();
you can do somefunction() if you have the function outside of the timeout but if you put the function in it you n eed function
__________________
Deep into the Darkness peering...
Reply With Quote
Reply


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 10:40 PM.


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