Author Topic: Killer location is impossible to acccess  (Read 1266 times)

Part of my current project involves doing something at the killer's location when he kills someone. I couldn't find a specific "onKill" function, so I took GameConnection::onDeath. Here is a small section of the script, which is inside a package in which other overwritten scripts work just fine:
Code: [Select]
function GameConnection::OnDeath(%this, %killerPlayer, %killer, %damageType, %damageLoc)
{
ServerPlay3D(killSound, %killerPlayer.getPosition());
Parent::OnDeath(%this, %killerPlayer, %killer, %damageType, %damageLoc);
}
I have tried every imaginable combination of using %this, %killerplayer, and %killer to try and play a sound at the killer when a player dies. But it either throws errors or plays it at the victim instead. I gave this problem to some of my more experienced friends and we tried all sorts of combinations and it still didn't work.
What's going wrong? Am I missing something obvious?

%this.player.getPosition();

That's the person who was killed.

try dumping %killerPlayer and %killer, maybe they are not of the player class for whatever reason

%this.player.getPosition();

That's the person who was killed.
No, I want the killer, not the killed.

try dumping %killerPlayer and %killer, maybe they are not of the player class for whatever reason
The class of %killerPlayer is Player, and %killer is a GameConnection.

No, I want the killer, not the killed.
The class of %killerPlayer is Player, and %killer is a GameConnection.

So what does %killer.player do?

Code: [Select]
function GameConnection::OnDeath(%this, %killerPlayer, %killer, %damageType, %damageLoc)
{
ServerPlay3D(killSound, %killerPlayer.getPosition());
Parent::OnDeath(%this, %killerPlayer, %killer, %damageType, %damageLoc);
}
If I remember correctly (because I've run into an issue similar to this), %killerPlayer is a misnomer since it's more like %killerSource meaning it's sometimes a projectile. This would mean it plays it at the projectile (which may no longer exist and or is at the player). If you're bent on using %killerPlayer, re-write it to be %killerPlayer.client.player (Projectiles have a client property that ties them to the client that owns them) or just go for the easier alternative,
%killer.player

If I remember correctly (because I've run into an issue similar to this), %killerPlayer is a misnomer since it's more like %killerSource meaning it's sometimes a projectile. This would mean it plays it at the projectile (which may no longer exist and or is at the player). If you're bent on using %killerPlayer, re-write it to be %killerPlayer.client.player (Projectiles have a client property that ties them to the client that owns them) or just go for the easier alternative,
Okay, now it's working. Thank you. I swear I tried that earlier but I think it was when I was using bots/Self Delete and not other players. I hosted a server and it worked fine.

Out of curiosity, what is a more correct way of naming the variables present in GameConnection::OnDeath's parameters? I've seen a huge variety from all the sources I looked at. Also, when a bot kills me it throws an error, how can I check for this and skip the function if I die from a clientless bot?
« Last Edit: May 20, 2015, 04:58:10 PM by Narkro555 »

Okay, now it's working. Thank you. I swear I tried that earlier but I think it was when I was using bots/Self Delete and not other players. I hosted a server and it worked fine.

Out of curiosity, what is a more correct way of naming the variables present in GameConnection::OnDeath's parameters? I've seen a huge variety from all the sources I looked at. Also, when a bot kills me it throws an error, how can I check for this and skip the function if I die from a clientless bot?
Use the function isObject() to determine if the client is a thing, and if it isn't, don't run your code.

I'd personally use function GameConnection::OnDeath(%this, %damageSource, %killer, %damageType, %damageLoc)
Damage source may be more ambiguous but it's less confusing from the standpoint that it doesn't claim it's a player. It also can be easier to understand if you think it from a literal standpoint. On his death, %client died from a %damageSource originating from the %killer being dealt damage as %damageType at %damageLoc.
In the end, it's all preference and you're free to name it whatever you like.

Use the function isObject() to determine if the client is a thing, and if it isn't, don't run your code.

I'd personally use function GameConnection::OnDeath(%this, %damageSource, %killer, %damageType, %damageLoc)
Damage source may be more ambiguous but it's less confusing from the standpoint that it doesn't claim it's a player. It also can be easier to understand if you think it from a literal standpoint. On his death, %client died from a %damageSource originating from the %killer being dealt damage as %damageType at %damageLoc.
In the end, it's all preference and you're free to name it whatever you like.
Excellent. Thank you very much.

Use the damage location for the sound.

Also, if you are making other death sounds. You can package Player::playDeathCry(%player)