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:
$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);
}