Event Handler still triggers after resource stop

I created an event handler for the event populationPedCreating in C#. Here is the code below to reproduce this bug:

const string replacement = "s_m_y_cop_01";
new Model(replacement).Request();
EventHandlers["populationPedCreating"] += new Action<float, float, float, uint, dynamic>(
        ( x, y, z, model, setters ) => {
            Debug.WriteLine( $"Making cop at {x}, {y}, {z} plus a bit ({(PedHash)model})" );
            setters.setModel( replacement );
            setters.setPosition( x, y, z + 5.5f );
        });

To reproduce this bug, create a C# resource which has the above event handler, and then start the resource. Once the resource is started and you’re in-game, stop the resource, and then check the F8 console. You can still see the trace for populationPedCreating still being executed.

What’s more peculiar is that the previous event handler stops executing when the resource is started again.

I’ve yet to test this with other events, so I’m unsure if it’s only reproduced with populationPedCreating or if it’s other events as well.

2 Likes