How to tell if an event was sent by server or sent by single player AI?

In pvp mode, I use the way in the tutorial to distinguish who sent the event, but connecting `Player` class with `BoltConnection`, so when an event is received, if `evnt.RaisedBy`(connection) is not null, I can get the player. It it's null, then it is sent by the client that play as a server.

However in single player mode, if AI sent an event, then `evnt.RaisedBy` is also null. Is there a way to distinguish who sent this event except add another property in the event? That's too much work for every event I have to add another property and add codes to deal with it.

Comments

  • With FromSelf, RaisedBy, and IsSinglePlayer you can write logic for each of these cases without needing extra event properties.
  • I don't know about FromSelf. The document says "Returns true if this event was sent from own connection". I tested it in single player mode, the event sent by player and by AI all have True for "event.FromSelf".

    So I still can't see how to distinguish which event is sent by AI and which by the player.

    BTW the other two values are also the same. "RaisedBy" are both null, and "IsSinglePlayer" are both True.
  • Hi @SPF ,
    I don't know about FromSelf. The document says "Returns true if this event was sent from own connection". I tested it in single player mode, the event sent by player and by AI all have True for "event.FromSelf".

    Events are sent from a Connection to another one, or to itself, and it has nothing to do with the Entities.

    On the other hand, an Event can have an Entity reference as a property, and this can point to any Entity you have on your game. If you have a Player Entity and an AI Entity, just include its reference on the Event and check it on the receiving end.
    BTW the other two values are also the same. "RaisedBy" are both null, and "IsSinglePlayer" are both True.

    - "RaisedBy" will be null if it's sent by the local peer, as there is no way to reference your own connection (a connection can only represent a communication between two peers).

    - "IsSinglePlayer" is self-explanatory.

    --
    Ramon Melo
    Photon Bolt Team