TriggerClientEvent to more than one player

I get into some situations which a lot of players should get an event, but not everyone, for example half of the server, when I think about it, if 1024 players are online, looping TriggerClientEvent to 512 players could be hard to the CPU to handle. (I don’t wanna send unnecessary events for these who shouldn’t get it anyway)

My suggestion is to change the TriggerClientEvent function’s send argument to player/table of players, which will let us use this function only one time and send it to all of the players without any unnecessary loops (I know it will loop anyway, but it’s easier to loop in C++ instead of lua). I have these tables of players for something else also, so I think it will reduce a lot CPU usage for me and who else have them and just loop them now. Even if you don’t have these tables, I think it will be easier for the server to loop table.insert instead of TriggerClientEvent, so it’s a win anyway.

Uh, you’re simplifying it too much.

Passing ‘tables’ or other complex types to such natives would require serialization/deserialization, which also involves a lot of per-ScRT HLL code which is likely to be slower than just N native calls also due to GC pressure.

2 Likes

thanks