Author Topic: Giving a projectile constant AoE?  (Read 730 times)

Is there a way to give a projectile an AoE (Area of Effect) that lasts for the whole life of the projectile without constantly spawning explosions?  For example a projectile that spwans shockwaves but does no direct damage.

I made this a while back to make a projectile explode if a player was within a certain radius of it.
I fixed it up a bit as it was messy before, just replace (imagenamehere) with the weapons imagename, and it *should* work fine.

the 5 / in lines 9 and 26 is how many seconds you want it to check for a player within a certain radius. For example, the 5 would make it check for 5 seconds. Feel free to change that if you want.

$Pref::Server::ExpSamples is how many times within that time frame that it will check for a player within the given radius, it's set to 50 by default, you shouldn't need to set it much, or any higher than that.

$Pref::Server::ExplodeDistance is the radius to check for. If a player is within this radius of the projectile, it will explode. It's set to 3 by default. This can be set to anything that isn't negative, really.

I'm sure you can adapt that to work with just damaging people, rather than exploding the projectile, but it's very close to what you wanted.

The code:
Code: [Select]
$Pref::Server::ExpSamples = 50;
$Pref::Server::ExplodeDistance = 3;

function (imagenamehere)::onFire(%this, %obj, %slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
%projectile = parent::onFire(%this,%obj,%slot);
%c = 5 / $Pref::Server::ExpSamples * 1000;
schedule(%c+500, 0, "rpl_doExpCheck", %projectile, "1");
}

function rpl_doExpCheck(%proj, %checknum)
{
if(!isObject(%proj))
return;
for(%a = 0; %a < ClientGroup.getCount(); %a++)
{
%player = ClientGroup.getObject(%a).player;
if(vectorDist(%player.position, %proj.position) < $Pref::Server::ExplodeDistance)
{
%proj.explode();
return;
}
}
schedule(5 / $Pref::Server::ExpSamples * 1000 + 500, 0, "rpl_doExpCheck", %proj, %checknum + 1);
}

Not sure which would be worse, looping through every client in the server and checking distance every so often, or doing a container search every so often. Probably the latter, but that's just a guess.

I guess it really just depends on certain conditions?

Not sure which would be worse, looping through every client in the server and checking distance every so often, or doing a container search every so often.
This script is so simple, it would take doing it 1000 times a second to make a noticable difference in performance.

This script is so simple, it would take doing it 1000 times a second to make a noticable difference in performance.
I tend to underestimate how fast Torque is a lot, so that wouldn't surprise me.

I tend to underestimate how fast Torque is a lot, so that wouldn't surprise me.
Considering torques speed, and the fact that I needed to make my own multiplication function, I managed to:
  • Calculate 50 decimal places of the square root of almost any number in 6 seconds
  • Calculate the factorials of 2 all the way through 1500 in 15 seconds
  • and calculate 100 hex digits of pi in around 10 seconds.

    So yeah, it'll be fine to run on any server, no matter how packed it may be.

Considering torques speed, and the fact that I needed to make my own multiplication function, I managed to:
  • Calculate 50 decimal places of the square root of almost any number in 6 seconds
  • Calculate the factorials of 2 all the way through 1500 in 15 seconds
  • and calculate 100 hex digits of pi in around 10 seconds.

    So yeah, it'll be fine to run on any server, no matter how packed it may be.

WORD!!