Graal Forums

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

theHAWKER 05-05-2007 12:10 AM

spawn baddy probs...
 
i have a spar where u can spawn baddys but its not working x.x can u guys help me out?

oh and im just using the g-baddy script found in the script gallery
so here it is:
PHP Code:

// NPC made by theHAWKER
//#CLIENTSIDE
if (playerchats&&strequals(#c,/baddy)){
    
putnpc2 playerx,playery,{ //GBaddy
//Version 1.0

//Features:
// Constantly moving about, not idle like most
// boring baddies you see on Graal.
// When you step into the baddies vision radius,
// he will begin to chase after you, in attack mode.
// While in attack mode, the baddy has a total of
// 3 possible things that he can do, all of which
// are chosen randomly.
// The baddy can choose to swing his sword at
// you, heal himself, and/or cause an explosion
// under him.
// NOTE: I didn't add any damage checks besides
//       Was.Hit, so if Was.Hit only checks for
//       whether or not the baddy was hit by
//       a sword, then that's all that will
//       hurt it for now.
// NOTE #2: I know that it's NOT PERFECT,
//          but it's the first time I've actually,
//          worked with Artificial Intelligence,
//          excluding the current bot that I'm
//          making on Graal X, which is much
//          different. I figured it was a
//          nice learning experience, and I
//          figured some people could find it
//          useful since it's MUCH MORE challenging
//          than the default baddy NPCs.
// NOTE #3: I used some of the mathematical
//          calculations previously created by
//          Stefan in his baddy NPC (the default
//          Graal baddy NPC).

//By: Gambet

enum
{
 
WALK,
 
ATTACK,
 
DEAD
}

function 
onCreated()
{
  
showcharacter();
  
this.bodyimg "body2.png";
  
this.shieldimg "no-shield.png";
  
this.nick "GBaddy";
  
this.ap 0;
  for (
a=0a<5a++)
   {
    
this.colors[a] = "black";
   }
  if (
this.ani != "idle")
   {
     
setcharani("idle","");
   }
  
this.health = {10,10};
  
this.mov_speed 0.5;
  
this.count int(random(10,40));
  
this.mode WALK;
  
setTimer(0.1);
}

function 
onPlayerEnters()
{
  
onTimeOut(); //To Wake Up The NPC
  
this.headimg "head" int(random(0,1000)) @ ".png"//To Have A Different Head Each Time You Enter The Level
}

function 
onWa****() //REMOVE THE . - GRAAL FORUMS FILTER IS ANNOYING >O
{
 if (
this.health[0]-(player.swordpower/2) > 0)
  {
    if (
this.ani != "hurt")
     {
       
setcharani("hurt","");
       
scheduleevent(1,"Counter","");
     }
    switch(
this.plyr.dir//Knockback
     
{
      case 
"2":
       if (!
onwall(this.x,this.y+3))
        {
         
this.y+=3;
        }
       break;
      case 
"0":
       if (!
onwall(this.x,this.y-3))
        {
         
this.y-=3;
        }
       break;
      case 
"1":
       if (!
onwall(this.x-3,this.y))
        {
         
this.x-=3;
        }
       break;
      case 
"3":
       if (!
onwall(this.x+3,this.y))
        {
         
this.x+=3;
        }
       break;
     }
     
this.health[0]-=player.swordpower/2;
     
chat this.health[0] @ "/" this.health[1];
     
scheduleevent(2,"HideChat","");
  } else
   {
    if (
this.mode != DEAD)
     {
       
this.mode DEAD;
       
this.health[0] = 0;
       
putexplosion2(3,3,this.x,this.y);
       
putexplosion2(3,3,this.x,this.y+0.5);
       
setcharani("dead","");
       
chat this.health[0] @ "/" this.health[1];
       
scheduleevent(8,"Respawn","");
     }
   }
}

function 
onHideChat()
{
 if (
params[0] == "idle")
  {
    
chat "";
    
setcharani("idle","");
  } else
   {
     
chat "";
   }
}

function 
onCounter()
{
 if (
this.health[0] > 0)
  {
    
setcharani("sword","");
  }
}

function 
onRespawn()
{
 if (
this.mode == DEAD)
  {
    
setcharani("idle","");
    
chat "";
    
this.health[0] = this.health[1];
    
this.mode WALK;
  }
}

function 
onTimeOut()
{
 if (
players.size() > 0)
  {
   
setTimer(0.1);
  } else
   {
    
setTimer(0); //To Sleep In Case No Players Are In The Room - Saves CPU Time
   
}
 if (
this.mode != DEAD)
  {
   if (
this.to_check.x in |this.x-10,this.x+10| && this.to_check.y in |this.y-10,this.y+10|)
    {
     if (
this.mode != ATTACK)
      {
        
this.mode ATTACK;
      }
    } else
     {
       
this.mode WALK;
     }
  }
 if (
this.mode == WALK)
  {
    
this.to_check findnearestplayer(this.x,this.y);
    
this.new_x this.vecx(this.dir) * this.mov_speed;
    
this.new_y this.vecy(this.dir) * this.mov_speed;
    
this.count--;
   if (
this.count 0)
    {
      
this.to_add_x this.new_x 1.5 vecx(this.dir);
      
this.to_add_y this.new_y vecy(this.dir);
     if (
onwall(this.to_add_x,this.to_add_y))
      {
        
this.dir = (this.dir+2)%4;
      } else
       {
         
setcharani("walk","");
         
this.new_x;
         
this.new_y;
       }
    } else
     {
       
this.count int(random(10,40));
       
this.dir = (this.dir+1+int(random(0,2))*2)%4;
     }
  }
  if (
this.mode == ATTACK)
   {
     
this.plyr this.to_check;
     
this.dist_x this.plyr.this.x;
     
this.dist_y this.plyr.this.y;
     
this.len = (this.dist_x*this.dist_x+this.dist_y*this.dist_y)^0.5;
     
this.add_x = (this.dist_x this.len);
     
this.add_y = (this.dist_y this.len);
     
this.check_x this.1.5;
     
this.check_y this.2;
     if (!
onwall(this.check_x this.add_x,this.check_y this.add_y))
      {
        
DamagePlayer();
        
Move();
      } else if (!
onwall(this.check_x this.add_x,this.check_y))
       {
         
this.+= this.add_x;
         
DamagePlayer();
       } else if (!
onwall(this.check_x,this.check_y this.add_y))
        {
          
this.+= this.add_y;
          
DamagePlayer();
        }
   }
 
setTimer(0.1);
}

function 
DamagePlayer()
{
 
this.randomize int(random(0,101));
  if (
this.randomize in |0,82|) //Attack With Sword
   
{
     
setcharani("sword","");
   } else if (
this.randomize in |83,95|) //Cause Explosion
    
{
      
putexplosion2(3,3,this.x,this.y);
    } else if (
this.randomize in |95,101|) //Heal
     
{
      if (
this.health[0] < this.health[1])
       {
        if (
this.health[0]+this.health[1])
         {
           
this.temp_add int(random(0,6));
           
this.health[0]+=this.temp_add;
           
chat "*Healed for " this.temp_add "*";
         } else if (
this.health[0]+>= this.health[1])
          {
            
this.health[0] = this.health[1];
            
chat "*Fully Healed*";
          }
           
setcharani("lift","");
           
this.health[0] = this.health[1];
           
scheduleevent(1,"HideChat","idle");
       }
     }
}

function 
Move()
{
  
setcharani("walk","");
  
this.x+=this.add_x * (this.mov_speed 0.6);
  
this.y+=this.add_y * (this.mov_speed 0.6);
  if (
abs(this.dist_x) > abs(this.dist_y))
   {
    if (
this.dist_x 0)
     {
       
this.dir 3;
     } else
      {
        
this.dir 1;
      }
   } else
    {
     if (
this.dist_y 0)
      {
        
this.dir 2;
      } else
       {
         
this.dir 0;
       }
    }
}   };
  } 


killerogue 05-05-2007 12:22 AM

*Sigh*.

1.) THIS IS THE MOST IMPORTANT PART. I WANT YOU TO READ, UNDERSTAND AND REMEMBER THIS WHILE YOU ARE ATTEMPTING TO CRITICIZE OTHER'S EFFORTS.

GS1 != GS2, IT'S NOT GOOD FOR COMPATIBILITY.

:) Now on, to the second part.

