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-27-2009, 06:56 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
GBaddy v.2.0

You can find version one here.


Updates

. Code optimization: restyled the entire script to make it more legible (also added new comments and changed around some old), changed some this. vars to temp. vars where they better fit, and I added two new functions:

- healBaddy(amount) - heals the baddy for specified amount
- baddyReset() - resets baddy back to its starting position (automatically done when the baddy kills a player to prevent the player from getting constantly harassed by the baddy)

. Variable-value changes: changed some values such as the baddy's speed, amount of damage taken, and also played with the chance-probability of the baddy either attacking with its sword, causing an explosion, or healing itself

. Smarter AI: when a baddy is low in health, it will cycle through the other NPC's in the level to see if any of them are joined to the "public_gambet_gbaddy" class (which means you must either add this script to a class titled the same, or tweak this portion of the script), and if they are, they will then check to see if the baddies found are currently attacking the same player, if they aren't, then they will call those baddies to help fight the player.


Important: You will need to replace 'PERCENTSIGNHERE' with the actual percent symbol in lines 58 and 69 when uploading because the forums does not allow the posting of percent signs. Also, the function onWas.Hit() will need the period removed.


Graal Script Code:
/*
 *GBaddy - v.2.0
 *@author Gambet
*/

enum 
{
 
WALK,
 
ATTACK,
 
DEAD
}

