itHyperoX Posted September 22, 2017 Share Posted September 22, 2017 (edited) Hello, i'm working on a vehicle system, and again got some problem.... destroyElement - expected element at argument 1. Code: addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),function() targetSpawnedVeh = getElementData(source,"vehSpawned") if targetSpawnedVeh then destroyElement(targetSpawnedVeh) removeElementData(source,"vehSpawned") outputChatBox("success1") else outputChatBox("error") end end) addEventHandler("onResourceStop",resourceRoot,function() targetSpawnedVeh = getElementData(source,"vehSpawned") if targetSpawnedVeh then destroyElement(targetSpawnedVeh) removeElementData(source,"vehSpawned") outputChatBox("success2") else outputChatBox("error") end end) Always returning to "error" Edited September 22, 2017 by TheMOG Link to comment
Anubhav Posted September 22, 2017 Share Posted September 22, 2017 where are you setting the element data? Link to comment
pa3ck Posted September 22, 2017 Share Posted September 22, 2017 When checking if the element exists, try to use if isElement(vehicle) instead of just if vehicle. 1 Link to comment
itHyperoX Posted September 22, 2017 Author Share Posted September 22, 2017 4 hours ago, Anubhav said: where are you setting the element data? when player spawning the vehicle 42 minutes ago, pa3ck said: When checking if the element exists, try to use if isElement(vehicle) instead of just if vehicle. Tried, the same error. Link to comment
pa3ck Posted September 22, 2017 Share Posted September 22, 2017 Can you show us how you set the elementData, because if the isElement() doesn't fail, that means there's an element but not necessarily a vehicle. Link to comment
itHyperoX Posted September 22, 2017 Author Share Posted September 22, 2017 (edited) if #playercar == 1 then local x,y,z = getElementPosition(source) local vehicle = createVehicle(playercar[1].vehID,x + 5,y +2,z) setElementData(vehicle,"vehicle:Owner","vehicleSpawned") setElementData(vehicle,"vehicleSpawned",getPlayerName(source)) setElementData(source, "vehicleSpawned", vehicle) setElementData(vehicle,"VehOwner",getPlayerName(source)) vehicleSpawnMessage(1) else noVehicleOnSlot(1) end I checked with a command, and its working. addCommandHandler("test",function(source,cmd) veh = getElementData(source,"myVehicle1") isInVeh = getPedOccupiedVehicle ( source ) if isInVeh then if isElement(veh) then outputChatBox("The vehicle is spawned",source) else outputChatBox("The vehicle is not spawned",source) end else outputChatBox("Not in veh") end end) Edited September 22, 2017 by TheMOG Link to comment
pa3ck Posted September 22, 2017 Share Posted September 22, 2017 You're using the events onResourceStart and onResourceStop with "source" --> source is never going to be a player, it will always be the resource. What you should do is, when a resource starts, use a for loop to loop through every player. 1 Link to comment
itHyperoX Posted September 22, 2017 Author Share Posted September 22, 2017 13 minutes ago, pa3ck said: You're using the events onResourceStart and onResourceStop with "source" --> source is never going to be a player, it will always be the resource. What you should do is, when a resource starts, use a for loop to loop through every player. Niice thank you buddy. Working perfect 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