playMaker

Author Topic: Arraymaker to count number of Photon players  (Read 12931 times)

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Arraymaker to count number of Photon players
« on: February 01, 2013, 08:23:38 AM »
Could have added this to my Photon thread, but this is more Arraymaker related so made new thread.

In my game 4 multi-player characters are spawned using Photon. Each one is given a different character model, and spawned to a different location in the game.

Using Arraymaker I hope to track which characters are currently in use, so that if a player quits mid-game their character then becomes available for a new player to take over.

I figured that I would have a Clean game object with the Array List Proxy on it, which should at game launch add all the possible players. Then on each player model I would use the Array list remove to REMOVE that model from the list. THEN I would use that list to let the spawning function choose the next possible character from the list, the characters that were already taken would therfore be removed from the list.

I have got the List proxy to add all characters at the start of the game, but the REMOVE from list function that is added to the models game object does NOT seem to remove anythign from the list...

I am sure that Im just setting this up wrong, something to do with being able to access the list from another game object.

The reason that I canĀ“t have the Array List Proxy actually IN the spawning FSM itself, is that, that game object is removed at runtime by the Enabler FSM..

Am I approaching this the correct way, maybe not? If I am, whats the right way to remove stuff from a list that exists only on another FSM, indeed another game object?

Mark


markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Arraymaker to count number of Photon players
« Reply #1 on: February 08, 2013, 03:02:44 AM »
Is it ok forum protocol to just say
*BUMP* ???

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker to count number of Photon players
« Reply #2 on: February 08, 2013, 03:31:18 AM »
Hi,

 By all means yes! please bump, even old threads. This forum is getting bigger and bigger each day, and it starts to be difficult to keep up with everything. So to *everyone*! please keep bumping on what is important for you, it allows everyone to clearly be up to date with what matters and what's current.

I think you are over designing this. If you have only 4 characters per room as part of your game, then you will be better off implementing something simpler.

 have one fsm that responsible for handling who's who. totally hardcoded ( I don't like that, but sometimes it's the logical way to not get lost in unecessary generical approaches... in short, get it done!)

have four boolean variables that you flag to true when you have a player for that role. Then as a new user comes in the game, you go trhough them four variabl in the order you want, and check it, if it is false, this is the role to assign to the new player.

You can also aside these four bools, maintain four gameObjects variables to host the reference to the player gameObject.

 As far as photon and networking, my approach to implement this would be to have this fsm on a regular gameObject that is normally instantiated ( not instantiated over the network).

I don't see the need to because you will use this manager as responses to Photon global events such as new player in room, or join room or leave room, so in theory, I think you are fine with this approach

 Does it make sense?

Bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Arraymaker to count number of Photon players
« Reply #3 on: April 10, 2013, 05:29:51 AM »
Two months later I'm back to this one. (OH! Thread title seems wrong now cos you suggested NOT using ArrayMaker)
I think I get what you mean here Jean, just not sure how to achieve it.
Quote
I think you are over designing this.
GREAT! It was seeming a bit complex
Quote
have four boolean variables that you flag to true when you have a player for that role. Then as a new user comes in the game, you go trhough them four variabl in the order you want, and check it, if it is false, this is the role to assign to the new player
OK I get this, but dont know how to implement it...
...but I have one more additional issue, Im thinking that I MAY want these 4 characters to be randomly chosen. this is because each charactr has a new start position, and for a single user, playing multiple times would give a different character to play (maybe) so repeat play would be more appealing.
So I need to assign these player Bools randomly

SO...

1) I have to fill these bools randomly??? Dunno how...

2) Currently in Game Manager FSM I simply have a counting state, how many in the room, Int Compare etc... If there 1, then I instantiate player one
(as shown in image 1 BELOW)

So here, instead of a hard coded player, I need to got to these bools and choose the next available?

How...

