Egekan Posted May 20, 2018 Share Posted May 20, 2018 (edited) Hello, I've made a carspawner script. function spawnveh(plr,veh,x,y,z,rx,ry,rz) for k,v in ipairs(getElementsByType("vehicle")) do if v and getElementData(v,"owner") == getPlayerName(plr) then destroyElement(v) end end local xx,yy,zz = getElementPosition(plr) local veh = createVehicle(getVehicleModelFromName(veh),xx,yy,zz,rx,ry,rz,"Egekan") setElementData(veh,"owner",getPlayerName(plr)) setVehicleColor(veh,255,100,15,255,100,15) warpPedIntoVehicle(plr,veh) setElementFrozen(plr,false) end addEvent("Spawn",true) addEventHandler("Spawn",getRootElement(),spawnveh) Everything works fine, I'can spawn the vehicle by clicking the spawn button from client side but: It seems like this custom event triggers "onClientVehicleEnter" event for 4 or more times. When I put outputChatBox function which is handled by "onClientVehicleEnter", I always get 4 outputs once. I have also a vehiclehud script, so the hud displays for 4 times when you spawn a vehicle. But everyting is fine if I spawn the vehicle with adminpanel, or just enter a vehicle with "F" key. This is another carspawner script made by me, when I spawn the vehicle using the button in this one everything is fine just like adminpanel. function spawnveh(plr,vehid) local x,y,z = getElementPosition(plr) local rx,ry,rz = getElementRotation(plr) local allvehicles = getElementsByType("Vehicle") for k,v in ipairs(allvehicles) do if getElementData(v,"Owner") == getAccountName(getPlayerAccount(plr)) then destroyElement(v) end end if getPedOccupiedVehicle(plr) then destroyElement(getPedOccupiedVehicle(plr)) end if getVehicleNameFromModel(vehid) then vehicle = createVehicle(vehid,x,y,z,rx,ry,rz,"Ege FTW") setElementData(vehicle,"Owner",getAccountName(getPlayerAccount(plr))) warpPedIntoVehicle(plr,vehicle) end if getVehicleModelFromName(vehid) then vehicle = createVehicle(getVehicleModelFromName(vehid),x,y,z,rx,ry,rz,"Ege FTW") setElementData(vehicle,"Owner",getAccountName(getPlayerAccount(plr))) warpPedIntoVehicle(plr,vehicle) end end addEvent("spawnVehServer",true) addEventHandler("spawnVehServer",getRootElement(),spawnveh) They both are nearly same. Edited May 20, 2018 by Egekan Link to comment
TEDERIs Posted May 20, 2018 Share Posted May 20, 2018 Hello, are you alone on the server when this issue appears? Link to comment
Egekan Posted May 20, 2018 Author Share Posted May 20, 2018 28 minutes ago, TEDERIs said: Hello, are you alone on the server when this issue appears? Yes I'm the only player on the server, as I said second spawner script works fine. There must be something wrong with the first one. Link to comment
TEDERIs Posted May 20, 2018 Share Posted May 20, 2018 I have tried to reproduce the issue, but all is fine. It seems like a bug. I faced similar issues in the past and server restarting only helped me. Link to comment
N3xT Posted May 20, 2018 Share Posted May 20, 2018 Don't put the outputChatBox inside the loop. Link to comment
Egekan Posted May 20, 2018 Author Share Posted May 20, 2018 (edited) 10 hours ago, N3xT said: Don't put the outputChatBox inside the loop. outputChatBox is not the main problem for me. I get more than one outputs even if I get the output with another resource which has onClientVehicleEnter handler. This affects everything for example if I draw DX thing with onClientVehicleEnter handler, everything will be doubled. I will make a new one, seems like there is no solution. Thanks to the people who tried to help me. Topic can be locked Edited May 20, 2018 by Egekan Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now