function 
onCreated()
{
  
showcharacter();
  
this.bodyimg "body2.png";
  
this.shieldimg "no-shield.png";
  
this.nick "GBaddy";
  
this.ap 0;
  
this.health = {1010}; //{Current Health, Maximum Health}
  
this.mov_speed 0.45;
  
this.count int(random(1040));
  
this.start_coordinates = {this.xthis.y};
  
this.mode WALK;
  
  for (
a=0a<5a++) this.colors[a] = "black";
  if (
this.ani != "idle"setcharani("idle","");
  
  
setTimer(0.1);
}

function 
onPlayerEnters()
{
  
onTimeOut(); //Wake up the NPC (in case it was sleeping due to no players being in the level)
  
this.headimg "head" int(random(01000)) @ ".png"//NPC changes head image each time you enter the level
}

function 
onTimeOut()
{
 if (
players.size() > 0
   
setTimer(0.1);
  else
   
setTimer(0); //Sleep if no players in level
    
 
if (this.mode == WALK)
  {
   
this.to_check findnearestplayer(this.xthis.y);
   
temp.new_x this.vecx(this.dir) * this.mov_speed;
   
temp.new_y this.vecy(this.dir) * this.mov_speed;
   
this.count--;
    
   if (
this.count 0)
    {
      
temp.to_add_x new_x 1.5 vecx(this.dir);
      
temp.to_add_y new_y vecy(this.dir);
      
     if (
onwall(to_add_xto_add_y)) 
      
this.dir = (this.dir 2PERCENTSIGNHERE 4;
     else 
      {
       
setcharani("walk""");
       
this.new_x;
       
this.new_y;
      }
    } 
   else
    {
     
this.count int(random(1040));
     
this.dir = (this.dir int(random(02)) * 2PERCENTSIGNHERE 4;
    }
  }
 else 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_xthis.check_y this.add_y))
     {
      
damagePlayer();
      
moveBaddy();
     } 
    else if ((!
onwall(this.check_x this.add_xthis.check_y)) || (!onwall(this.check_xthis.check_y this.add_y))) 
     {
      
damagePlayer();
     }
    if ((
this.health[1] / 3) >= this.health[0]) //If low on health and other gbaddies in level, call for help
     
{
      for (
nnpcs)
       {
        if (
n.isinclass("public_gambet_gbaddy"))
         {
          if (
n.mode != ATTACK//Check to see if gbaddy isn't already attacking player
           
{
            
this.chat "Help!";
            
n.to_check this.plyr;
            
n.mode ATTACK;
           }
         }
       }
     }
   }
 if (
this.mode != DEAD)
  {
   if (
this.to_check.x in |this.x-10this.x+10| && this.to_check.y in |this.y-10this.y+10|)
    {
     if (
this.mode != ATTACKthis.mode ATTACK;
    } 
   else
    {
     
this.mode WALK;
    }
  }
  
 
setTimer(0.1); 
}

function 
moveBaddy()
{
 
setcharani("walk""");
 
this.+= this.add_x * (this.mov_speed 0.6);
 
this.+= 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;
  }


function 
damagePlayer()
{
 
temp.randomize int(random(0101));
 
temp.plyr findPlayer(this.plyr);

 if (
plyr.hearts 0)
  {
   if (
randomize in |092|) //Attack With Sword
     
setcharani("sword""");
   else if (
randomize in |9398|) //Cause Explosion
     
putexplosion2(33this.xthis.y);
   else if (
randomize in |99101|) //Heal
    
{
     if (
this.health[0] < this.health[1])
      {
       if ((
this.health[0] + 5) < this.health[1]) healBaddy(int(random(06)));
       else if ((
this.health[0] + 5) >= this.health[1]) healBaddy(this.health[1]);
      }
    }
  }
 else
  {
   
baddyReset();
  }


function 
healBaddy(amount)
{
 if ((
this.health[0] + amount) < this.health[1])
  {
   
this.health[0] += amount;
   
this.chat "*Healed for " amount "*";
  }
 else
  {
   
this.health[0] = this.health[1];
   
this.chat "*Fully Healed*";
  }
  
 
setcharani("lift""");
 
scheduleevent(1"HideChat""idle");
}

function 
baddyReset()
{
 
this.this.start_coordinates[0];
 
this.this.start_coordinates[1];
 
this.health[0] = this.health[1];
 
this.mode WALK;
}

function 
onWas.Hit() 
{
 if (
this.health[0] - ((player.swordpower 2) + 0.5) > 0)
  {
    if (
this.ani != "hurt")
     {
      
setcharani("hurt""");
      
scheduleevent(1"Counter""");
     }
     
    switch(
this.plyr.dir//Knockback
     
{
      case 
"2":
       if (!
onwall(this.xthis.3)) 
         
this.y+=3;
       break;
      case 
"0":
       if (!
onwall(this.xthis.3))
         
this.y-=3;
       break;
      case 
"1":
       if (!
onwall(this.3this.y))
         
this.-= 3;
       break;
      case 
"3":
       if (!
onwall(this.3this.y))        
         
this.x+=3;
       break;
     }
     
   
this.health[0] -= (player.swordpower 2) + 0.5;
   
this.chat this.health[0] @ "/" this.health[1];
   
scheduleevent(2"HideChat""");
  } 
 else
  {
   if (
this.mode != DEAD)
    {
     
this.mode DEAD;
     
this.health[0] = 0;
     
setcharani("dead""");
     
this.chat this.health[0] @ "/" this.health[1];
     
scheduleevent(8"Respawn""");
    }
  }
}

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

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

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

Reply With Quote
  #2  
Old 04-27-2009, 07:10 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Good stuff, as always .

Also, if you want to include an actual %, you can use this "percent transform." It's a funky way of posting percent signs, but they just wont fix it...
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #3  
Old 04-27-2009, 07:17 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by napo_p2p View Post
Good stuff, as always .

Also, if you want to include an actual, you can use this "percent transform." It's a funky way of posting percent signs, but they just wont fix it...

I just tried editing my original post with that and I still got that bad request error (I'm using the new Internet Explorer 8 Beta - I have Firefox as well, but I've been testing around the new I.E.), not sure if my browser has anything to do with it but I actually had to write this thread twice because of the percent problem.

The first time that I wrote this thread I had completely forgotten about the percent problem and I lost everything that I wrote, I even tried using the back button on my browser but all of the information was lost through the bad request. I made sure not to make the same mistake twice.

Thanks for the link, though, it's just really annoying to have to go through all this trouble.
Reply With Quote
  #4  
Old 04-27-2009, 07:04 PM
zephirot zephirot is offline
Banned?
Join Date: Sep 2004
Location: Paris
Posts: 1,311
zephirot is a name known to allzephirot is a name known to allzephirot is a name known to all
Send a message via AIM to zephirot Send a message via MSN to zephirot
Nice.
Is there any way to try out GS2 scripts offline? (I don't have access to any server)
__________________

Quote:
Originally Posted by unixmad
Can you just shut up ?
MAGA
MFGA
MEGA
Reply With Quote
  #5  
Old 04-27-2009, 07:19 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by zephirot View Post
Nice.
Is there any way to try out GS2 scripts offline? (I don't have access to any server)
No, but you could get access to the 'Testbed Server'. The Testbed Server is enabled for classic accounts and is meant for people who need a place to test out their scripts.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #6  
Old 04-27-2009, 07:34 PM
zephirot zephirot is offline
Banned?
Join Date: Sep 2004
Location: Paris
Posts: 1,311
zephirot is a name known to allzephirot is a name known to allzephirot is a name known to all
Send a message via AIM to zephirot Send a message via MSN to zephirot
Quote:
Originally Posted by napo_p2p View Post
No, but you could get access to the 'Testbed Server'. The Testbed Server is enabled for classic accounts and is meant for people who need a place to test out their scripts.
Oh I see, but I'm not a scripter myself, I just like to **** around with other peoples creations.
__________________

Quote:
Originally Posted by unixmad
Can you just shut up ?
MAGA
MFGA
MEGA
Reply With Quote
  #7  
Old 04-27-2009, 11:51 PM
Rufus Rufus is offline
Registered User
Join Date: Jun 2004
Location: United Kingdom
Posts: 4,698
Rufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud of
Would it be possible for you to record a video of your baddy functioning with the things that you've described? I'd be interested to see it, and don't really have a server I could just throw it on and test it.
__________________
Quote:
Originally Posted by Loriel View Post
Seriously, you have ****-all for content and you're not exactly pulling in new developer talent, angling for prestigious titles should be your last concern.
Reply With Quote
  #8  
Old 04-28-2009, 01:00 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
I added an attachment that contains an avi file straight from my videos folder of the GBaddy in action (more or less since I was lagging a bit due to my connection being split at the moment). I've never before used the video capturing feature that the new Graal version has, so my apologies if it's small or whatnot since I don't really know how to make it bigger.

Although you can't really tell from the video due to the small resolution, the baddies do walk around the level if there is no player within their attack radius.
Attached Files
File Type: zip GBaddy v.2.0 Video.zip (4.71 MB, 275 views)
Reply With Quote
  #9  
Old 04-28-2009, 12:01 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano can only hope to improve
Quote:
Originally Posted by Rufus View Post
Would it be possible for you to record a video of your baddy functioning with the things that you've described? I'd be interested to see it, and don't really have a server I could just throw it on and test it.
Testbed o_O?
Reply With Quote
  #10  
Old 04-28-2009, 06:55 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
nice work, and if u forget where the percent transform is, i have it in my sig.
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #11  
Old 04-28-2009, 06:59 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
Quote:
Originally Posted by Deas_Voice View Post
nice work, and if u forget where the percent transform is, i have it in my sig.
I prefer the Greasemonkey script
__________________
Reply With Quote
  #12  
Old 04-28-2009, 09:06 PM
Bell Bell is offline
Registered User
Bell's Avatar
Join Date: Feb 2007
Posts: 1,824
Bell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud of
Quote:
Originally Posted by Pelikano View Post
Testbed o_O?
http://forums.graalonline.com/forums...hlight=testbed

Its up of course. Just forum pm Tigairius about it if you have any questions.
__________________
For support contact
http://support.toonslab.com/
Reply With Quote
  #13  
Old 04-28-2009, 10:39 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Looks like fun!

Suggestionssss

It should victory dance when it kills! As well as taunt, and when he is aggro'd.

Could have a setup in the onCreated()

this.vocals_taunt = "y so bad";
this.vocals_victory = "come back when u r not suck";
this.vocals_aggrod = "cum get summmmm";
this.victorygani = "dance";

Also where you have the whole isinclass("public_gambet_gbaddy");
Could use a onCreated string as well.

this.classname = "public_gambet_gbaddy";

So anyone who uses it can use a different class name and figure out to change that right away.

Possibly tweak so it can use a longer timer instead of 0.1, however I don't think this is that important depending on how widespread it becomes.

The above should be worthy of a 2.1 release rep++
__________________
Quote:
Reply With Quote
  #14  
Old 04-28-2009, 10:43 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
My only complaint is that it basically runs into your sword a number of times before it attacks you back.
__________________
Save Classic!
Reply With Quote
  #15  
Old 04-29-2009, 04:54 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by Chompy View Post
I prefer the Greasemonkey script
>:0
tell gimmeh the script!
i nvr been good at greasemonkey..
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
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 11:28 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.