Solved Track explosive owner

Discussion in 'Rust Development' started by KillParadise, May 11, 2015.

  1. Is there a route to take to track who threw a grenade, timed explosive, or fired a rocket so you can track who killed who with an explosive? Or is that a no go right now?
     
  2. I've add the OnWeaponThrown(BasePlayer player, BaseEntity entity) hook a while back so you could use that one.
     
  3. Thanks Mughisi. I'll see what I can do.
     
  4. Hello Mughisi, The OnWeaponThrown helped me to track the owner of all explosives except for the rockets. Do you know of anyway to do this? I was messing about and used a Raycast that went out from the rocket itself backwards. It detects the player almost all the time now, but if it explodes immediately, it may or may not detect the player. Is there any good way to track a rocket's owner at the moment, or has no one else tried? I can post my code if you want to see what I have for it, but it's messy. Just let me know if you want to see what I've got.
     
  5. In the hook's defense, a rocket is shot and not thrown ;) You should be able to grab the position of the rocket when it spawns and then just grab the player by using a spherecast or something, if a lot of players are in the spherecast it will grab multiple people though but you just need the cast to be just big enough to get the player and not anything else :p Or I might look into adding the hook OnFireRocket :p
     
  6. That's the problem I saw with a spherecast, so I use a raycast that shoots out of the rockets rear. If you manage to get OnFireRocket that would be great. xP
    [DOUBLEPOST=1432007761,1431813114][/DOUBLEPOST]For anyone that comes across this thread, I just added a pull request (#360) for OnRocketFired which functions the same way that OnWeaponThrown does. I'm hoping this will get merged, because if it does it means we will also be able to track rocket owners.
     
  7. Calytic

    Calytic Community Admin Community Mod

    Hold the phone, this is not solved. I can tell the owner of an explosive when the explosive is thrown, but I can't store the UID of the explosive and reference it OnEntityDeath to determine who threw what and who it killed.

    Please tell me I'm wrong and there is in-fact a way to grab a UID for explosives.

    As I understand it right now, even with the new hooks, there is NO WAY to determine who threw the explosive that killed you. This is reflected in DeathNotes that does not reveal the attacker. I spent a futile 3 hours researching the core and oxide which revealed nothing!

    The only way to do this is to track the position of who threw it and compare that that against the position of who died. However, this is unreliable and expensive as it requires a ton of processing and may blame multiple players for the same death!
     
  8. Code:
    [HookMethod("OnWeaponThrown")]
            void OnWeaponThrown(BasePlayer player, BaseEntity entity)
            {            entity.name = String.Format("{0}[{1}]", entity.name, player.userID); //Combines to create: item/timed.explosive.deployed(Clone)[76561198076504297]        }
    Code:
    if (hitInfo.Initiator.ToString().StartsWith("item"))
                    {
                        string[] attackerArray = hitInfo.Initiator.name.ToString().Split('/');
                        attacker = attackerArray[attackerArray.Length - 1]; //timed.explosive.deployed(Clone)[76561198076504297]                    if (hitInfo.Initiator.GetType().ToString().EndsWith("Explosive"))
                        {
                            string[] attackerArray2 = attacker.Split(new Char[] { '(', ')', '[', ']' }); //'timed.explosive.deployed' 'Clone' '' '76561198076504297' ''
                            weapon = attackerArray2[0]; //timed.explosive.deployed                        attackerID = attackerArray2[3]; //76561198076504297
                            attacker = BasePlayer.Find(attackerID).displayName; //tarper24
                        }
                    }
    This is code taken from my plugin that I'm currently working on. It works every time to track the owner of a thrown explosive. I also have added a hook for rockets locally. Once they add that hook, rockets will be able to be tracked in a similar manner. I only need to know the owner of the explosive, so I only attach the ID, but you could attach any information you wanted.

    I hope this helps clear things up on how you can use these hooks to track the owner, and other things, if you needed.
     
  9. Calytic

    Calytic Community Admin Community Mod

    Thank you very much tarper for your detailed and concise reply. This does address the issue and changing the entity name is very clever.

    While I expect it is simply an engine limitation, it is still impossible to determine exactly which entity is at fault (with no uid) though your solution does significantly reduce the likelihood of error and for that I appreciate it, thanks.