Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-04-2007, 11:25 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
[WIP] Enemy (Baddy) System

Baddy System V.1


So, hey guys! I've actually had the chance to start scripting and working with enemies and ai and the sort and have really been having fun doing it.

I'm currently working on a project, ( yes one of the same projects I always bounce back and for between ) which requires me to do so. However, I wanted to be a bit inventive in what I was doing about it. So I figured I'd use text files and a public function in the database.

I eventually hope to release alot of the things from my project scriptwise for learning purposes and to make life easier for those who lack scripters on their up and coming servers and such. I doubt any scripts I've made custom to my project will help you must in terms of copy and pasting to use it, but it might help you le

arn something and that's what I want to do ( we need more scripters! ).

Here, I can only post the actual class part first as I haven't gotten around to doing the loading of the text file and setting the vars, as well as doing a custom attack system. So for this purpose I use "wa****", as well as regular Graal head and body.

Keep in mind that this system is being debugged and you should NOT use it, I posted it here as to show what I'm doing so far, what I plan to do and to get major feedback and some opinions as well.

--- Plans ---

1.) Get everything that can be done with regular Graal finished up completely.
2.) Finish the loading of the file and setting of the appropriate ani.
3.) Get the AI worked on a bit more and perfected as much as possible.


As said this is not the only file based AI I plan to release as a package from my project, but for the most part if you have any questions just AIM me.

So without further ado, here's the, in progress, class for the enemy:

PHP Code:
/*

  For now I shall set the baddy with regular npc vars.
  
*/

function onCreated()
{
  
enum 
  
{
    
MODE_IDLE,
    
MODE_WALK,
    
MODE_SCAN,
    
MODE_TRACK,
    
MODE_ATTACK,
    
MODE_DEAD,
    
MODE_RESPAWN
  
};
  
  
this.doInitEnemy();
}

function 
doInitEnemy()
{
  
//To Do:
  //Load Vars and set Enemy Type and Look
  
  //Note:
  //For now I'll use regular Graal looks.
  
  
this.showCharacter();
  
this.headimg "head10.png";
  
this.bodyimg "xantanbody1.png";
  
this.shieldimg "no-shield.png";
  
  
temp.mode MODE_IDLE;
  
  
setTimer);
}

function 
onTimeOut()
{
  if ( 
temp.mode != MODE_WALK )
  { 
    
temp.ranX intrandom( -1010 ) );
    
temp.ranY intrandom( -1010 ) );
    
    
setcharani"walk"NULL );
    
movetemp.ranXtemp.ranY1, ( 16 ) );
    
    
temp.mode MODE_WALK;
  }
  
  else
  { 
    
setcharani"idle"NULL );
    
    
temp.mode MODE_IDLE;
    
this.doInitScan();
  }
  
  
setTimer);
}

function 
doInitScan()
{
for ( 
pfindNearestPlayerthis.xthis.) )
  {
    if ( 
temp.mode != MODE_SCAN )
    {
      
temp.mode MODE_SCAN;
      
      if ( 
p.x in this.10this.10 | )
      {
        if ( 
p.y in this.10this.10 | )
        {
          
this.doInitTrack();
        }
      }
      
      else
      {
        
setTimer);
      }
    }
  }
}

function 
doInitTrack()
{
  if ( 
temp.mode != MODE_TRACK )
  {
    
temp.mode MODE_TRACK;
    
//tracking stuff
    
    
for ( plyrfindNearestPlayerthis.xthis.) )
    {
      if ( 
plyr.x in this.vecxdir ) * ) || plyr.y in this.vecydir ) * ) )
      {
        
this.doInitAttack();
      }
    }
  }
  
  else
  {
    for ( 
plfindNearestPlayerthis.xthis.) )
    {
      if ( ! ( 
pl.x in this.10this.10| ) )
      {
        if ( ! ( 
pl.y in this.10this.10 | ) )
        {
          
setTimer);
        }
      }
    }
  }
}

function 
doInitAttack()
{
  if ( 
temp.mode != MODE_ATTACK )
  {
    
temp.mode MODE_ATTACK;
    
    
temp.ranRoll intrandom090 ) );
    
    if ( 
temp.ranRoll in 031 | )
    {
      
//dothis
    
}
    
    else if ( 
temp.ranRoll in 3160 | )
    {
      
//then do this
    
}
    
    else
    {
      
//then finally do this
    
}
  }
  
  else
  {
    if( 
pl.x in this.10this.10 | &&  ( ! ( pl.x in this.vecxdir ) * )  ) && ( pl.y in this.vecydir ) * ) ) ) ) 
    {
      
this.doInitTrack();
    }
    
    else
    {
      if ( ! ( 
pl.x in this.10this.10 | ) )
      {
        if ( ! ( 
pl.y in this.10this.10 | ) )
        {
          
setTimer);
        }
      }
    }
  }
}

function 
onWa****()
{
  if ( ( 
this.hearts ) > )
  {
    
this.hearts -= 1;
    
setcharani"hurt"NULL );
    
    switch ( 
dir )
    {
      case 
"0":
        if ( ! ( 
onwallthis.3this.) ) )
        {
          
this.3;
        }
      break;
      
      case 
"1":
        if( ! ( 
onwallthis.xthis.) ) )
        {
          
this.3;
        }
      break;
      
      case 
"2":
        if( ! ( 
onwallthis.3this.) ) )
        {
          
this.3;
        }
      break;
      
      case 
"3":
        if( ! ( 
onwallthis.xthis.) ) )
        {
          
this.3;
        }
      break;
    }
  }
  
  else
  {
    
temp.mode MODE_DEAD;
    
    
this.doInitRespawn();
  }
}

function 
doInitRespawn()
{
  if ( 
temp.mode != MODE_RESPAWN )
  {
    
temp.mode MODE_RESPAWN;
    
setcharani"somerespawnani"NULL );
    
    
this.this.+= 1;
    
this.this.+= 1;
    
    
setcharani"idle"NULL );
    
    for ( 
plyfindNearestPlayerthis.xthis.) )
    {
      if( 
ply.x in this.5this.| )
      {
        
this.doInitAttack();
      }
    
      else
      {
        
this.doInitScan();
      }
    }
  }


Upon the final version everything, necessary, will be commented and I was have a guide or something about using it.

The distance checks and hurt section was a part borrowed from Gambet. I also had some help from Joey's old baddy script.



Crits would be nice and appreciated.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.

Last edited by killerogue; 05-04-2007 at 11:26 PM.. Reason: Missed a G! :O
Reply With Quote
 


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 12:48 PM.


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