THEN, When all four are chosen, I need to get a message to my FSM that created the room called Create and Join
(as shown in image 2 BELOW)
and have it Create a new one with a new name (My Room is called Main, so Main01 maybe??)I spose thats trivial...

I may have asked this before, but Im not sure how to track what happens when someone leaves... I need to see who that is, open a space in that Room, and then if a new player comes along they BOTH get the available character (not a duplicate of another, thats important, my story can only have 1 Priest, 1 Nurse, etc... This is not working now, If I player leaves NOW, they will get the 4th character, even if thats NOT the one that left... hmm.. did you get that?) AND fill up the room again, so a new character would create a whole new room..

Im afraid its all looking a bit daunting now... Is there a simple way to achieve this?
My head hurts!

MArk

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker to count number of Photon players
« Reply #4 on: April 11, 2013, 01:40:05 AM »
:)

I have created an action just for that actually:

http://hutonggames.com/playmakerforum/index.php?topic=1596.msg6948#msg6948

so your roles are assigned ids ( 1 2 3 and 4), using the action above you can achieve a loop system to randomly choose, but it might get complex to implement because your fsm need to stay in that loop for this action to work.

 the other solution is now indeed to use ArrayMaker. Have an arrayList with 4 int, 1 2 3 4, and everytime you request a new player, you pick one from this array ( randomly, you have actions to do this), AND you remove that index from the array, so if it picked 3, you remove 3, and your array now only contains 1 2 and 4, next time, you pick a random item from that array, and you are sure that you will not pick the same id again this way.

does that make sense?

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Arraymaker to count number of Photon players
« Reply #5 on: April 11, 2013, 04:18:16 AM »
It makes sense, and I think I would prefer to use the ArrayMaker method, for flexibility, but I have one question that I've been knocking my head against in my own experiments for solutions, and that how does this work with Photon?

I tested an idea you suggested earlier where we set bools for each new player, and although each client of course correctly set the bool for its own player, I couldnt figure out how to sync this to other players, so the list was updated on all players in a room... and then created a new room after 4 players were in.

I suspect I'll hit the same problem using ArrayMaker? If I put the ArrayMAker List on a separate "PlayerManager" Game Object, is it just to add a photon view to that GO? (cos thats not working for me... )

Quickie hint on that isse would be nice and Ill go ahead with some more experiment using ArrayMaker...

cheers

Mark

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker to count number of Photon players
« Reply #6 on: April 11, 2013, 07:43:54 AM »
Hi,

 Good point. several way to go about it.One way to go about it is the following;

