TheBossCl Posted May 12, 2022 Share Posted May 12, 2022 (edited) Marker = createMarker ( 2063.57104, -1831.39954, 13.54688-1, "cylinder", 4, 255, 0, 0, 127.5) Blip = createBlip ( 2063.57104, -1831.39954, 13.54688-1, 27, 2, 255, 0, 0, 255, 0, 250) Marker2 = createMarker ( 2056.77319, -1909.43298, 13.54688-1, "cylinder", 4, 255, 0, 0, 127.5) Blip2 = createBlip ( 2056.77319, -1909.43298, 13.54688-1, 27, 2, 255, 0, 0, 255, 0, 250) function onMarker(player) local veh = getPedOccupiedVehicle ( player ) local vida = getElementHealth ( veh ) precio = (1000 - vida)/2 if isElement(player) and getElementType(player) == "player" then local vehType = getVehicleType(veh) if vehType == "Automobile" or "Monster Truck" or "Quad" or "Bike" then if precio >= 1 then outputChatBox("el costo de la reparacion es: $"..precio..", si quieres repararlo escribe /reparar, sino /cancelar", player) setElementFrozen(veh, true) setVehicleEngineState ( veh, false) addCommandHandler("reparar", repararVeh) addCommandHandler("cancelar", cancelVeh) else outputChatBox("tu vehiculo no tiene daños, se ve de lujo :)", player, 0, 255, 0) end else outputChatBox("tu vehiculo no se puede reparar aqui :(") end end end function repararVeh(player) if (getPlayerMoney(player) >= precio)then takePlayerMoney(player, precio) outputChatBox("reparado con exito", player) local veh = getPedOccupiedVehicle ( player ) fixVehicle(veh) setVehicleEngineState ( veh, true) setElementFrozen(veh, false) else outputChatBox("no tienes suficiente dinero, tu dinero es: $"..getPlayerMoney(player)) end end function cancelVeh(player) local veh = getPedOccupiedVehicle ( player ) setVehicleEngineState ( veh, true) removeCommandHandler("reparar") removeCommandHandler("cancelar") end addEventHandler("onMarkerHit", Marker, onMarker) addEventHandler("onMarkerHit", Marker2, onMarker) What happens is that when entering the marker with a helicopter or another vehicle, it still reads from line 15 and in the console it tells me the following: [19:46:48] WARNING: fixVehicle2\server.lua:9: Bad argument @ 'getPedOccupiedVehicle' [Expected ped at argument 1, got vehicle] [19:46:54] WARNING: fixVehicle2\server.lua:10: Bad argument @ 'getElementHealth' [Expected element at argument 1, got boolean] [19:46:54] ERROR: fixVehicle2\server.lua:11: attempt to perform arithmetic on local 'vida' (a boolean value) Edited May 13, 2022 by xLive fix formatting Link to comment
Addlibs Posted May 13, 2022 Share Posted May 13, 2022 if vehType == "Automobile" or "Monster Truck" or "Quad" or "Bike" then evaluates as true because "Monster Truck" evaluates true because meaning it isn't false or nil, "Quad" and "Bike" are likewise evaluated as such. What you probably intended was if vehType == "Automobile" or vehType == "Monster Truck" or vehType == "Quad" or vehType == "Bike" then Link to comment
Scripting Moderators xLive Posted May 13, 2022 Scripting Moderators Share Posted May 13, 2022 (edited) Hi! Please use code highlighting when pasting code, this will make your code easier to read: Then select Lua. Don't worry about it now since I did it this time for you. 8 hours ago, TheBossCl said: [19:46:48] WARNING: fixVehicle2\server.lua:9: Bad argument @ 'getPedOccupiedVehicle' [Expected ped at argument 1, got vehicle] [19:46:54] WARNING: fixVehicle2\server.lua:10: Bad argument @ 'getElementHealth' [Expected element at argument 1, got boolean] [19:46:54] ERROR: fixVehicle2\server.lua:11: attempt to perform arithmetic on local 'vida' (a boolean value) function onMarker(player) local veh = getPedOccupiedVehicle ( player ) local vida = getElementHealth ( veh ) You get these errors because onMarkerHit also triggers for vehicles. You should check first if the element that hit the marker is a player using getElementType, and if veh exists before using getElementHealth since the player may not be in a vehicle. Edited May 13, 2022 by xLive Link to comment
TheBossCl Posted May 14, 2022 Author Share Posted May 14, 2022 Thank you very much everyone, you helped me 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