I would suggest actually putting the baddy in a damn class and then adding that weapon to the player and putnpc2 the class.

godofwarares 05-05-2007 12:24 AM

Quote:

Originally Posted by theHAWKER (Post 1305529)
*Code*

Rofl!

How embarrassing for you! Hybridized scripts = Bad.

More to the point,
Try putting it in a class on RC and use the code putnpc2 x, y, "join baddyclass;"; to put it on the field.

Gambet 05-05-2007 12:31 AM

O_O


Wow.....


That's not how you do it at all x-x


You need to set up the baddy script as a class and then putnpc2 with the npc joining the classname that contains my baddy script.

theHAWKER 05-05-2007 12:33 AM

so like make an npc in the level saying join baddyclass;
then i make a class, and in the class i put the putnpc2 playerx,playery(*script*)

is that right?

xXziroXx 05-05-2007 12:34 AM

Use GS2!!

putnpc2(player.x, player.y, "join(\"classname\");");

killerogue 05-05-2007 12:43 AM

No, you make the class through RC. And then use putnpc2 through something like player chats then triggeraction. Or even a public function.

By the way, PUTNPC2 IS SERVERSIDE.

Edit: YOU HAVE THE MEANS TO LEARN A MUCH SIMPLER LANGUAGE CALLED Gscript2, WHY DO YOU NOT UTILIZE THEM TO NOT BURN OUR EYES OUT EVERY TIME YOU POST.