when a player gets instanciated, the application that instanciated it has the right arrayMaker values, so you simply need to update the arrayList when you find out that the player that was just instanciated is "not mine".

 on the player itself, have an fsm, responsible to dispatch that event ( a global event, like "PLAYER ENGAGED"

one other way would be to simply fire a RPC event, and because it is a regular global event you can catch it on any gameobject. so have a global event for each player:

"PLAYER 1 LOADED"
"PLAYER 2 LOADED"
etc etc
the same is true when the player is disconnected
"PLAYER 1 UNLOADED"

your player is responsible to fire this rpc, only if it "is mine", you get that right?

your arrayList proxy has a fsm component listening to that and simply adding the id or removing the id from the arrayList.

 Does that make sense?


Bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Arraymaker to count number of Photon players
« Reply #7 on: April 11, 2013, 10:44:47 AM »
Quote
Does that make sense?
Not completely...
Quote
when a player gets instanciated, the application that instanciated it has the right arrayMaker values,

What do you mean by RIGHT arrayMaker values?

Quote
so you simply need to update the arrayList when you find out that the player that was just instanciated is "not mine".

Well I get that my own character knows who HE is therefore he can add or take himself away from that list, but we still need to know which characters are left that are possible to take, so your character msy broadcast who he is to the other players, so dont understand only having to update list on "not mine".
Clarify?

Quote
on the player itself, have an fsm, responsible to dispatch that event ( a global event, like "PLAYER ENGAGED"
Yes did that on my own experiment, but couldnt get the broadcast (whats the right word here) to other clients to work, would add or remove himself from his own list but NOT the list of others... A photon thing...

Quote
one other way would be to simply fire a RPC event, and because it is a regular global event you can catch it on any gameobject. so have a global event for each player:
Sounds a tad easier, just because... well what you said...

Quote
"PLAYER 1 LOADED"
"PLAYER 2 LOADED"
etc etc
the same is true when the player is disconnected
"PLAYER 1 UNLOADED"

DONE! Exactly my choice of wording!
Quote
your player is responsible to fire this rpc, only if it "is mine", you get that right?

NAH.. Sorry. My player "fires the RPC" (which action is this actually???) and then other players fire theirs, and ALL CLIENTS, mine included need to pick up these, to add/remove from list right? AM I right? Close??

Quote
your arrayList proxy has a fsm component listening to that and simply adding the id or removing the id from the arrayList.

Yes... get this, but Im still not getting how to listen for them over Photon... again, which action?

Sorry for being slow on this... I know Im close though...

OH.. I still need help starting a whole NEW Room, after the 4 players are in, with all the same functionality, but maybe that should be a different thread?

:)

Mark

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker to count number of Photon players
« Reply #8 on: April 12, 2013, 02:57:13 AM »
:) We'll get there!

 When a player ( PLAYER A ) gets instanciated, the application instance ( running on that user computer) was responsible for choosing what type of player he/she will be, so in that sense, the arrayMaker will be the true reflection of the game state.  Let's say that PLAYER A has been assign a player type 3, so the arrayList on that computer is 1,2,4 now. yes?

On the other running instances ( other users on other computers, within the same photon room), Will see that PLAYER A popup in the room, theere own arrayMaker list will not be in synch, they will still have '3' in there arrayList.
 
So when you instanciate PLAYER A/3 you need to also fire a RPC event OR react somehow when PLAYER A/3 is instanciated on other computers, to update the local arrayList.

Does that make better sense? you only need to "update" the list on not Mine, because you haven't decided in this case what id to assign, it's only in the case of "is mine" true that indeed you were respsonsible for assigning a random Id.



The action to send RPC is: https://hutonggames.fogbugz.com/default.asp?W920

This page references usage in the actual demo so you can see how it works.

Bye,

 Jean


markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Arraymaker to count number of Photon players
« Reply #9 on: April 12, 2013, 06:50:18 AM »
Quote
Does that make better sense?

YES!!!

Watch this space... I have kids arriving with my son soon, so Im not gonna get to it today... but... its clear now... getting it to work is still a challenge, but I think you just nailed the concept for me..

Sorry for being so slow...

Mark

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker to count number of Photon players
« Reply #10 on: April 12, 2013, 07:23:59 AM »
Hi,

 Don't worry, it is a very difficult concept to grasp when you start with all this. Once you have the picture in your head and who does what and when, it's really easy and actually enjoyable, until the next hurdle... I am banging my head on daily bases if that can reconfort you a bit... :P

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Arraymaker to count number of Photon players
« Reply #11 on: April 14, 2013, 03:44:44 PM »
IM THINKING TOO MUCH!!

To choose a random character:
Would you?
Use Ints in the list that are simply IDs for the game objects that will be player character? Or can I /should I use the Game Object Slots to hold the actual Player Prefabs?
Should I randomise my List? Somehow create the list randomly, Or Randomise the picking of elements from it?
You said...
Quote
Have an arrayList with 4 int, 1 2 3 4, and everytime you request a new player, you pick one from this array ( randomly, you have actions to do this),
So I think you suggest the INTS method.. but you say I have actions for it? Which are they?

So after picking a random number, and that number is removed from the list, that number transitions to a player character it represents, and spawns it in the right location for that character.
Am I right?

So Quitting?

