Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 05-05-2007, 12:58 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
whats the point of putting this here unless u want people to use it?
__________________
**FLIP OUT**
Reply With Quote
  #3  
Old 05-05-2007, 01:17 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by theHAWKER View Post
whats the point of putting this here unless u want people to use it?
Hi, I believe I speak for all of us here in the NPC Scripting forum when I say that you cannot script. You seem to think that it is okay to take other peoples scripts, put your name on it and take all of the credit, and then complain when they don't work, and say it is all somebody else's fault. Please stop waisting my time, and all of our time. You are very good at wasting posts, and that is what you have just done. killerouge posted this script because it is considered code and it is in the Code Gallery. He posted the code in the Code Gallery in hopes that people like you would be able to learn from it. There are no rules that state he has to encourage people to use this script. If you want to use this script, go ahead and use it. If it does not work, then please do not come complain to killerouge, because he has worked hard on this project, and is continuing to do so. You are not obliged to use this code, so by all means DO NOT USE IT IF YOU DO NOT LIKE IT!

Very nice script, killerouge, I hope people like theHAWKER can learn from this, and perhaps if it gets some more features, I may even use it on my server!

Chris
__________________
Reply With Quote
  #4  
Old 05-05-2007, 01:22 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by cbkbud View Post
Hi, I believe I speak for all of us here in the NPC Scripting forum when I say that you cannot script. You seem to think that it is okay to take other peoples scripts, put your name on it and take all of the credit, and then complain when they don't work, and say it is all somebody else's fault. Please stop waisting my time, and all of our time. You are very good at wasting posts, and that is what you have just done. killerouge posted this script because it is considered code and it is in the Code Gallery. He posted the code in the Code Gallery in hopes that people like you would be able to learn from it. There are no rules that state he has to encourage people to use this script. If you want to use this script, go ahead and use it. If it does not work, then please do not come complain to killerouge, because he has worked hard on this project, and is continuing to do so. You are not obliged to use this code, so by all means DO NOT USE IT IF YOU DO NOT LIKE IT!

Very nice script, killerouge, I hope people like theHAWKER can learn from this, and perhaps if it gets some more features, I may even use it on my server!

Chris
Well said!
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #5  
Old 05-05-2007, 02:00 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
killerouge, I never quite understood what enum did, and what it can be used for. Care to explain?
__________________
Reply With Quote
  #6  
Old 05-05-2007, 02:02 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
it says that u cant use it, so i was wondering why he put it here
__________________
**FLIP OUT**
Reply With Quote
  #7  
Old 05-05-2007, 02:03 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by theHAWKER View Post
it says that u cant use it, so i was wondering why he put it here
He never said you can't use it. He advised you not to, because it was not finished.
__________________
Reply With Quote
  #8  
Old 05-05-2007, 03:14 AM
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
Quote:
Originally Posted by cbkbud View Post
killerouge, I never quite understood what enum did, and what it can be used for. Care to explain?
It's almost like an array, but I tend to call it an object moreso because it can be used like this:

