Jump to content

I need help with this code of fixSystem


Recommended Posts

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 by xLive
fix formatting
Link to comment
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

Hi!
Please use code highlighting when pasting code, this will make your code easier to read:
MSHAyJ3.png
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 by xLive
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...