This event is fired before creating a population ped and allows manipulating population from script. You can also cancel this event with CancelEvent(). Setters contains two function:
float posX, float posY, float posZ, uint model, object setters
This example illustrates how you can intercept population:
CreateThread(function()
RequestModel('s_m_y_cop_01')
end)
AddEventHandler('populationPedCreating', function(x, y, z, model, setters)
Citizen.Trace(('making cop at %s %s %s plus a bit (was %s)\n'):format(tostring(x), tostring(y), tostring(z), tostring(model)))
setters.setModel('s_m_y_cop_01') -- you can use a hash as well
setters.setPosition(x, y, z + 5.5)
-- you can also CancelEvent() to skip creating the ped
end)
setImmediate(() => {
RequestModel('s_m_y_cop_01')
})
on('populationPedCreating', (x, y, z, model, setters) => {
console.log(`Making cop at ${x} ${y} ${z} plus a bit (${model})`);
setters.setModel('s_m_y_cop_01') // you can use a hash as well
setters.setPosition(x, y, z + 5.5)
})
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 );
});