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( 1 );
}
function onTimeOut()
{
if ( temp.mode != MODE_WALK )
{
temp.ranX = int( random( -10, 10 ) );
temp.ranY = int( random( -10, 10 ) );
setcharani( "walk", NULL );
move( temp.ranX, temp.ranY, 1, ( 0 + 4 + 16 ) );
temp.mode = MODE_WALK;
}
else
{
setcharani( "idle", NULL );
temp.mode = MODE_IDLE;
this.doInitScan();
}
setTimer( 1 );
}
function doInitScan()
{
for ( p: findNearestPlayer( this.x, this.y ) )
{
if ( temp.mode != MODE_SCAN )
{
temp.mode = MODE_SCAN;
if ( p.x in | this.x - 10, this.x + 10 | )
{
if ( p.y in | this.y - 10, this.y + 10 | )
{
this.doInitTrack();
}
}
else
{
setTimer( 1 );
}
}
}
}
function doInitTrack()
{
if ( temp.mode != MODE_TRACK )
{
temp.mode = MODE_TRACK;
//tracking stuff
for ( plyr: findNearestPlayer( this.x, this.y ) )
{
if ( plyr.x in ( this.x + 1 + vecx( dir ) * 2 ) || plyr.y in ( this.y - 1 + vecy( dir ) * 2 ) )
{
this.doInitAttack();
}
}
}
else
{
for ( pl: findNearestPlayer( this.x, this.y ) )
{
if ( ! ( pl.x in | this.x - 10, this.x + 10| ) )
{
if ( ! ( pl.y in | this.y - 10, this.y + 10 | ) )
{
setTimer( 1 );
}
}
}
}
}
function doInitAttack()
{
if ( temp.mode != MODE_ATTACK )
{
temp.mode = MODE_ATTACK;
temp.ranRoll = int( random( 0, 90 ) );
if ( temp.ranRoll in | 0, 31 | )
{
//dothis
}
else if ( temp.ranRoll in | 31, 60 | )
{
//then do this
}
else
{
//then finally do this
}
}
else
{
if( pl.x in | this.x - 10, this.x + 10 | && ( ! ( pl.x in ( this.x + 1 + vecx( dir ) * 2 ) ) && ( pl.y in ( this.y - 1 + vecy( dir ) * 2 ) ) ) )
{
this.doInitTrack();
}
else
{
if ( ! ( pl.x in | this.x - 10, this.x + 10 | ) )
{
if ( ! ( pl.y in | this.y - 10, this.y + 10 | ) )
{
setTimer( 1 );
}
}
}
}
}
function onWa****()
{
if ( ( this.hearts - 1 ) > 0 )
{
this.hearts -= 1;
setcharani( "hurt", NULL );
switch ( dir )
{
case "0":
if ( ! ( onwall( this.x + 3, this.y ) ) )
{
this.x + 3;
}
break;
case "1":
if( ! ( onwall( this.x, this.y + 3 ) ) )
{
this.y + 3;
}
break;
case "2":
if( ! ( onwall( this.x - 3, this.y ) ) )
{
this.x - 3;
}
break;
case "3":
if( ! ( onwall( this.x, this.y - 3 ) ) )
{
this.y - 3;
}
break;
}
}
else
{
temp.mode = MODE_DEAD;
this.doInitRespawn();
}
}
function doInitRespawn()
{
if ( temp.mode != MODE_RESPAWN )
{
temp.mode = MODE_RESPAWN;
setcharani( "somerespawnani", NULL );
this.x = this.x += 1;
this.y = this.y += 1;
setcharani( "idle", NULL );
for ( ply: findNearestPlayer( this.x, this.y ) )
{
if( ply.x in | this.x - 5, this.x + 5 | )
{
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.