Graal Forums

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

excaliber7388 12-22-2006 11:32 PM

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);



excaliber7388 01-04-2007 06:48 AM

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);
    }
  } 


Angel_Light 01-04-2007 06:59 AM

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)

excaliber7388 01-04-2007 09:50 PM

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

Chompy 01-04-2007 10:23 PM

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

excaliber7388 01-04-2007 10:48 PM

Quote:

Originally Posted by Chompy (Post 1260817)
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.

Angel_Light 01-05-2007 09:39 PM

Quote:

Originally Posted by Chompy (Post 1260817)
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.

excaliber7388 01-06-2007 10:34 PM

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).

Chompy 01-07-2007 12:57 AM

Quote:

Originally Posted by Angel_Light (Post 1261420)
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' <_<

Angel_Light 01-07-2007 07:49 AM

Quote:

Originally Posted by Chompy (Post 1261955)
That just looks weird with 'function' >_>
It would work wihtout 'function' <_<

???

Twinny 01-07-2007 08:51 AM

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() ....

excaliber7388 01-10-2007 02:56 AM

The old gs1 baddy used wa****, why wouldn't it work on this one?

Angel_Light 01-10-2007 11:20 PM

Quote:

Originally Posted by Twinny (Post 1262174)
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 >_<


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

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