Problem| problems with damage script

Options
I got that script:
the problem is that, when the gameobject that got tagged "bullet" hiiting the player, i got an errors...
using UnityEngine;
using System.Collections;

[RequireComponent (typeof(PhotonView))]
[RequireComponent (typeof(Rigidbody))]
public class HealthAndDamagess : MonoBehaviour {
   
   public float health = 100;
   public PhotonView photonView;
   public PhotonViewID photonViewID;
	
	public float dmg;
   
   void Start () {
      photonView = PhotonView.Get(this);
      photonViewID = photonView.viewID;
      Debug.Log("My view ID is: " + photonViewID);
   }
   
	void OnCollisionEnter(Collision other)
	{
			if ((other.transform.tag == "bullet"))
			{
	    		Debug.Log("bullet");
				dmg = 25;
				photonView.RPC("Damage", PhotonTargets.AllBuffered, dmg); 
			}
	}
	
   	[RPC]
   	void Damage(float dmg, PhotonViewID target, PhotonMessageInfo info) 
	{
      	Debug.Log ("RPC Recieved");
      	if (target == this.photonViewID) 
		{
	         Debug.Log("Did damage to ID: " + target);
	         health -= dmg;
		    if (health <= 0)
			{
				Debug.Log("die");
	            KillDestructible();
			}
			else 
			{
				Debug.Log("hurt");
		    }
      	}
   }
   
   public void Hit(float dmg, PhotonViewID target) 
	{
      photonView.RPC("Damage",PhotonTargets.All, dmg, target);
   }
   
   void KillDestructible() 
	{
      PhotonNetwork.Destroy(photonView);
   }
}

but i getting this error:
PhotonView with ID 2001 has no method "Damage" that takes 1 argument(s): Single
UnityEngine.Debug:LogError(Object)
PhotonHandler:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:127)
NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:709)
NetworkingPeer:ExecuteRPC(Hashtable, PhotonPlayer) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1633)
NetworkingPeer:RPC(PhotonView, String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2327)
PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1489)
PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/Extension/PhotonView.cs:219)
HealthAndDamagess:OnCollisionEnter(Collision) (at Assets/Scripts/New Folder/HealthAndDamagess.cs:28)

