Blockland Forums > Modification Help
Giving a projectile constant AoE?
(1/2) > >>
zmaster:
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.
Ipquarx:
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: ---$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);
}
--- End code ---
otto-san:
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?
Ipquarx:

--- Quote from: otto-san on April 11, 2012, 06:25:44 PM ---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.
--- End quote ---
This script is so simple, it would take doing it 1000 times a second to make a noticable difference in performance.
otto-san:

--- Quote from: Ipquarx on April 11, 2012, 06:40:15 PM ---This script is so simple, it would take doing it 1000 times a second to make a noticable difference in performance.

--- End quote ---
I tend to underestimate how fast Torque is a lot, so that wouldn't surprise me.
Navigation
Message Index
Next page

Go to full version