the goal was to start a ptfx on the players ped if H was pressed only in vehicles (for something i had planned) but cant get it working tried differant ptfx and fx but nothing worked as it is it just freezes fivem when H is pressed
i had it as client could be wrong? and thats the only file any help would be sweet.
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsPedSittingInAnyVehicle(GetPlayerPed(-1)) then
if IsControlJustPressed(1, 74) then
local coords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), false, false, false)
local ptfx = "core"
local fx = "veh_exhaust_truck_rig"
local fx_loop = 25
local i=0
while (i<fx_loop) do
RequestNamedPtfxAsset(ptfx)
StartParticleFxLoopedAtCoord(fx, coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 0x3F800000, false, false, false)
local i=i+1
end
end
end
end
end)
IsControlJustPressed() returns only true once while holding it, after that it returns false until the player lets go of the button and presses it again.
local i = 0 is fine, but in the while (i < fx_loop) do loop there’s a few things wrong:
There’s no Citizen.Wait(0), which is probably why it freezes the game or creates “lag spikes” if the loop is only short.
You’re not actually incrementing i by 1 each time, what you’re really doing is you’re re-creating the variable locally inside the while loop. Which means that it will be set to 0 + 1 each time and the i from the section above is never changed, so the while loop will run forever (and without the wait it’ll just freeze/crash the game.
The particles won’t ever display because you’re not using UseParticleFxAssetNextCall().
This particle effect would probably continue forever, as you’re creating a new particle effect each time but you’re never actually stopping any of them. So even if the code above worked, it’d still create 25 times the same particle at the same location, and never get rid of them.
You’re using GetOffsetFromEntityInWorldCoords() wrong, you’re providing boolean values when you should be providing float values instead, also if you don’t want the particle to be anywhere “offset” from the player, why not use GetEntityCoords() instead?
I’ll test some stuff and try to get a working example for you in a bit.
well thanks it was just something i threw together dont really know lua but know alot of the natives if you could sort an example of it working like that ^^ thatd be great i could hopefully figure it out from there and 5 i tried get entitycoords but get errors and didnt of that i just thought it was right.
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = PlayerPedId()
-- If the player is in a vehicle.
if IsPedInAnyVehicle(PlayerPedId(), false) then
-- If the player presses H (74)
if IsControlJustPressed(0, 74) then
-- Save the particle dictionary name and particle name in local variables.
local particleDictionary = "core"
local particleName = "veh_exhaust_truck_rig"
-- Define the amount of particle effects to start.
local loopAmount = 25
-- Load the particle dictionary.
RequestNamedPtfxAsset(particleDictionary)
-- Wait until it's done loading.
while not HasNamedPtfxAssetLoaded(particleDictionary) do
Citizen.Wait(0)
end
-- Create a table to save all of the particle effects in so we can stop them
-- 1 second after starting them.
local particleEffects = {}
-- Loop from 0 to the loop amount defined above.
for x=0,loopAmount do
-- Specify which particle dicitonary we'll be using in the next particle call.
UseParticleFxAssetNextCall(particleDictionary)
-- Start the particle effect and stick it to the player's vehicle
-- with 0.0 offset and 0.0 rotation for each axis.
-- Set the scale to 3.0 to create some bigger smoke.
local particle = StartParticleFxLoopedOnEntity(particleName, GetVehiclePedIsIn(ped, false), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, false, false, false)
-- Add the particle effect to the table.
table.insert(particleEffects, 1, particle)
-- Prevent freezing.
Citizen.Wait(0)
end
-- Wait 1 second (or however long you want it to last)
Citizen.Wait(1000)
-- Then loop through all particle effects in the table.
for _,particle in pairs(particleEffects) do
-- Stopping each particle effect.
StopParticleFxLooped(particle, true)
end
end
end
end
end)
Unless you make sure the particle dictionary is loaded on all clients
Or if that doesn’t work, make it an event and just have that triggered and get all players to “spawn” those particles at the player’s vehicle location.
If you figured out the syncing with other players let me know! Would I need to make a server event? Or is it possible to do though just a client script?