PDA

View Full Version : Range Checks


killerogue
04-22-2007, 04:27 AM
Hello! I was working on RC with Chandler earlier today and I came up with these distance checks.

I needed them for a few things and I thought it might be awesome to let the public be able to use them as well.

=]

The class checks for the NPC can be changed as you wish. There is another function to this set. But I have not completed it yet, so when I do I'll make sure to post it here! =D


public function playerInRange()
{
for ( pl: players )
{
if ( pl.x in this.getPlayerVec( 2, 2 )[0] )
{
if ( pl.y in this.getPlayerVec( 2, 2 )[1] )
{
return true;
}
}
else
{
return false;
}
}
}


public function enemyInRange()
{
for ( cl: findareanpcs( this.getPlayerVec( 10, 10 )[0], this.getPlayerVec( 10, 10 )[1], 64, 64 ) )
{
if ( cl.isinclass( "mud_enemyfunctions" ) )
{
if ( cl.x in this.getVec( 2, 2 )[0] )
{
if ( cl.y in this.getVec( 2, 2 )[1] )
{
return true;
}
}
else
{
return false;
}
}
}
}


public function getPlayerVec( xDist, yDist )
{
temp.dx = player.x + 1 + vecx( player.dir ) * temp.xDist;
temp.dy = player.y - 1 + vecy( player.dir ) * temp.yDist;

return ( { temp.dx, temp.dy } )
}

Twinny
04-22-2007, 08:36 AM
Ahh

if ( cl.isinclass( "mud_enemyfunctions" ) )


Probably shouldn't be in a public function. Or atleast have a comment explaining what to do with it.

Chandler
04-22-2007, 09:18 AM
cool script

killerogue
04-22-2007, 10:05 AM
Thanks Chandler and Twinny.

Oh yeah, got to start commenting things, sorry 'bout that.

theHAWKER
04-23-2007, 01:58 AM
i dont understand what its for c.c

killerogue
04-23-2007, 03:06 AM
For checking if an npc such as a class, or a player is within a certain distance. I've created for use on my playerworld specifically for my battle system.