playMaker

Author Topic: Photon networking listing players in arrayMaker  (Read 3871 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 11912
  • Official Playmaker Support
    • View Profile
Photon networking listing players in arrayMaker
« on: August 09, 2012, 01:06:45 AM »
Hi,

 after a request, please find an action that will store the photon players currently in the room in a set of arrayLists.

 basically, it expects two list, one to store the players names, one to store their ids. I did it so, because if you only have names, you won't be able to do anything valuable, player's ID is always required for interactivity. I also prefer two arrayList instead of one hashtable because then it can grow and have more entries.

so, on one gameObject, create two arrayList, one named "Photon Player Name", and the other named "Photon Player ID". The action use them names as default, but you can change that if you want. then you simply need to call that action when the player is in a room and choose if you want to list all players, or only other players.

 If you have any doubts on how to set it up, let me know.

I don't think I will include this action in the photon bundle, because it would mean shipping arrayMaker too. I might make a additional bundle just for arrayMaker/photon integration.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Photon")]
[Tooltip("Store the list of Photon players in an ArrayList")]
public class ArrayMakerGetPhotonPlayersInRoom : CollectionsActions
{

[ActionSection("Array referencing")]
[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;

[Tooltip("The ArrayList reference that will host the players names")]
public FsmString NameReference;

[Tooltip("The ArrayList reference that will host the players id")]
public FsmString IdReference;

[ActionSection("Options")]
[Tooltip("If true, list only other players.")]
public FsmBool otherPLayerOnly;


private PhotonPlayer[] players;
private string[] playerNames;



public override void Reset()
{
gameObject = null;
otherPLayerOnly = true;
NameReference = "Photon Player Name";
IdReference = "Photon Player ID";
}

public override void OnEnter()
{
if (otherPLayerOnly.Value){
players = PhotonNetwork.otherPlayers;
}else{
players = PhotonNetwork.playerList;
}
//
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);

// -------- Player -----------//
// get each arrayList reference
PlayMakerArrayListProxy nameList = GetArrayListProxyPointer(go,NameReference.Value,false);

/*
if (nameList ==null)
{
nameList = go.AddComponent<PlayMakerArrayListProxy>();
nameList.referenceName = "Photon Player Name";
}
*/

PlayMakerArrayListProxy idList = GetArrayListProxyPointer(go,IdReference.Value,false);
/*
if (idList ==null)
{
idList = go.AddComponent<PlayMakerArrayListProxy>();
idList.referenceName = "Photon Player ID";
}
*/

nameList.arrayList.Clear();
idList.arrayList.Clear();

foreach (PhotonPlayer player in players)
            {
nameList.arrayList.Add(player.name);
idList.arrayList.Add(player.ID);
}

}
}
}


bye,

 Jean

Col. Phil Bilko

  • Playmaker Newbie
  • *
  • Posts: 45
    • View Profile
Re: Photon networking listing players in arrayMaker
« Reply #1 on: June 19, 2017, 03:37:33 AM »
Hey are there any samples on how to use this? I am trying to put together a player score board which shows the players NAME, Strokes on the current hole and Strokes over all. I have the array setup with the two listed above and it find them but as far as I can see it does not populate the list? Am I missing something ?

Thanks I hope replying to this old thread I still get a response. Thanks again!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 11912
  • Official Playmaker Support
    • View Profile
Re: Photon networking listing players in arrayMaker
« Reply #2 on: June 19, 2017, 04:09:50 AM »
Hi,

This should work fine:

 What is not working? do you get an error or en empty list?

 Bye,

 Jean

Col. Phil Bilko

  • Playmaker Newbie
  • *
  • Posts: 45
    • View Profile
Re: Photon networking listing players in arrayMaker
« Reply #3 on: June 19, 2017, 11:36:37 PM »
Hello and thanks for the prompt replying.

I get an empty list, I check the array at run time after it is connected and spawned the player but it shows nothing in the array. I have not setup any text fields or anything like that for the array to populate yet, this is just the array setup like your showing in the above link.

I am using the latest PUN, I get no errors.

Thanks

Col. Phil Bilko

  • Playmaker Newbie
  • *
  • Posts: 45
    • View Profile
Re: Photon networking listing players in arrayMaker
« Reply #4 on: June 29, 2017, 12:13:58 AM »
Ok I set it to string and unchecked other players only, and now it populates with the Players Name but ONLY the one name and not the other players name. 1 name 1 id.

What am I doing wrong?

Thanks much!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 11912
  • Official Playmaker Support
    • View Profile
Re: Photon networking listing players in arrayMaker
« Reply #5 on: June 30, 2017, 03:37:48 AM »
Hi,

I tested and it works, maybe you need to renter the state, this action doesn't work every update, only once you call it

Bye,

 Jean