Objects with the same RaiseEvent, call just for one?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Objects with the same RaiseEvent, call just for one?

redskry
2018-03-21 07:38:04

Hi everybody :smile:

I'm doing a 2D game with photon and now i'm trying to learn how "Raise Event" work

I have in my scene 10coin (for the exemple), but i don't want to use Photonview with them , because they don't need to receive RPC ( if i have to multiple the send rate by the amount of these coin it's will be a nightmare ..)

i just want to call a event, when one of them is get , to tell to other player that this specific coin can't be get anymore.

But all of my 10 coins have the same Event on them, So if i get a coin, will all coins receive the event ?

If what i do is the wrong way, someone can help me with that ?

Have a good day !

Edit : In other word, i can say that i want to find a solution to all player to have the same ID for all coins , without photonview .
The other solution that i found, is when a player connect to the room , the master client enable the photonview of all coin for him and the new player, send to him all ID of coin . and when the new player have check with master if ID are the same, he can disable all photonview's coins withthe master Client .
So, after , player can use simple RPC to tell to other which coin is get :dizzy:

EDIT 2: I think about a other way, there is possible to use 2 different network group? to avoid coin to receive RPC by other player's rpc ( Movement RPC for exemple) ? To minimize rpc exchange ^^'

Comments

[Deleted User]
2018-03-22 11:14:06

Hi @redskry,

basically you just need one OnEvent callback. From this callback forward the message to the correct receiver. In your case I would implement something like a 'Coin Manager'. This manager has a list including all coins in the level with an unique ID - this is important. Whenever a clients collects a coin, he raises an event containing the unique ID of the coin he just collected. On all clients OnEvent gets called and the incoming message can be forwarded to the correct receiver - in this case this is the 'Coin Manager'. This manager can now disable the coin with the unique ID he received before.

redskry
2018-03-22 17:38:20

Thanks for youre anwser!

Edit: I was wrong, it's easy now, whatever if this is the "same coin", the number of coin on the map is the same on all client, and all coin are exactly the same... so, the most important is just that coin is on the good place. The master just have to tell to the new player all position coin, and the client put the coin to the right place.

Thx again for the anwser! Have a good day!

diegodimap
2020-09-03 14:13:59

Hi Everyone, I am trying to solve this exact same problem but it is not working.
I am using PUN2 and raising an Event to open a door... but all doors on my game are opening.
I am using this method:
PhotonNetwork.RaiseEvent(0, cont, RaiseEventOptions.Default, SendOptions.SendUnreliable);

Where 'cont' is the door number.
When I receive the event I do not know how to recover this parameter.

private void NetworkingClientEventReceived(EventData obj) {
if (obj. "WHATHERE?"== cont) {
if (obj.Code == 0) {
anim.SetInteger("abrir", 0);
}
if (obj.Code == 1) {
anim.SetInteger("abrir", 1);
}
}
}

please help me! :)

Eristen
2021-11-05 14:52:08

Hey @diegodimap

In order to retrieve the values from the EventData object you need to do the following:

object[] data = (object[])obj.CustomData;

string someStringParam = (string)data[0];

float someFloatParam = (float)data[1];

int someIntParam = (int)data[2];

Back to top