from this line:
public void DebugReturn(DebugLevel level, string message)
    {
        [color=#FF0000]if (level == DebugLevel.ERROR)
        {
            Debug.LogError(message);
        }[/color]
        else if (level == DebugLevel.WARNING)
        {
            Debug.LogWarning(message);
        }
        else if (level == DebugLevel.INFO && PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
        {
            Debug.Log(message);
        }
        else if (level == DebugLevel.ALL && PhotonNetwork.logLevel == PhotonLogLevel.Full)
        {
            Debug.Log(message);
        }
    }

Comments

  • Tobias
    Options
    Have you read what you posted below "from this line:"? This is a debug logging method. It only makes sure errors it gets are put somewhere where you would notice or read them :)

    The actual problem is what the message says: "PhotonView with ID 2001 has no method "Damage" that takes 1 argument(s)".
    Your Damage() method defines that it needs 3 parameters.
    The last is a PhotonMessageInfo, which is "optional" and doesn't count.
    That leaves 2 actual, expected parameters your RPC requires. But you call the photonView.RPC() with just a single parameter ("dmg").
    Remove the PhotonViewID parameter from Damage() and you should do better.
  • Tobias wrote:
    Have you read what you posted below "from this line:"? This is a debug logging method. It only makes sure errors it gets are put somewhere where you would notice or read them :)

    The actual problem is what the message says: "PhotonView with ID 2001 has no method "Damage" that takes 1 argument(s)".
    Your Damage() method defines that it needs 3 parameters.
    The last is a PhotonMessageInfo, which is "optional" and doesn't count.
    That leaves 2 actual, expected parameters your RPC requires. But you call the photonView.RPC() with just a single parameter ("dmg").
    Remove the PhotonViewID parameter from Damage() and you should do better.
    BUT if i remove that i will have problem with that codes:
    if (target == this.photonViewID)
    {
    Debug.Log("Did damage to ID: " + target);
    health -= dmg;
    if (health <= 0)
    {
    Debug.Log("die");
    KillDestructible();
    }
    else
    {
    Debug.Log("hurt");
    }
    }
  • Tobias
    Options
    Remove that as well ;)
    The check will always be true anyways. Calling RPCs will only call the method on the game objects resembling the original (but on different clients).
  • Tobias wrote:
    Remove that as well ;)
    The check will always be true anyways. Calling RPCs will only call the method on the game objects resembling the original (but on different clients).
    what should i need to remove?
    just this line?
    if (target == this.photonViewID)
    or the whole the hole code that i already posted in my last post?
  • i have that right now:
    using UnityEngine;
    using System.Collections;
    
    &#91;RequireComponent (typeof(PhotonView))&#93;
    &#91;RequireComponent (typeof(Rigidbody))&#93;
    public class HealthAndDamagess : MonoBehaviour {
       
       public float health = 100;
       public PhotonView photonView;
       public PhotonViewID photonViewID;
    	
    	public float dmg;
       
       void Start () {
          photonView = PhotonView.Get(this);
          photonViewID = photonView.viewID;
          Debug.Log("My view ID is: " + photonViewID);
       }
       
    	void OnCollisionEnter(Collision other)
    	{
    			if ((other.transform.tag == "bullet"))
    			{
    	    		Debug.Log("bullet");
    				dmg = 25;
    				//photonView.RPC(RPCName.Damage,photonView.owner, dmg);	
    				////////this.photonView.RPC("Damage",PhotonTargets.All, dmg);
    				photonView.RPC("Damage", PhotonTargets.AllBuffered, dmg); 
    				////////photonView.RPC("Damage", PhotonTargets.AllBuffered);
    			
    				////////this.photonView.RPC("Damage",PhotonTargets.All, health);
    				////////photonView.RPC("Damage", PhotonTargets.AllBuffered, health); 
    				//photonView.RPC("Damage",PhotonTargets.All, dmg, target);
    				//NetworkManager.networkManagerPV.RPC("DestroyObject",PhotonTargets.MasterClient,zombie);
    			}
    	}
    	
       	&#91;RPC&#93;
       	void Damage(float dmg, PhotonMessageInfo info) 
    	{
          		Debug.Log ("RPC Recieved");
    	         //Debug.Log("Did damage to ID: " + target);
    	         health -= dmg;
    		    if (health &lt;= 0)
    			{
    				Debug.Log("die");
    	            KillDestructible();
    			}
    			else 
    			{
    				Debug.Log("hurt");
    		    }
       }
       
       public void Hit(float dmg, PhotonViewID target) 
    	{
          photonView.RPC("Damage",PhotonTargets.All, dmg, target);
       }
       
       void KillDestructible() 
    	{
          PhotonNetwork.Destroy(photonView);
       }
    }
    

    the Debugging is working but still i getting the problem of the killing,
    when the health of my friend is 0 (i killed him), he should Destroy, BUT - for some reason, I GETTING DESTROY!

    i really don't know why...
  • UPDATE:
    i stil have the same script that i posted in my last post.
    but now i got something, when i kill my friend in the game, it destroying just his Trigger objcet, and not hole of the player game object, so he is still in the game but without the Trigger game object.

    Trigger gameobject= the objec that we shoot on to hurt the other players..

    actually in the script it's destroying the photonView
    PhotonNetwork.Destroy(photonView);
    so the effect of that is that it's destroying the "Trigger" game object, but it's not destroying the hole player...
  • i got another problem,
    the problem is that i able to kill my friend (from the editor), but he cannot kill me in the game (he using exe file of the game).
  • Tobias
    Options
    There is no way we can help with this currently.
    Find out if the RPCs you intend to call are actually called and if there is anything suspicious in the client log.
  • Tobias wrote:
    There is no way we can help with this currently.
    Find out if the RPCs you intend to call are actually called and if there is anything suspicious in the client log.
    how you can't help me?!
    i giving you my hole script....
    do you want pictures of my inspector or something?

    using UnityEngine;
    using System.Collections;
    
    &#91;RequireComponent (typeof(PhotonView))&#93;
    &#91;RequireComponent (typeof(Rigidbody))&#93;
    public class HealthAndDamagess : MonoBehaviour {
       
       public float health = 100;
       public PhotonView photonView;
       public PhotonViewID photonViewID;
    	
    	public float dmg;
    	
    	public Transform playerPrefab;
       
       void Start () {
          photonView = PhotonView.Get(this);
          photonViewID = photonView.viewID;
          Debug.Log("My view ID is: " + photonViewID);
       }
       
    	void OnCollisionEnter(Collision other)
    	{
    			if ((other.transform.tag == "bullet"))
    			{
    	    		Debug.Log("bullet");
    				dmg = 25;
    				photonView.RPC("Damage", PhotonTargets.AllBuffered, dmg); 
    			}
    	}
    	
       	&#91;RPC&#93;
       	void Damage(float dmg, PhotonMessageInfo info) 
    	{
          		Debug.Log ("RPC Recieved");
    	         health -= dmg;
    		    if (health &lt;= 0)
    			{
    				Debug.Log("die");
    	            KillDestructible();
    			}
    			else 
    			{
    				Debug.Log("hurt");
    		    }
       }
       
       public void Hit(float dmg, PhotonViewID target) 
    	{
          photonView.RPC("Damage",PhotonTargets.All, dmg, target);
       }
       
       void KillDestructible() 
    	{
          PhotonNetwork.Destroy(photonView);
    		//PhotonNetwork.LeaveRoom();
    	  //PhotonNetwork.Destroy(this.gameObject);
    		//OnGUI();
       }
    }
    
  • Tobias
    Options
    Aside from the script, some debugging via logging would be nice. This is a basic requirement.
    Check if the RPCs get send and received. If they do: Why does one "kill" the player and why not the other way round?

    I can't really debug your scripts every time you're stuck, unless you don't understand something or you think there is some bug.
  • Tobias wrote:
    Aside from the script, some debugging via logging would be nice. This is a basic requirement.
    Check if the RPCs get send and received. If they do: Why does one "kill" the player and why not the other way round?

    I can't really debug your scripts every time you're stuck, unless you don't understand something or you think there is some bug.
    some debugging via logging
    how can i give you that?
  • I did it!
    i made health and damage script!
    but how can i do a respawn system?