NovaCrew Posted January 31, 2023 Posted January 31, 2023 So I have an error that says Bad argument @ "getPedOccupiedVehicle" [Expected ped at argument 1, got nil] and I have no idea how to fix it. If someone could help me I would really appreciate it. local speed = 20 local buoyancy = 1.5 local drag = 1 function swimVehicle (vehicle, seat, jacked) local id = getPedOccupiedVehicle (vehicle) if id == 407 then local x, y, z = getElementPosition ( vehicle ) local level = getWaterLevel ( x, y, z ) if id == 407 and level and z < level then setElementData(vehicle, "buoyancy", 1.5) setElementData(vehicle, "vehicleDrag", 1) setElementData(vehicle, "centerOfMass", {0,0,-1}) setVehicleHandling(vehicle, "engineAcceleration", 20) else setElementData(vehicle, "buoyancy", 0) setElementData(vehicle, "vehicleDrag", 0) setVehicleHandling(vehicle, "engineAcceleration", 0) end end end addEventHandler("onClientRender", root, swimVehicle) 1
Rougue90 Posted January 31, 2023 Posted January 31, 2023 1 hour ago, NovaCrew said: local id = getPedOccupiedVehicle (vehicle) if id == 407 then getPedOccupiedVehicle() should be receiving LocalPlayer, and i will return the Element Vehicle. Then you can use GetElementID() to compare here. Something like this i believe: local id = getElementID(getPedOccupiedVehicle(LocalPlayer)) if id == '407' then --YOUR CODE If you have a doubt, just ask or if it helped, you can leave a thanks 1
Shady1 Posted January 31, 2023 Posted January 31, 2023 33 minutes ago, Rougue90 said: getPedOccupiedVehicle() should be receiving LocalPlayer, and i will return the Element Vehicle. Then you can use GetElementID() to compare here. Something like this i believe: local id = getElementID(getPedOccupiedVehicle(LocalPlayer)) if id == '407' then --YOUR CODE If you have a doubt, just ask or if it helped, you can leave a thanks hello there is error in your comment, I recommend you to use getElementModel instead of getElementID 1 1
Rougue90 Posted January 31, 2023 Posted January 31, 2023 (edited) 2 hours ago, Shady1 said: hello there is error in your comment, I recommend you to use getElementModel instead of getElementID Wow, indeed. I don't know why i did that way, Thank you So the verification must compared to an int value local id = getElementModel(getPedOccupiedVehicle(LocalPlayer)) if id == 407 then --YOUR CODE Edited January 31, 2023 by Rougue90 1
Shady1 Posted January 31, 2023 Posted January 31, 2023 1 hour ago, Rougue90 said: Wow, indeed. I don't know why i did that way, Thank you So the verification must compared to an int value local id = getElementModel(getPedOccupiedVehicle(LocalPlayer)) if id == 407 then --YOUR CODE yes, you can be more careful in such matters, recheck the information about what you did well before saying anything. I always say, it may be better to test and submit the correct codes, because the codes we publish may contain erroneous or incomplete typos. When I will share code samples in the forum community I will try the codes on my own test server and share the codes properly to MTA players, thank you for your help, have a nice day And I can express my special thanks for helping the player. 1
Shady1 Posted February 1, 2023 Posted February 1, 2023 29 minutes ago, NovaCrew said: Thanks for the help if you want more support please open a new thread and tag me, if you liked my help you can like my comments 1
FLUSHBICEPS Posted February 8, 2023 Posted February 8, 2023 local speed = 20 local buoyancy = 1.5 local drag = 1 function swimVehicle() local player = localPlayer local vehicle = getPedOccupiedVehicle(player) if vehicle and getElementModel(vehicle) == 407 then local x, y, z = getElementPosition(vehicle) local level = getWaterLevel(x, y, z) if z < level then setElementData(vehicle, "buoyancy", buoyancy) setElementData(vehicle, "vehicleDrag", drag) setElementData(vehicle, "centerOfMass", {0, 0, -1}) setVehicleHandling(vehicle, "engineAcceleration", speed) else setElementData(vehicle, "buoyancy", 0) setElementData(vehicle, "vehicleDrag", 0) setVehicleHandling(vehicle, "engineAcceleration", 0) end end end addEventHandler("onClientRender", root, swimVehicle)
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