Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Third Party [Photon] sending rpc variable changes

Discussion in 'Multiplayer' started by KuPAfoo, Feb 21, 2014.

  1. KuPAfoo

    KuPAfoo

    Joined:
    Aug 24, 2013
    Posts:
    17
    I'm trying to make a PvP script award a player stats script a player kill point.

    The sword script detects collision with the player, and sends the player a value to decrement the health by.

    The player stats script (on the body mesh) recieves the sword's request to access a method that decrements the player's health by the sent sword damage.

    The player then calculates who has done the most damage based on viewID.

    The player should then return fire only to the winnerID of the viewID that damage'd the player, Incrementing the player's kill points.

    I cannot seem to wrap my mind around this...

    I'm thinking the player skills script will need to call an [RPC] that looks at the weapon's stats, and adds one?

    Am I just overthinking this? I tried replicating the send damage method into a confirmKill method. Any thoughts? I've been struggling with this for some time now >.> i've re-coded this function like 10 different ways at least... I just can't get past this >.>
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    Where exactly are you lost? In worst case, try to break down the tasks!
    Do you successfully calculate which player did the kill? To check, you can even go as "low tech" as logging the kill to console.
    You have to keep the PhotonPlayer.ID of that user, so you can easily send who killed who later on.

    Once that's done, you can send an RPC like "player X killed me (player Y)" or so. You can send that to all and everyone will know who to award the score.
     
  3. KuPAfoo

    KuPAfoo

    Joined:
    Aug 24, 2013
    Posts:
    17
    I think it's the actual variable that holds the kill point.

    I have the console displaying everything from
    My sword killed his body
    my body died to his sword
    Photonview.IDx died to Photonview.IDy
    my PhotonviewID killed photonviewID

    etc... I have all the calculations of WHO did the killing, and who died down to a science. I can't seem to figure out the point system....

    Do i need an array that holds all possible user ID's for indexers? Can't I just make a private variable for the player so he can yell to everyone in a GUI that IDx has xKills?

    Do I need a score keeping object in the scene to keep track incase someone left?

    These are the things i'm struggling with >.>
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    Yes, to keep the score, you need some dictionary to store the info per player.
    Lets say you keep kills and deaths per player, you could use something like Dictionary<string, byte[]>. Photon has a feature called room properties. You can store some data for the room, independently of the players. It's a Hashtable where you can add your own key/values. So instead of using the Dictionary, you might want to check out Room.SetCustomProperties. Keys have to be strings.
    After a match, let the Master Client set all values for players to null, to reset the score.

    Of course you could also create a class or struct that contains name or ID and kills and deaths. You have to be aware though that Photon can't simply send whatever you come up with. It needs to know how to send (and receive) the data you want to use in the game.
     
  5. KuPAfoo

    KuPAfoo

    Joined:
    Aug 24, 2013
    Posts:
    17
    This looks like very good information, I will be trying this asap!

    for now, I'll be researching Dictionary and Room.SetCustomProperties :)

    I appreciate your help!
     
  6. KuPAfoo

    KuPAfoo

    Joined:
    Aug 24, 2013
    Posts:
    17
    I was re-reading this before digging deep on this... when you say
    are you talking about sending variables through parameters when sending the RPC? because i'm sending and receiving ints that should be populated.
    I was beginning to think RPC's don't send ints?
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    You can send RPCs with parameters and of course those can be integers.

    You can send integers just fine. Types you can send out of the box are: string, bool, byte, short, int, long, float, double, Vector2, Vector3 and Quaternion.
    Arrays of the types above. Photon Hashtable (not available as array). Dictionary<K,V>