BiSolpos Posted May 13, 2021 Share Posted May 13, 2021 Hello My code gives this error, what is the problem? Bad argument @ 'getPedOccupiedVehicle' [Expected ped at argument 1, got string 'Quit'] Bad argument @ 'getElementID' [Expected element at argument 1, got boolean] Code Server function ExitCar (thePlayer, seat, jacked) local theVehicle = getPedOccupiedVehicle (thePlayer) local vehid = getElementID (theVehicle) if vehid == "1" or vehid == "2" or vehid == "3" or vehid == "4" or vehid == "5" or vehid == "6" then if getElementData(thePlayer, "onMark") then if seat == 0 then destroyElement(getElementData(thePlayer, "onMark")) end end end end addEventHandler("onVehicleStartExit", getRootElement(), ExitCar) addEventHandler("onPlayerQuit", getRootElement(), ExitCar) Thank you Link to comment
SpecT Posted May 13, 2021 Share Posted May 13, 2021 (edited) Hey, The problem is that the events onVehicleStartExit and onPlayerQuit have different parameters and your function is made to handle the arguments only from onVehicleStartExit. You can check out the documentations (the links above) of the two events and see what parameters they have. Simple example: when a player leaves (onPlayerQuit) the first argument is quitType and in your function it's thePlayer. This is why you get "Quit" as player and it can't get the occupied vehicle of "Quit" as it's expecting a ped not string. This should do the trick: function ExitCar (playerORquitType, seat) local thePlayer = playerORquitType local seat = seat if(type(thePlayer) ~= "player") then -- if the function is triggered by onPlayerQuit thePlayer = source -- in onPlayerQuit the player who left is "source" end if(type(seat) ~= "number") then -- if the function is triggered by onPlayerQuit; there is no argument for seat seat = getPedOccupiedVehicleSeat(thePlayer) -- so we get the seat of the player end local theVehicle = getPedOccupiedVehicle (thePlayer) local vehid = getElementID (theVehicle) if vehid == "1" or vehid == "2" or vehid == "3" or vehid == "4" or vehid == "5" or vehid == "6" then local onMark = getElementData(thePlayer, "onMark") or false -- we put this in a variable so we don't make unnecessary calls if onMark then if seat and seat == 0 then destroyElement(onMark) end end end end addEventHandler("onVehicleStartExit", getRootElement(), ExitCar) addEventHandler("onPlayerQuit", getRootElement(), ExitCar) *PS: Please, don't just copy and paste it but try to understand how it works. It might help you in future similar situations. Edited May 13, 2021 by SpecT 1 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