Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Custom baddies and custom hp (https://forums.graalonline.com/forums/showthread.php?t=68269)

excaliber7388 08-21-2006 09:19 PM

Custom baddies and custom hp
 
Basically, I have one, apparently very powerfull, baddy. I can't damage it.
Here's some parts of the scritps used for attacking it, it's mostly triggeractions, but AI can't find out what's failing, since it's all going through :(
First, the action triggered by punching:
PHP Code:

triggeraction(player.x+1+vecx(player.dir)*2.1,player.y+1.5+vecy(player.dir)*2.1,"hurt","hurt",clientr.attack); 

This is received by the baddy:

PHP Code:

function onActionhurt()
{
  if(
params[0]=="hurt")
  {
      
this.hp-=params[1];
      
chat=this.hp;
      
triggeraction(x,y,"hp","hp",this.hp);
      if(
this.hp<=0)
      {
        
this.hp=int(random(15,25));
        
triggeraction(0,0,"serverside","-System","exp",1,"secure");
        
hide();
        
settimer(random(10,20));
      } 
  }
}

function 
onCreated()
{
  
setshape(1,32,32);
  
this.hp=int(random(15,25));


Which triggers the client of the baddy, for the hp variable to exist on clientside as well:

PHP Code:

function onActionhp()
{
  
this.hp=params[1];
}
function 
onCreated()
{
  
this.direct=2;
  
setimg("dr_baddy_spider.png");
  
setshape(1,32,32);
  
onTimeout();


Now...what's not working???
The hp doesn't go down, yet the actions are received.
=(

Angel_Light 08-22-2006 12:22 AM

o.o, I would simply use 'wash1t' or something

excaliber7388 08-22-2006 03:15 PM

Okay, playing around I found out that I could damage the baddy if it didn't move. I then tried a long timeout, 3 seconds. I couldn't make it work with a shorter timeout. My question is, How could I make it so I could have a .05 timeout (clientside of course) and still have the actions be received?
Right now I'm using that long timeout with a for loop to make it look like it's moving, then stoping for a while.

excaliber7388 08-22-2006 10:50 PM

Okay, using the "hearts" variable now, so I can use hitobjects()
Still doesn't work well.
It might have something to do with the timeout, but I don't want to slow it down too much =(
PHP Code:


//#CLIENTSIDE
function onCreated()
{
  
this.direct=2;
  
setimg("dr_baddy_spider.png");
  
setshape(1,32,32);
  
hearts=int(random(15,25));
  
onTimeout();
}
function 
onPlayertouchsme()
{
  
setani("hurt",NULL);
  
triggeraction(0,0,"serverside","-System","hurt","secure",1);
}
function 
onTimeout()
{
  
chat=hearts;
  
this.hp=hearts;
  if(
hearts==&& this.hp==0)
  {
    
this.dead=1;
    
hide();
    
triggeraction(0,0,"serverside","-System","exp",1,"secure");
    
sleep(random(10,15));
    
this.dead=0;
    
onCreated();
  }  
  if(
this.dead==0)
  {
    if(
this.walk==0)
    {
      
this.shoot=1;
      
this.walk=int(random(20,40));
    }
    else
    {
      
this.walk--;
      if(
abs(x-player.x)>=abs(y-player.y))
      {
        if(
player.x<x)
        {
          
this.direct=1;
        }
        if(
player.x>=x)
        {
          
this.direct=3;
        }
      }
      else if(
abs(x-player.x)<abs(y-player.y))
      {
        if(
player.y>y)
        {
          
this.direct=2;
        }
        if(
playery<=y)
        {
          
this.direct=0;
        }
      }  
      if(
player.x+.5<x)
      {
        if(!
onwall(x-.2,y) && !onwall(x-.2,y+2))
        {
          
x-=.2;
        }
      }
      else if(
player.x+.5>=x)
      {
        if(!
onwall(x+2.2,y) && !onwall(x+2.2,y+2))
        {
          
x+=.2;
        }
      }
      if(
player.y+1<y)
      {
        if(!
onwall(x,y-.2) && !onwall(x+2,y-.2))
        {
          
y-=.2;
        }
      }
      else if(
player.y+1>=y)
      {
        if(!
onwall(x,y+.2) && !onwall(x+2,y+.2))
        {
          
y+=.2;
        }
      }
      if(
int(this.walk/2)<(this.walk/2))
      {  
        if(
this.direct==0)
        {
          
setimgpart("dr_baddy_spider",0,0,32,32);
        }
        if(
this.direct==1)
        {
          
setimgpart("dr_baddy_spider",32,0,32,32);
        }
        if(
this.direct==2)
        {
          
setimgpart("dr_baddy_spider",64,0,32,32);
        }
        if(
this.direct==3)
        {
          
setimgpart("dr_baddy_spider",96,0,32,32);
        }  
      }
      else
      {
        if(
this.direct==0)
        {
          
setimgpart("dr_baddy_spider",0,32,32,32);
        }
        if(
this.direct==1)
        {
          
setimgpart("dr_baddy_spider",32,32,32,32);
        }
        if(
this.direct==2)
        {
          
setimgpart("dr_baddy_spider",64,32,32,32);
        }
        if(
this.direct==3)
        {
          
setimgpart("dr_baddy_spider",96,32,32,32);
        } 
      }
      if(
abs(x-player.x) <  && abs(y-player.y) < 1
      {
        
triggeraction(0,0,"serverside","-System","hurt","secure",1);
        
setani("hurt",NULL);
      }
    }
    if(
this.shoot==1)
    {
      if(
this.direct==0)
      {
        
sleep(.1);
        
shootball();  
        
this.shoot=0;
      }
      if(
this.direct==1)
      {
        
setimgpart("dr_baddy_spider.png",32,64,32,32);
        
sleep(.1);
        
setimgpart("dr_baddy_spider.png",32,96,32,32); 
        
shootball();  
        
this.shoot=0;
      }
      if(
this.direct==2)
      {
        
setimgpart("dr_baddy_spider.png",64,64,32,32);
        
sleep(.1);
        
setimgpart("dr_baddy_spider.png",0,64,32,32); 
        
shootball();  
        
this.shoot=0;
      }
      if(
this.direct==3)
      {
        
setimgpart("dr_baddy_spider.png",96,64,32,32);
        
sleep(.1);
        
setimgpart("dr_baddy_spider.png",96,96,32,32); 
        
shootball();  
        
this.shoot=0;
      }
    }
  }
  
setTimer(.05);



Tolnaftate2004 08-22-2006 11:20 PM

The serverside (x,y) of the baddy are different than the clientside (x,y). Make sure you're triggering at the serverside coordinates. If you're not modifying the (x,y) serverside, than you can store them in save[] variables (the npc will be stationary serverside), granted they still work...

excaliber7388 08-22-2006 11:40 PM

It's all on clientside now :(

excaliber7388 08-23-2006 05:02 PM

Sorry to bump :forwn:
It seems that I can only damage it once. I attack it, it's hearts seem to go down, but after that, I cannot hit it again. I've shortened the timeout as well, in fact, here is the current script:
PHP Code:


//#CLIENTSIDE
function onCreated()
{
  
this.direct=2;
  
setimg("dr_baddy_spider.png");
  
setshape(1,32,32);
  
hearts=int(random(15,25));
  
onTimeout();
}
function 
onPlayertouchsme()
{
  
setani("hurt",NULL);
  
triggeraction(0,0,"serverside","-System","hurt","secure",1);
}
function 
onTimeout()
{
  
chat=hearts;
  
this.hp=hearts;
  if(
hearts==&& this.hp==0)
  {
    
this.dead=1;
    
hide();
    
triggeraction(0,0,"serverside","-System","exp",1,"secure");
    
sleep(random(10,15));
    
this.dead=0;
    
onCreated();
  }  
  if(
this.dead==0)
  {
    if(
this.walk==0)
    {
      
this.shoot=1;
      
this.walk=int(random(20,40));
    }
    else
    {
      
this.walk--;
      if(
abs(x-player.x)>=abs(y-player.y))
      {
        if(
player.x<x)
        {
          
this.direct=1;
        }
        if(
player.x>=x)
        {
          
this.direct=3;
        }
      }
      else if(
abs(x-player.x)<abs(y-player.y))
      {
        if(
player.y>y)
        {
          
this.direct=2;
        }
        if(
playery<=y)
        {
          
this.direct=0;
        }
      }  
      if(
player.x+.5<x)
      {
        if(!
onwall(x-.2,y) && !onwall(x-.2,y+2))
        {
          
x-=.2;
        }
      }
      else if(
player.x+.5>=x)
      {
        if(!
onwall(x+2.2,y) && !onwall(x+2.2,y+2))
        {
          
x+=.2;
        }
      }
      if(
player.y+1<y)
      {
        if(!
onwall(x,y-.2) && !onwall(x+2,y-.2))
        {
          
y-=.2;
        }
      }
      else if(
player.y+1>=y)
      {
        if(!
onwall(x,y+.2) && !onwall(x+2,y+.2))
        {
          
y+=.2;
        }
      }
      if(
int(this.walk/2)<(this.walk/2))
      {  
        if(
this.direct==0)
        {
          
setimgpart("dr_baddy_spider",0,0,32,32);
        }
        if(
this.direct==1)
        {
          
setimgpart("dr_baddy_spider",32,0,32,32);
        }
        if(
this.direct==2)
        {
          
setimgpart("dr_baddy_spider",64,0,32,32);
        }
        if(
this.direct==3)
        {
          
setimgpart("dr_baddy_spider",96,0,32,32);
        }  
      }
      else
      {
        if(
this.direct==0)
        {
          
setimgpart("dr_baddy_spider",0,32,32,32);
        }
        if(
this.direct==1)
        {
          
setimgpart("dr_baddy_spider",32,32,32,32);
        }
        if(
this.direct==2)
        {
          
setimgpart("dr_baddy_spider",64,32,32,32);
        }
        if(
this.direct==3)
        {
          
setimgpart("dr_baddy_spider",96,32,32,32);
        } 
      }
      if(
abs(x-player.x) <  && abs(y-player.y) < 1
      {
        
triggeraction(0,0,"serverside","-System","hurt","secure",1);
        
setani("hurt",NULL);
      }
    }
    if(
this.shoot==1)
    {
      if(
this.direct==0)
      {
        
sleep(.1);
        
shootball();  
        
this.shoot=0;
      }
      if(
this.direct==1)
      {
        
setimgpart("dr_baddy_spider.png",32,64,32,32);
        
sleep(.1);
        
setimgpart("dr_baddy_spider.png",32,96,32,32); 
        
shootball();  
        
this.shoot=0;
      }
      if(
this.direct==2)
      {
        
setimgpart("dr_baddy_spider.png",64,64,32,32);
        
sleep(.1);
        
setimgpart("dr_baddy_spider.png",0,64,32,32); 
        
shootball();  
        
this.shoot=0;
      }
      if(
this.direct==3)
      {
        
setimgpart("dr_baddy_spider.png",96,64,32,32);
        
sleep(.1);
        
setimgpart("dr_baddy_spider.png",96,96,32,32); 
        
shootball();  
        
this.shoot=0;
      }
    }
  }
  
setTimer(.1);



excaliber7388 08-26-2006 10:39 PM

Okay, I'm using hitobjects, and hearts for the baddy. Now, why would I only be able to hurt this baddy once. Even after it revives, I cannot hit it again unless I reconnect. Why?
There should be no reason for this now? At least not one I can see. Can someone please fill me in? What is wrong with this?!?

xXziroXx 08-27-2006 01:24 AM

First of all, why the heck are you making a clientsided baddy?

excaliber7388 08-27-2006 02:11 AM

Because the serversided one didn't work. x_x
I want it serverside, but I'm afraid a large number could hurt the NPC server, or cause lag, etc. It doesn't work either way. :(

xXziroXx 08-27-2006 02:13 AM

Malorias baddys are serversided, and Im pretty sure that GKs and Zodiac's are aswell.

excaliber7388 08-27-2006 04:20 PM

Once again, doesn't work
Movement is messed up, he doesn't shoot, and you can still only hit him once. Any thoughts?
Here's what I have now:
PHP Code:

function onCreated()
{
  
showcharacter();
  
dir 2;
  
setcharani("dr_baddy_spider",NULL);
  
setshape(1,32,32);
  
hearts int(random(10,25));
  
onTimeout();
}
function 
onTimeout()
{
  if(
hearts>0)
  {
    if(
this.walk==0)
    {
      
setcharani("dr_baddy_spider_prep",NULL);
      
sleep(random(.5,1.5));
      
shootball();
      
setcharani("dr_baddy_spider_shoot",NULL);
      
this.walk=int(random(2,15));
    }
    else
    {
      
this.walk--;
      if(
abs(x-player.x)>=abs(y-player.y))
      {
        if(
player.x<x)
        {
          
dir 1;
        }
        if(
player.x>=x)
        {
          
dir 3;
        }
      }
      else if(
abs(x-player.x)<abs(y-player.y))
      {
        if(
player.y>y)
        {
          
dir 2;
        }
        if(
playery<=y)
        {
          
dir 0;
        }
      }  
      if(
player.x+.5<x)
      {
        if(!
onwall(x-.2,y) && !onwall(x-.2,y+2))
        {
          
x-=.2;
        }
      }
      else if(
player.x+.5>=x)
      {
        if(!
onwall(x+2.2,y) && !onwall(x+2.2,y+2))
        {
          
x+=.2;
        }
      }
      if(
player.y+1<y)
      {
        if(!
onwall(x,y-.2) && !onwall(x+2,y-.2))
        {
          
y-=.2;
        }
      }
      else if(
player.y+1>=y)
      {
        if(!
onwall(x,y+.2) && !onwall(x+2,y+.2))
        {
          
y+=.2;
        }
      }
    }
  }
  else if(
hearts<=0)
  {
    
hearts 0;
    
triggeraction(0,0,"serverside","-System","exp","secure",player.account,1);
    
setani(NULL,NULL);
    
sleep(random(7,20));
    
onCreated();
  }
  
settimer(.1);
}
function 
onPlayertouchsme()
{
  
setani("hurt",NULL);
  
triggeraction(0,0,"serverside","-System","hurt","secure",1);      
}
function 
onWa****()
{
  
setcharani("dr_baddy_spider_shoot",NULL);



excaliber7388 08-28-2006 09:10 PM

Only pay attention to the above post....bump ;)

contiga 08-29-2006 09:54 AM

Lol, that movement.. is so.. lmao xD

excaliber7388 08-29-2006 06:27 PM

Quote:

Originally Posted by contiga
Lol, that movement.. is so.. lmao xD

It worked in the past versions of this baddy, but for some reason it doesn't work right now. Also, the baddy can STILL only be damaged ONCE. After than, I have to reconnect to damage it again. I can't figure out what the problem is, and apparently, no one else can either x_x

Skyld 08-29-2006 07:37 PM

Ugh.. use move(dx, dx, speed, options) for movement.

Editing the X and Y manually will not give you very fluid movement due to the 0.05 second limit.

excaliber7388 08-29-2006 07:43 PM

Quote:

Originally Posted by Skyld
Ugh.. use move(dx, dx, speed, options) for movement.

Editing the X and Y manually will not give you very fluid movement due to the 0.05 second limit.

It doesn't look too bad, but I'll do that, just to see if it makes the NPC work at all

excaliber7388 08-31-2006 12:41 AM

Oh come on, I've rescripted this three times, the last one should work.
Does anyone know why it wouldn't????

excaliber7388 08-31-2006 12:58 AM

Okay, added the move thing, I'm nwe to using move, so tell me if I'm wrong:
(btw, it still doesn't work)
PHP Code:

//by Excalibur
function onCreated()
{
  
showcharacter();
  
dir 2;
  
setcharani("dr_baddy_spider",NULL);
  
setshape(1,32,32);
  
hearts int(random(10,25));
  
onTimeout();
}
function 
onTimeout()
{
  if(
hearts>0)
  {
    if(
this.walk==0)
    {
      
setcharani("dr_baddy_spider_prep",NULL);
      
sleep(random(.5,1.5));
      
shootball();
      
setcharani("dr_baddy_spider_shoot",NULL);
      
this.walk=int(random(2,15));
    }
    else if(
this.walk>0)
    {
      
this.walk--;
      if(
abs(x-player.x)>=abs(y-player.y))
      {
        if(
player.x<x)
        {
          
dir 1;
        }
        if(
player.x>=x)
        {
          
dir 3;
        }
      }
      else if(
abs(x-player.x)<abs(y-player.y))
      {
        if(
player.y>y)
        {
          
dir 2;
        }
        if(
playery<=y)
        {
          
dir 0;
        }
      }  
      if(
player.x+.5<x)
      {
        if(!
onwall(x-.2,y) && !onwall(x-.2,y+2))
        {
          
move(-.2,0,1,1);
        }
      }
      else if(
player.x+.5>=x)
      {
        if(!
onwall(x+2.2,y) && !onwall(x+2.2,y+2))
        {
          
move(.2,0,1,1);
        }
      }
      if(
player.y+1<y)
      {
        if(!
onwall(x,y-.2) && !onwall(x+2,y-.2))
        {
          
move(0,-.2,1,1);
        }
      }
      else if(
player.y+1>=y)
      {
        if(!
onwall(x,y+.2) && !onwall(x+2,y+.2))
        {
          
move(0,.2,1,1);
        }
      }
    }
  }
  else if(
hearts<=0)
  {
    
hearts 0;
    
triggeraction(0,0,"serverside","-System","exp","secure",player.account,1);
    
setani(NULL,NULL);
    
sleep(random(7,20));
    
onCreated();
  }
  
settimer(.1);
}
function 
onPlayertouchsme()
{
  
setani("hurt",NULL);
  
triggeraction(0,0,"serverside","-System","hurt","secure",1);      
}
function 
onWa****()
{
  
setcharani("dr_baddy_spider_shoot",NULL);




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

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