Adding Scoreboard on my FPS

how do i start on adding scoreboard on my fps ... showing number of kills and deaths of a player . . . .

Comments

  • You could use a custom property "k" for "Kills" per player and update it every time needed. All clients get those properties and to display the score board, you would go through the list of players in the room and fetch everyone's "k" property. Set it with Player.SetCustomProperty(). This method is documented in the pdf and in best case, the doc shows up in your IDE, too.
  • Tobias wrote:
    You could use a custom property "k" for "Kills" per player and update it every time needed. All clients get those properties and to display the score board, you would go through the list of players in the room and fetch everyone's "k" property. Set it with Player.SetCustomProperty(). This method is documented in the pdf and in best case, the doc shows up in your IDE, too.


    thanks for your tip. im gonna try it out. . . . is this the same when preventing on killing team member on a team match? because i've done on spawning team but they still hit or kill each other....
  • @tobias about on customproperty where do i need to include it on room.cs?
  • You don't have to include it in room.cs. You add it to the Room.customProperties Hashtable by calling Room.SetCustomProperties().
  • Tobias wrote:
    You don't have to include it in room.cs. You add it to the Room.customProperties Hashtable by calling Room.SetCustomProperties().

    thanks im gonna try it.
  • @Tobias do you have an example of it? coz i still can't figure it out T_T . . thanks for your help man. i really appreciate your help.
  • For exemple when your player connect to the lobby , you setup his kills and deaths:
    Hashtable PlayerCustomProps = new Hashtable();
    PlayerCustomProps["Kills"] = 0;
    PlayerCustomProps["Death"] = 0;
    PhotonNetwork.player.SetCustomProperties(PlayerCustomProps);

    Whe the player kill someone , you update his kills score:
    Hashtable PlayerCustomProps = new Hashtable();
    PlayerCustomProps["Kills"] = 1;
    PhotonNetwork.player.SetCustomProperties(PlayerCustomProps);

    And for list all players kills and deaths :
    foreach (PhotonPlayer player in PhotonNetwork.playerList){

    Debug.Log(player.name.ToString() + " Kills : " player.customProperties["Kills"].ToString() + " Deaths : " + player.customProperties["Death"].ToString());

    }

    I hope that you will understand a little bit more now.
  • @rokawar thanks thanks for this its a big help on me. i really appreciate your help guys. :D:D:D
  • @rokawar why is that everytime i kill the score doesn't increase. stock at 1 score
  • I have write that just as exemple :
    Hashtable PlayerCustomProps = new Hashtable();
    PlayerCustomProps["Kills"] = 1;
    PhotonNetwork.player.SetCustomProperties(PlayerCustomProps);

    For your player , you need to use his real score , for exemple
    Hashtable PlayerCustomProps = new Hashtable();
    PlayerCustomProps["Kills"] = YourPlayerScore;
    PhotonNetwork.player.SetCustomProperties(PlayerCustomProps);

    YourPlayerScore is the variable where you save his score.

    so when he kill someone , YourPlayerScore = YourPlayerScore +1 , and after that you update his props.
  • @rokawar ohh i see thanks for this... ^^
  • @rokawar i've done it the kills score is now working perfectly but the deaths are having issue. it reset the score everytime the player die.
  • im having strange problem on the Score of Deaths its not working perfectly if the player dies it increase the death score but after it respawned it reset again the death score. on the kill score it working correctly..
  • im done on it now heheh thanks for your info... but still the Death Score is not working perfectly.... about on winning player if somebody reach the required winning kills how to show the winner in screen and go back to the lobby when the player won..... how can i add it? can you give me a sample please? ? ? TIA
  • i've done on scoreboard for total kills and death my problem now is how can i execute the player who set the number of kills needed to win. im having problem on showing it up.

    if(player.customProperties["Kills"] = 15)
    {
    GUILayout.Label(player.name + " --- Wins the Game --- ", style);
    }

    error:
    error CS0266: Cannot implicitly convert type `object' to `bool'. An explicit conversion exists (are you missing a cast?)
  • I think that you need to learn a little bit more what you do before ......

    Your "player.customProperties["Kills"]" is a typed string.

    Your "15" is an INT

    So on your line you have 2 errors "if(player.customProperties["Kills"] = 15){"

    player.customProperties["Kills"] need to be int.Parse(player.customProperties["Kills"].ToString())

    And equal need to be" =="

    Final result:

    if(int.Parse(player.customProperties["Kills"].ToString()) == 15){

    GUILayout.Label(player.name + " --- Wins the Game --- ", style);

    }

    Try to understand what you do , copy and past don't help.
  • @rokawar thanks for your help. yes sir I'm still learning on it and i've tried it a few time but i can't still figured it out so i just copy and paste that code sorry for it sir. really appreciate your help on it ... thanks
  • how can i add round timer to sync on both screen???
  • PhotonNetwork.time is a shared server time. It's +/- 20ms accurate usually.
    If you set a room property round start time ("rst" e.g.), any client can calculate how much of a round's time passed.
  • Tobias wrote:
    PhotonNetwork.time is a shared server time. It's +/- 20ms accurate usually.
    If you set a room property round start time ("rst" e.g.), any client can calculate how much of a round's time passed.

    ohh i see thanks for this......

    i have a minor bug. am i doing my stuff right? I add Time.timeScale = 0.0f; to stop the game when the player reaches the kills needed... but. . . when i tried to create again when a player join on my create we can't see each other... me and he must relog again to see each other on the game?? is my idea right adding time.timescale when the player reach the kills neede to win? or is there a better way to do it??
  • You should verify that this specific change really causes the issue you see. A simple way to check: Modify the timescale in some of our demos and see what happens.
    Maybe you made some other error. Hard to tell.
  • thanks tobias... ill check it out
  • sir tobias . . . i have a question... how can i add a countdown timer after a player reach the score needed to win? example when i get the required kills of 10 it will show the player who got the 10 kills then countdown for 10 secs and return to the lobby.
  • Hehe. No need for the "sir" :)
    A sloppy way would be to send an event "reached X points. end of round in 10 sec" and each client would start it's 10 sec countdown when they get the event.
    As there is a synced server time, you can use that. Send the server timestamp in that event and any client knows when the round ends. If more than one player reached the points, the earliest timestamp is used for all clients.
  • ill try it.... thanks....
  • tobi... can i ask.... how can i remain the score of the total kills of a player when returning to lobby? because i set a timer that when a player reach 10 kills the timer will activate and countdown. when a first player reach 0 seconds it return to lobby but the other players will stop countdown the timer. how can i disable destroying the timer or the score.. i tried the DontDestroyOnLoad (); but i cant make it.
  • Only one player has to leave?
    I don't know how you implemented your timer, so I can't tell you how to disable it. Please try to learn this from the documentation for the API you use. This is out of scope for me, sorry.
Sign In or Register to comment.