Get the name of the attacker

Hello,

i want to get the name of the attacker, like inside a game you can know the name of the killed player but the killer or the attacker i can't access it, is there anyone who was able to display it.

thank you in advance.
 
Yes, you can use the OnDeath event to get the name. This thread is from a bug report that has been fixed but it gives an example.

 
Yes, you can use the OnDeath event to get the name. This thread is from a bug report that has been fixed but it gives an example.

Hello Justin,

public void Awake()
{
Debug.Log("Here we are");
EventHandler.RegisterEvent<Vector3, Vector3, GameObject>(gameObject, "OnDeath", OnDeath);
}

/// <summary>
/// The object has died.
/// </summary>
/// <param name="position">The position of the force.</param>
/// <param name="force">The amount of force which killed the object</param>
/// <param name="attacker">The GameObject that killed the object</param>
public void OnDeath(Vector3 position, Vector3 force, GameObject attacker)
{
Debug.Log("The object " + gameObject.name + " died.");
if (attacker != null)
{
Instantiate(killMessageUI);
Debug.Log(gameObject.name + "Is Dead");
playerUI.KilledNickName.text = this.gameObject.GetComponent<PhotonView>().Owner.NickName;
playerUI.KillerNickName.text = attacker.GetComponent<PhotonView>().Owner.NickName;
Destroy(killMessageUI, 3f);



}

when there's no condition (means i don't put th if statment if(attacker != null) it gives back the name of the dead player, but the attacker name is alwys null (empty), can you please help me find the problem ?


thanks in advance;
 
I am not familiar with the NickName property - this is a PUN property so I recommend checking their docs on how to use it.
 
Hello Justin,

public void Awake()
{
Debug.Log("Here we are");
EventHandler.RegisterEvent<Vector3, Vector3, GameObject>(gameObject, "OnDeath", OnDeath);
}

/// <summary>
/// The object has died.
/// </summary>
/// <param name="position">The position of the force.</param>
/// <param name="force">The amount of force which killed the object</param>
/// <param name="attacker">The GameObject that killed the object</param>
public void OnDeath(Vector3 position, Vector3 force, GameObject attacker)
{
Debug.Log("The object " + gameObject.name + " died.");
if (attacker != null)
{
Instantiate(killMessageUI);
Debug.Log(gameObject.name + "Is Dead");
playerUI.KilledNickName.text = this.gameObject.GetComponent<PhotonView>().Owner.NickName;
playerUI.KillerNickName.text = attacker.GetComponent<PhotonView>().Owner.NickName;
Destroy(killMessageUI, 3f);



}

when there's no condition (means i don't put th if statment if(attacker != null) it gives back the name of the dead player, but the attacker name is alwys null (empty), can you please help me find the problem ?


thanks in advance;
What version are you on?, I believe this was fixed recently. I use a different method for handling this stuff, for me I like it to only happen on master, and it goes alot more in depth as to I collect info with the damage not the kill, I declare the kill via master only. You will see my MP work as an addon asset soon :)
 
I am not familiar with the NickName property - this is a PUN property so I recommend checking their docs on how to use it.
Attacker name is null or empty as the attacker is coming up null. But as stated I am sure you guys fixed this, I just never tested as I use my own methods.
 
I just tried the demo scene and attacked using the assault rifle. The attacker was correctly sent:

Attacked by: AtlasPun(Clone) (UnityEngine.GameObject)
UnityEngine.Debug:Log (object)
Opsive.UltimateCharacterController.Traits.Health:OnDamage (Opsive.UltimateCharacterController.Traits.Damage.DamageData) (at Assets/Opsive/UltimateCharacterController/Scripts/Traits/Health.cs:334)

With that said..
i'm using the final update of opsive
Are you referring to version 2 of the character controller? Version 2 is no longer supported and I am no longer fixing anything within that version.
 
This may help, but is designed around OnDamage and via master only. The same logic can be applied and will work, but for some complex stuff like my USC and Heli Addon I have since changed that to be solid for them assets also. (Relevant only to upcoming Ultimate Multiplayer Game Modes)
 
Top