If  player quits, we put his number back in the list, I do this in the quit manager? (I haven't changed this from the demo, excatly the same corner button) What if someone just closes the window?

And After 4 players are playing?

If I simply increment the Room Name, and Create a new room, will it work? The Players that are counted by Photon, are they PER ROOM; or total?

What if 2 rooms are created, and filled with 4 players each. But someone from room 1 quits, and then a NEW player joins, will they make a new room? or Join the space left by the player in Room 1?

Jeeezzz theres loads to think about!!

Mark
« Last Edit: April 14, 2013, 05:50:35 PM by markfrancombe »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker to count number of Photon players
« Reply #12 on: April 15, 2013, 01:33:45 AM »
I see your brain cells melting and dreeping out of your ears! :)

I have created a custom action called "ArrayListGetRandom"

use that in your array of player refs

{1,2,3,4}

after you used ArrayListGetRandom, you will get 3 for example

so the variable is 3 and the index of that ref is 3 ( bear with me)

you store 3, and you Delete index 3

now you have {1,2,4}

another player comes, you use ArrayListGetRandom again, this time it picks 4, so the reference is 4 BUT the index is 3, you delete the index 3 of that array

you are left with {1,2}

etc etc

does that make sense?

quit:

 you will have to listen to player connecting and disconnecting. if the user pause or quit, you can either be proactive and listen to puse and quit events ( where possible) and inform photon, or simply wait for photon time out and you will get notified with a Player disconnected global event.

room name: it's better if you use a unique name for the room, something generated on your server, or simply the datetime down to the milliseconds or something like that. incrementing on the client is not going to be bullet proof.


room management is something that you will have to draft, as it's really up to you to implement it the right way for your game.

 if a player leave a room, and want to join again, either you choose for him in a the current list of rooms, or you expose to him a selection system of the currently opened room. that's really up to you, and already something beyond Photon scope, photonsimply allows you to create room for player to join, that's all, you make up the room real "meaning" for your game.

Bye,

 Jean


markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Arraymaker to count number of Photon players
« Reply #13 on: April 15, 2013, 07:14:21 AM »
Ill try to keep this short.

I think this has got a bit beyond me, so Im trying to just break it down, and come back to you with just how to achieve the first step.

First, where can I get ArrayListGetRandom of which you speak?

If I can get my Players removing themselves from an Array List, that will be a start.

FYI: My players will never join a room, or choose a room name, infact Im trying to hide from them that its multiplayer at all! They can play single player too, but get a different experience.
So if they quit. they would have to start from the beginning again... so I dont care if they go back into the same room at all.. I would rather they fill a space left by another partly empty room.
I see your point about incrementing being risky, if a new room is ALWAYS ONE HIGHER; I guess it will never end, until I have Room300000000000000.

Maybe I can create a random string? Or the date as you say...

Soo.. something I had forgotten about the original Photon (non Playmaker) version. is the mention of Random Matchmaking... isnt that just sticking players in a random room? Maybe that would do? If a room exists with space?

...and you are right about my brain cells... GONE!
I may resort to a flow diagram to do this... you can "approve" it, and then Ill go from one box to another getting each node working... Don't care how long it takes... gonna get it to work!

Do I get a prize for determination?

Mark



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker to count number of Photon players
« Reply #14 on: April 16, 2013, 01:26:09 AM »
Hi,

 ArrayListGetRandom is a action shipped with ArrayMaker, search for it like a regular action, in the action browser.

Your player "thinks" he doesn't join a room, but infact you will have to make him, so you are simply hiding this from the user, photon requires that each player explicitly join or create rooms, it's not a case where you can create rooms on the server side, since photon works in the cloud, it's all done on the client side basically,

So, yes, using datetime string for room name is likely the good approach. I am designing a similar system, and I actually rely on a webservice I designed to generate unique room names, by using a webservice, I can create safe room name cause I keep track of them.

I don't think you can use random room, since I am not sure how random room will pick rooms that are constraint to 2 player, or is it a case where room have no limits?

Bye,

 Jean