- Home /
PhotonTargets.AllBuffered doesn't work properly for master client
Hello everyone,
I'm making team deathmatch game,when someone is died,died guy calls a rpc method which adds score to against team via PhotonTargets.AllBuffered at my game manager script.
I'm having this issue:
Normal clients killing each other and team scores is 2-2, but when master client kills someone it must be 3-2, it's works only for who playing at that time.But if someone joins later the game,they still see the score is 2-2.
This is player health script
// This method calls when player takes damage
[PunRPC]
public void TestDmg(int damage,string shootername)
{
health -= damage;
if (health <= 0)
{
if (photonView.isMine)
{
if (GetComponent<TeamBase>().myTeam == TeamBase.Team.team1)
{
gameManager.photonView.RPC("AddScoreToTeam2", PhotonTargets.AllBuffered,10);
}
else if (GetComponent<TeamBase>().myTeam == TeamBase.Team.team2)
{
gameManager.photonView.RPC("AddScoreToTeam1", PhotonTargets.AllBuffered, 10);
}
}
health = 100;
}
}
This is Game manager script
[PunRPC]
public void AddScoreToTeam1(int score)
{
team1Score += score;
}
[PunRPC]
public void AddScoreToTeam2(int score)
{
team2Score += score;
}
Answer by Captain_Pineapple · Jun 05, 2019 at 07:37 PM
Hey there,
i'd suggest to not use buffered rpcs as a scorecounter. This could result in some massive message spike which kill your photon.
Instead save those points to custom room properties. This way anyone can access them at will and you cannot miss any.
Example from my own game:
curPointCounter = (int)(PhotonNetwork.CurrentRoom.CustomProperties ["RedPoints"]);
PhotonNetwork.CurrentRoom.SetCustomProperties (new ExitGames.Client.Photon.Hashtable (){ { "RedPoints",curPointCounter + pointsToAdd } });
It doesn't work here is updated scripts
Health Script
[PunRPC]
public void TestDmg(int damage, string shootername)
{
health -= damage;
if (health <= 0)
{
if (photonView.is$$anonymous$$ine)
{
if (GetComponent<TeamBase>().myTeam == TeamBase.Team.Rebels)
{
int curPointUSA = (int)(PhotonNetwork.player.CustomProperties["UsArmyScore"]);
Debug.Log("USA Score : " + curPointUSA);
PhotonNetwork.player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "UsArmyScore", curPointUSA + 10 } });
}
else if (GetComponent<TeamBase>().myTeam == TeamBase.Team.UsArmy)
{
int curPointRebels = (int)(PhotonNetwork.player.CustomProperties["RebelsScore"]);
Debug.Log("Rebels Score : " + curPointRebels);
PhotonNetwork.player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "RebelsScore", curPointRebels + 10 } });
}
}
health = 100;
}
}
Game $$anonymous$$anager script
public int UsArmyScore;
public int RebelsScore;
private ExitGames.Client.Photon.Hashtable m_playerCustomProperties = new ExitGames.Client.Photon.Hashtable();
private void Awake()
{
m_playerCustomProperties.Add("UsArmyScore", UsArmyScore);
m_playerCustomProperties.Add("RebelsScore", RebelsScore);
PhotonNetwork.player.SetCustomProperties(m_playerCustomProperties);
InvokeRepeating("scoreSetter", .1f,.1f);
}
private void scoreSetter()
{
int usascore = (int)PhotonNetwork.player.CustomProperties["UsArmyScore"];
UsArmyScore = usascore;
int rebelsscore = (int)PhotonNetwork.player.CustomProperties["RebelsScore"];
RebelsScore = rebelsscore;
}
Read my post carefully. There is a difference between PhotonNetwork.player.CustomProperties
and PhotonNetwork.CurrentRoom.CustomProperties
. The latter one will be accessible for everyone and will be the same value for everyone.
please note at this point that i think that every set
action to the customproperties counts as a room message. Since reducing the message count is crucial i'd like to advise against using a .1f repeat invoke for this. (equals to 10 msgs per user per second -> you have a limit of 500 msgs/s per room)
only call these things when you have to -> so when values actually changed.
Your answer
![](https://koobas.hobune.stream/wayback/20220612202645im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to use Hashtables? 0 Answers
Having only one of the same gameobjects in a scene. Photon Pun 1 Answer
Only one client can see enemy hp bars 1 Answer
Multiplayer cant see host player C# 0 Answers