I can't give u pseudo code, since its always a combination of sending events between FSM inside PM and external script code also communicating with a FSM.
I will try to detail the problem cases we run into.
1) We used Playmaker.SendEvent(string) to send events by default from script, assuming we would always send the event to the Fsm component we call the function on, as there is no parameter/hint on the code itself that would suggest otherwise.
The problem is this only works if u never use the "SetEventTarget" action, which just notes "Sets the target FSM for all subsequent events sent by this state."
Whats actually missing is the check if a incoming fsm event, was actually send by this "fsm state" as stated in the tooltip, instead "this.Event(this.EventTarget, fsmEvent);" will always be used.
So if u setup a SetEventTarget in some states and also have script code sending events, the script code needs to clear the EventTarget or u might send the event to whatever is set at this time. While this seems fine, u need to-be aware of this or like in our case are up for quite some debugging.
2) The other problem was this: How can u correctly send a delayed FsmEvent from script if u are not aware of the way EventData is handled inside DelayedEvent().Update().
I naively used a vp_timer() from the UFPS package, in conjunction with setting eventdata. This ofc will fail, if u interleave PM and script event data sets and not correctly emulate what DelayedEvent().Update() is doing.
Thats why using the "SendEventToGameObject" version is safer, since it handles the EventTarget + EventData correctly in all cases. The problem was, that i did not look for a "PlayMakerUtils" namespace, since i found the SendEvent/Event calls easily.
The only oddity is the "Fsm.SetEventDataSentByInfo()" call, that will always be called, no matter what event source was used?
It seems u cant override this logic, since if u send a event from script, those members should be null/unset. This can only be solved by manually calling ProcessEvent(), with a correctly setup EventData object, which seems like a bad idea.
So a version like this is missing to handle all this correctly:
public void Event(FsmEventTarget eventTarget, FsmEvent fsmEvent, FsmEventData eventData);
U could than also wrap this around some extension methods, to correctly set the EventDataSentByInfo inside FsmEventData.
bye Andy