Help needed : Sending info via RPC

Options
Good day,
Would like to seek for your kind helps on this...been struggling & pulling my hairs for 3days 2nights...just could not get it right

**I'm using your kind AngryBot Demo Showcase to do my project. It works wonderfully ! Thanks!

Situation :-
Player A gets an item/loots , the loots/item grab the player photonview.owner.name. The loot/item's script has below code (I modified using the demopickup from PUN package) :-
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[RequireComponent(typeof(PhotonView))]
public class LootReward : Photon.MonoBehaviour {

	public string whois ;
	public string whoGetLoot ;
	public void OnTriggerEnter(Collider other)		{
			if (other.gameObject.tag == "Player") { 				
						PhotonView otherpv = other.GetComponent<PhotonView> ();
						if (this.PickupOnCollide && otherpv != null && otherpv.isMine) {
								whois = otherpv.owner.name;
				this.photonView.RPC("WhoGotLoot", PhotonTargets.AllViaServer, whoGetLoot );
}


... ...

	void OnGUI()
	{
			if (!PhotonNetwork.inRoom) {
					return;		}
                        GUILayout.Label (whoGetLoot + "  Got Loots!");
}

	[RPC]
	void WhoGotLoot(string whois)
	{
		whoGetLoot = whois;

		}

The problem is...when Player A pickup the item/loot, the GUI does display correctly, but on other players ( Player B, C..etc), the GUI doesn't display the info correctly. It just display the word "Got Loots!" , without the whoGetLoot (player info) info.


I've been searching for guides on forum ( and actually read them one by one...) :-
search.php?st=0&sk=t&sd=d&sr=posts&keywords=rpc+string&start=20
...and scratching my head trying to understand the code on http://doc.exitgames.com/en/pun/current ... c317517606

I just could not get it right....

Any help ? I'm lost. Is my codes above correct ? I just couldn't get it right ...

Thanks for your kind helps
James

Comments

  • Tobias
    Options
    You basically need to find out who sent an RPC, right?
    This is not in the tutorial but you can do it easily. You have to add another, optional parameter to the method you marked as [RPC]. It must be of type PhotonMessageInfo and provides you the player who sent something and when it was sent (in "server time").

    In your case:
    [RPC]
    void WhoGotLoot(PhotonMessageInfo msgInfo)
    {
        // access: msgInfo.sender
        //...
    

    Then you should be able to show the sender.name or so.

    In the PUN v1.28 and up, we have a Pickup demo. You could take a look at the solution there and use the components if you like to.