Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on August 09, 2012, 04:06:45 AM

Title: Photon networking listing players in arrayMaker
Post by: jeanfabre on August 09, 2012, 04: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
Title: Re: Photon networking listing players in arrayMaker
Post by: Col. Phil Bilko on June 19, 2017, 06: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!
Title: Re: Photon networking listing players in arrayMaker
Post by: jeanfabre on June 19, 2017, 07:09:50 AM
Hi,

This should work fine:

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

 Bye,

 Jean
Title: Re: Photon networking listing players in arrayMaker
Post by: Col. Phil Bilko on June 20, 2017, 02:36:37 AM
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
Title: Re: Photon networking listing players in arrayMaker
Post by: Col. Phil Bilko on June 29, 2017, 03: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!
Title: Re: Photon networking listing players in arrayMaker
Post by: jeanfabre on June 30, 2017, 06: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
Title: Re: Photon networking listing players in arrayMaker
Post by: heavygunner on November 01, 2020, 08:06:16 PM
Hi !

Not working in PUN 2 and Unity 2020

However, managed to list players using Get Player Properties by looping
Title: Re: Photon networking listing players in arrayMaker
Post by: vinitambini on December 14, 2020, 06:03:29 PM
Hi heavygunner,

Could you please tell us a little more how you've managed to use "Get Player Properties" by looping to get a players list?

I'm stuck on this for a while now. If you could share a little bit of your workflow on it, I'd really appreciate it.

Thanks
Title: Re: Photon networking listing players in arrayMaker
Post by: heavygunner on January 02, 2021, 01:50:20 AM
Hi heavygunner,

Could you please tell us a little more how you've managed to use "Get Player Properties" by looping to get a players list?

I'm stuck on this for a while now. If you could share a little bit of your workflow on it, I'd really appreciate it.

Thanks
Sorry mate ! Didn't noticed your reply.

We managed to found a simple solution which can ad nicknames of players to Array. Check below screenshots

In level scene create a empty object (I named it GM, it created on Level scene) and add new fsm and an Array (String) there.
You need to get FSM array add action from Ecosystem