theHAWKER 05-05-2007 12:46 AM

nah it wont work eaven with just if (created)
:(

xXziroXx 05-05-2007 12:47 AM

Quote:

Originally Posted by theHAWKER (Post 1305542)
nah it wont work eaven with just if (created)
:(

Have to be serverside.

killerogue 05-05-2007 12:49 AM

Quote:

Originally Posted by theHAWKER (Post 1305542)
nah it wont work eaven with just if (created)
:(

MAYBE YOU OUGHT TO ACTUALLY READ AND TRY TO UNDERSTAND WHAT PEOPLE TELL YOU.

IF WE ARE SAYING IT IS SERVERSIDE ONLY, WHY WOULD ONCREATED MAKE A DIFFERENCE?

theHAWKER 05-05-2007 12:50 AM

stop spazzing out....
i just took out the celent side and that makes it server side, right?

Bl0nkt 05-05-2007 12:59 AM

Quote:

// NPC made by theHAWKER
LOL

cbk1994 05-05-2007 01:00 AM

Quote:

Originally Posted by theHAWKER (Post 1305545)
stop spazzing out....
i just took out the celent side and that makes it server side, right?

Look, your code is ****. You took great code from Gambet, erased his name and put your own on it, and then cry to us when it doesn't work.

Firstly, IT IS SERVERSIDE!

Secondly, MAKE A CLASS!

Thirdly, DO NOT MIX GS1 AND GS2!

Go to RC, go to classes, than create a new class. Name it "baddy". In that class, put Gambet's GBaddy. Then put this in a level.

PHP Code:

function onPlayerChats()
{
  if ( 
player.chat == "/baddy" )
  {
    
putnpc2player.xplayer.y"join( \"baddy\" ); ");
  }


Please take the time to look at the wiki and learn GS2, then maybe we won't all have to cry whenever you post.

EDIT:

Quote:

Originally Posted by Bl0nkt (Post 1305548)
LOL

I second that.

killerogue 05-05-2007 01:04 AM

Quote:

Originally Posted by theHAWKER (Post 1305545)
stop spazzing out....
i just took out the celent side and that makes it server side, right?

It's not the fact I'm spazzing out, it's the fact that if you're asking people questions like the latter, then I suggest you take some time out to actually study before you dive right in.

Now where's Inverness to tell me I need to learn to script first?

cbk1994 05-05-2007 01:09 AM

Quote:

Originally Posted by killerogue (Post 1305551)
It's not the fact I'm spazzing out, it's the fact that if you're asking people questions like the latter, then I suggest you take some time out to actually study before you dive right in.

Now where's Inverness to tell me I need to learn to script first?

Don't worry, he's coming. I called him on my gPhone.


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

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