How to use native functions?

Hi, I’m trying to create an area where npc vehicles don’t have to spawn. I tried to create a plugin that uses RemoveVehiclesFromGeneratorsInArea native function.
__resource.lua

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
client_script 'client.lua'

client.lua

RemoveVehiclesFromGeneratorsInArea(-71.3, -1123.0, 20.0, 0.0, -1081.5, 40.0)

But it seems not working. So out of curiosity I tried to put the command in a loop and it seems to work. Code like:

Citizen.CreateThread(function()
    while true do
        Wait(0)
        RemoveVehiclesFromGeneratorsInArea(-71.3, -1123.0, 20.0, 0.0, -1081.5, 40.0)
    end
end)

But I don’t think it’s correct. I think there is a waste of resources. Does anyone have ideas?
I would like to know how to use native functions
Thank you in advance

https://runtime.fivem.net/doc/natives/#_0xBF1A602B5BA52FEE

What? Please explain :slight_smile:

Hi marco.paggioro, sorry but it’s for reply you but for ask you something i try to do the same thing of you but it didn’t work. Do you only put :slight_smile:
Citizen.CreateThread(function()
while true do
Wait(0)
RemoveVehiclesFromGeneratorsInArea(-71.3, -1123.0, 20.0, 0.0, -1081.5, 40.0)
end
end)
in your main.lua ?

I never used the native yet, but I’ll give you some advice. If you make loops try to go for the highest (acceptable) Wait(). For example, if you’re checking if a player still has a certain permission you can easily loop it over ~10-30 seconds without any issues (depending on the situation). In your case I’d go for 50-500ms, considering you don’t want the vehicles to appear for a second before they get de-spawned. Of course you’ll have to do some tweaking of your own to find the best value. Keep this in mind: The shorter the Wait(), the more performance it takes.

Thanks for your advice. i’ll try this

It still don’t worck, any one else ??