Update player's custom properties
Options
Im a little confused on how to do this, I have been searching around and found out I can use
[code2=csharp]ExitGames.Client.Photon.Hashtable PlayerProperties = new ExitGames.Client.Photon.Hashtable() { { "Deaths", 0 } };
....
....
....
if (photonView.isMine){
foreach (PhotonPlayer PlayerScore in PhotonNetwork.playerList.Where(i => i.ID == LastAttackerID)){
PlayerScore.AddScore(1);
}
foreach (PhotonPlayer PlayerScore in PhotonNetwork.playerList.Where(i => i.ID == photonView.owner.ID)){
PlayerScore.customProperties["Deaths"] = (int)PlayerScore.customProperties["Deaths"]+1;
}
....
....
//access:
GUILayout.Label(PlayerScore.customProperties["Deaths"].ToString());[/code2]
but that only updates on the owners client it does not automaticaly synch with on the other clients, what Im missing?
[code2=csharp]ExitGames.Client.Photon.Hashtable PlayerProperties = new ExitGames.Client.Photon.Hashtable() { { "Deaths", 0 } };
....
....
....
if (photonView.isMine){
foreach (PhotonPlayer PlayerScore in PhotonNetwork.playerList.Where(i => i.ID == LastAttackerID)){
PlayerScore.AddScore(1);
}
foreach (PhotonPlayer PlayerScore in PhotonNetwork.playerList.Where(i => i.ID == photonView.owner.ID)){
PlayerScore.customProperties["Deaths"] = (int)PlayerScore.customProperties["Deaths"]+1;
}
....
....
//access:
GUILayout.Label(PlayerScore.customProperties["Deaths"].ToString());[/code2]
but that only updates on the owners client it does not automaticaly synch with on the other clients, what Im missing?
0
Comments
-
Player.customProperties is only for reading (see doc on this field).
To write property use Player.SetCustomProperties method.0 -
vadim wrote:Player.customProperties is only for reading (see doc on this field).
To write property use Player.SetCustomProperties method.
For use SetCustomProperties I need to reference the original hashtable, right? the original hashtable is in a different script its not like thats a problem but could you make a little example how would you update a property using SetCustomProperties, please
I been reading and it seems to be done by using hashtable.add("property", value); but Im not sure, this is the first time I have used hashtables so I dont know if I need to reference the original table or not
Thank you0 -
Instead of PlayerScore.customProperties["Deaths"] = (int)PlayerScore.customProperties["Deaths"]+1
you need something like
PlayerScore.SetPlayerScore.SetCustomProperties( new ExitGames.Client.Photon.Hashtable(){ { "Deaths", (int)PlayerScore.customProperties["Deaths"]+1 } } )
This will update "Deaths" player property leaving other properties intact.0 -
Hello I have a fps kit. When I set custom properties works well but when I get for a particular photonviev like this int killplayer=(int)photonView.owner.customProperties["Kills"]; return null reference.0
-
Make sure "Kills" is set in the customProperties. With 0 kills, it's likely not set at all.
Also make sure you get the naming right everywhere you use "Kills". It's case sensitive, too.0