Author Topic: Proper kill message for delayed damage  (Read 1591 times)

I'm making a weapon that deals damage 2 seconds after the target is hit. Here is a snippet of code:

function gunASDFProjectile::onCollision(%this,%obj,%col,%fade,%pos,%norm)
{
   %col.schedule(2000,damage,%obj,%col.getPosition(),100,%this.directDamageType);

   Parent::onCollision(%this,%obj,%col,%fade,%pos,%norm);
}


The problem is that the person using the weapon is not credited with kills in the chat. I suspect this is because the projectile %obj no longer exists after 2000 ms. If so, what would be the optimal way to preserve the data of the projectile to pass into the damage function, and then delete it when it's no longer necessary?

Your suspicion is correct.

To fix this, you should create a temporary scriptobject, and assign it the following parameters from the projectile:
sourceObject
sourceClient
dataBlock (capitalization on this one may matter, assign %obj.getDatablock() to it)

Have it be created before running the schedule, and deleted on a schedule as well.


To fix this, you should create a temporary scriptobject, and assign it the following parameters from the projectile:
sourceObject
sourceClient
dataBlock (capitalization on this one may matter, assign %obj.getDatablock() to it)

Have it be created before running the schedule, and deleted on a schedule as well.
um

first off projectiles typically use the variable 'client' as the creating client
and instead of creating a temporary script object you can just source the damage from the client which works far better than creating a temporary script object everytime a projectile damages someone
Code: [Select]
%col.schedule(2000,damage,%obj.client,%col.getPosition(),100,%this.directDamageType);

Code: [Select]
%col.schedule(2000,damage,%obj.client,%col.getPosition(),100,%this.directDamageType);
I tried this, and the kill messages seem to work for players but not bots.

check if its a bot with
if(%obj.getClassName() $= "AiPlayer")

and then instead of %obj.client do %obj.sourceObject
if the bot somehow gets deleted before 2 seconds is up thats not really your fault since if a bot gets completely deleted before one of its projectiles hits a player it won't register properly even under normal circumstances (it will work if the bots corpse still exists)

I put a check so that in case of a bot being the killer it would use %obj.sourceObject, but the kill message still doesn't show the bot's name.

function gunASDFProjectile::onCollision(%this,%obj,%col,%fade,%pos,%norm)
{
   if(%obj.sourceObject.getClassName() $= "AiPlayer")
      %col.schedule(2000,damage,%obj.sourceObject,%col.getPosition(),100,%this.directDamageType);
   else
      %col.schedule(2000,damage,%obj.client,%col.getPosition(),100,%this.directDamageType);

   Parent::onCollision(%this,%obj,%col,%fade,%pos,%norm);
}


On further testing, it appears that kill messages are usually correct when the attacker is a player and either %obj (the projectile), %obj.sourceObject, or %obj.client is passed in to the damage method, provided that whatever is passed in still exists after 2 seconds. However, if the attacker is a bot, then neither %obj.sourceObject nor %obj.client will get a correct kill message, and only %obj works, as long as it exists.

How bad is it to be creating temporary script objects every time someone gets hit by the weapon's projectiles?

upon closer inspection this is entirely because of hole bots and blocklands stuffty damage code the kill message will only work on the projectile created by the bot, create a temporary script object but make sure its deleted after and obviously don't do that for if its a normal player


Have you tried just passing the projectile into the damage function (%obj)?

Also note that this goes around minigame checks so this will attack anyone outside of minigame.

Have you tried just passing the projectile into the damage function (%obj)?
It'll stop existing before the damage function is called.