PHP Code:
function onCreated()
{
  
enum people {
    
Chris,
    
Ziro,
    
Stan
  
}

  if ( 
player.headimg == "head105.png" )
  {
    
temp.person people.Chris;
  }

Quote:
Originally Posted by theHAWKER View Post
whats the point of putting this here unless u want people to use it?
You have no clue how much I was waiting for you to post something this idiotic.

In my post I clearly stated it was free to use when I had finished the actual product. I put it here so that people like you may learn from it and also to get some constructive criticism from people who can actually script.
__________________


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.
Reply With Quote
  #9  
Old 05-05-2007, 04:06 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
enumerators auto-assign integers to the variable. ( I don't think you should use them inside events, or functions. I don't in C++, at least. )

PHP Code:
enum MENU
{
  
FILE,// 0
  
NEW, // 1
  
END  // 2
};

function 
onCreated() {
  echo(
"File: " MENU.FILE); // Output: File: 0
  
echo("New: " MENU.NEW);   // Output: New: 1
  
echo("End: " MENU.END);   // Output: End: 2

It should work that way.
__________________
- Zidane / Zidaya
Reply With Quote
  #10  
Old 05-05-2007, 05:07 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Enum is useful because it can be used in ways like this:
PHP Code:
enum key{
F9 122,
F10 123,
F11 124
}

function 
onKeyPressed(codekey)
{
  if (
code in {key.F9key.F10key.F11})
    
do_something();

Reply With Quote
  #11  
Old 05-05-2007, 05:31 AM
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
Quote:
Originally Posted by Rapidwolve View Post
Enum is useful because it can be used in ways like this:
PHP Code:
enum key{
F9 122,
F10 123,
F11 124
}

function 
onKeyPressed(codekey)
{
  if (
code in {key.F9key.F10key.F11})
    
do_something();

I didn't know it could be used that way, of course I just found out you can make assignments to the enums but that's news to me.

Of course this makes it seem more and more like an array! But easier to remember and such in the fact that it's more so, enumname.stuff rather than array[0].

Can you add things to enumerators through function?
__________________


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.
Reply With Quote
  #12  
Old 05-05-2007, 05:45 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
PHP Code:
enum key{
F9 122,
F10 123,
F11 124

I'd prefer doing this since I see no apparent difference:

PHP Code:
this.key = new TStaticVar();
this.key.F9 122;
this.key.F10 123;
this.key.F11 124
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #13  
Old 05-05-2007, 06:07 AM
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
Quote:
Originally Posted by xXziroXx View Post
PHP Code:
enum key{
F9 122,
F10 123,
F11 124

I'd prefer doing this since I see no apparent difference:

PHP Code:
this.key = new TStaticVar();
this.key.F9 122;
this.key.F10 123;
this.key.F11 124
Hmm...never thought about making a key list an object.


Anyway, back on topic! Can I get a few opinions here?
__________________


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.
Reply With Quote
  #14  
Old 05-05-2007, 07:15 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Enumerators are mainly for auto-assigning integers, I would prefer something like xXziroXx said for the keys. ( Though I think you wouldn't be required to set it as a new TStaticVar(), unsure though )
__________________
- Zidane / Zidaya
Reply With Quote
  #15  
Old 05-05-2007, 08:45 AM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by Rapidwolve View Post
Enum is useful because it can be used in ways like this:
PHP Code:
enum key{
F9 122,
F10 123,
F11 124
}

function 
onKeyPressed(codekey)
{
  if (
code in {key.F9key.F10key.F11})
    
do_something();

I'd just do this:

HTML Code:
function onKeyPressed(characterCode)
{
  temp.codesNeeded = {122, 123, 124};
  if (temp.codesNeeded.index(temp.characterCode) != -1)
  {
    this.doPressed(temp.characterCode);
  }
  //Or
  if (temp.characterCode in |122, 124|)
  {
    this.doPressed(temp.characterCode);
  }
  //Or even
  if (temp.characterCode in {122, 123, 124})
  {
    this.doPressed(temp.characterCode);
  }
}
I think making it an enum is pretty pointless...
Reply With Quote
  #16  
Old 05-05-2007, 12:12 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by xXziroXx View Post
PHP Code:
enum key{
F9 122,
F10 123,
F11 124

I'd prefer doing this since I see no apparent difference:

PHP Code:
this.key = new TStaticVar();
this.key.F9 122;
this.key.F10 123;
this.key.F11 124
Exactly. Enumerators are completely pointless in my book!
__________________
Do it with a DON!
Reply With Quote
  #17  
Old 05-05-2007, 03:03 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Back on topic, this is a pretty good base of a script. Needs a bit more meat on its bones before it's ready to be used though.
__________________
Reply With Quote
  #18  
Old 05-05-2007, 03:25 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
I also think enumerators are pointless, I had a talk about this on RC before, I use them because I think it makes my code look cleaner.
Reply With Quote
  #19  
Old 05-05-2007, 03:38 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
They can be useful if you know how to use them well. Stuff like using enums for every month of the year. Gives them the appropriate monthly number. Can also be used for things like colours. It may be easier to use 'purple' rather than a 3 in code.

Another example could be parameters. Say a function takes an integer as a parameter to change the object. For instance, a baddy and it's mode. It may be easier for people to understand if they send 'attack' rather than a 3 as a parameter. In essence, the number 3 will still be sent as the parameter but the code will make more sense for the programmer.

Enums are a method of documentation. They have there uses. I think it's much more efficient to use enums to represent integer values rather than creating a TStaticVar() for them.

Last edited by Twinny; 05-05-2007 at 03:49 PM..
Reply With Quote
  #20  
Old 05-05-2007, 05:10 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Enums are not pointless.
Reply With Quote
  #21  
Old 05-06-2007, 01:57 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Twinny View Post
They can be useful if you know how to use them well. Stuff like using enums for every month of the year. Gives them the appropriate monthly number. Can also be used for things like colours. It may be easier to use 'purple' rather than a 3 in code.

Another example could be parameters. Say a function takes an integer as a parameter to change the object. For instance, a baddy and it's mode. It may be easier for people to understand if they send 'attack' rather than a 3 as a parameter. In essence, the number 3 will still be sent as the parameter but the code will make more sense for the programmer.

Enums are a method of documentation. They have there uses. I think it's much more efficient to use enums to represent integer values rather than creating a TStaticVar() for them.
How about posting examples how it can be useful.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
Reply


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:58 PM.


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