[C#] Getting 'source' in events?

Hey guys,

so I’m trying to figure out this little code. I’ve seen that Lua uses ‘source’ without even having it somewhere in parameters of events.

public Main()
{
      EventHandlers["playerDropped"] += new Action<string>(OnPlayerDropped);
}

private void OnPlayerDropped(string reason)
{
     // how do I get source?
     Debug.WriteLine("Player dropped, reason: " + reason);
}

I’m kinda curious how do I get ‘source’, which player has disconnected. Thanks

try

public Test()
        {
            EventHandlers["playerDropped"] += new Action<Player, string>(PlayerDropped);
        }

        void PlayerDropped([FromSource] Player source, string reason)
        {
            Debug.WriteLine($"Player {source.Name} dropped");
        }
1 Like

Thanks a lot, do you mind giving me some simple explanation on why [FromSource] is needed and what it does? I’d appreciate

@kubop Did you have any answer about your last question ? :slight_smile:
It’s seems it can be used with Vector and Player, but i don’t understand when.