Jump to content

Vehicle Fix


Recommended Posts

I get this debug error

ERROR: line 18: attempt to compare boolean with number

It's supposed to when you enter the marker see if your vehicle health is below 100% if it is, it fixes it, if not it does nothing.

UKMarker = createMarker ( -2079.88, 2099.58, 15.5,"cylinder",6.0,255,255,0,125) 
USAMarker = createMarker (349.18, 2540.00, 15.5,"cylinder",6.0,255,255,0,125) 
RUSMarker = createMarker ( 2205.92, -219.31, 16.5,"cylinder",6.0,255,255,0,125) 
GERMarker = createMarker ( -1088.41, -1036.57, 128.25,"cylinder",6.0,255,255,0,125) 
  
UKBlip = createBlipAttachedTo ( UKMarker,63, 1,0,0,0,255,0,3000,getRootElement()) 
USABlip = createBlipAttachedTo ( USAMarker,63, 1,0,0,0,255,0,3000,getRootElement()) 
RUSBlip = createBlipAttachedTo ( RUSMarker,63, 1,0,0,0,255,0,3000,getRootElement()) 
GERBlip = createBlipAttachedTo ( GERMarker,63, 1,0,0,0,255,0,3000,getRootElement()) 
     
  
function fixUK ( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
        if ( getElementType ( hitPlayer ) == "player" ) then 
            local vehicle = getPedOccupiedVehicle ( hitPlayer ) 
            if ( vehicle ) then 
            local vehicleHealth = getElementHealth ( playerVehicle ) 
            if vehicleHealth <= 100 then 
                fadeCamera ( false ) 
                --toggleAllControls ( false ) 
                setElementFrozen ( vehicle, true ) 
                setTimer ( 
                    function ( ) 
                        fixVehicle ( vehicle ) 
                        --toggleAllControls ( true ) 
                        setElementFrozen ( vehicle, false ) 
                        fadeCamera ( true ) 
                        takePlayerMoney(250) 
                        outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                    end 
                    , 2000, 1 
                ) 
            else 
                outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) 
            end 
            end 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", UKMarker, fixUK ) 

Link to comment
function fixUK ( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
            local vehicle = getPedOccupiedVehicle ( hitPlayer ) 
            if not ( vehicle ) then outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) return end 
            local vehicleHealth = getElementHealth ( vehicle ) 
            if vehicleHealth <= 100 then 
                fadeCamera ( false ) 
                --toggleAllControls ( false ) 
                setElementFrozen ( vehicle, true ) 
                setTimer ( 
                    function ( ) 
                        fixVehicle ( vehicle ) 
                        --toggleAllControls ( true ) 
                        setElementFrozen ( vehicle, false ) 
                        fadeCamera ( true ) 
                        takePlayerMoney(250) 
                        outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                    end 
                    , 2000, 1 
                ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", UKMarker, fixUK ) 

Link to comment

Is that what you wanted to?

UKMarker = createMarker ( -2079.88, 2099.58, 15.5,"cylinder",6.0,255,255,0,125) 
USAMarker = createMarker (349.18, 2540.00, 15.5,"cylinder",6.0,255,255,0,125) 
RUSMarker = createMarker ( 2205.92, -219.31, 16.5,"cylinder",6.0,255,255,0,125) 
GERMarker = createMarker ( -1088.41, -1036.57, 128.25,"cylinder",6.0,255,255,0,125) 
  
UKBlip = createBlipAttachedTo ( UKMarker,63, 1,0,0,0,255,0,3000,getRootElement()) 
USABlip = createBlipAttachedTo ( USAMarker,63, 1,0,0,0,255,0,3000,getRootElement()) 
RUSBlip = createBlipAttachedTo ( RUSMarker,63, 1,0,0,0,255,0,3000,getRootElement()) 
GERBlip = createBlipAttachedTo ( GERMarker,63, 1,0,0,0,255,0,3000,getRootElement()) 
  
function fixUK ( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
        if ( getElementType ( hitPlayer ) == "player" ) then 
            local vehicle = getPedOccupiedVehicle ( hitPlayer ) 
            if ( vehicle ) then 
                local vehicleHealth = getElementHealth ( vehicle ) 
                if ( vehicleHealth < 1000 ) then 
                    fadeCamera ( false ) 
                    --toggleAllControls ( false ) 
                    setElementFrozen ( vehicle, true ) 
                    setTimer ( 
                        function ( ) 
                            fixVehicle ( vehicle ) 
                            --toggleAllControls ( true ) 
                            setElementFrozen ( vehicle, false ) 
                            fadeCamera ( true ) 
                            takePlayerMoney ( 250 ) 
                            outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                        end 
                    , 2000, 1 
                    ) 
                end 
            else 
                outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", UKMarker, fixUK ) 

Link to comment
function fixUK ( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
            local vehicle = getPedOccupiedVehicle ( hitPlayer ) 
            if not ( vehicle ) then outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) return end 
            local vehicleHealth = getElementHealth ( vehicle ) 
            if vehicleHealth <= 100 then 
                fadeCamera ( false ) 
                --toggleAllControls ( false ) 
                setElementFrozen ( vehicle, true ) 
                setTimer ( 
                    function ( ) 
                        fixVehicle ( vehicle ) 
                        --toggleAllControls ( true ) 
                        setElementFrozen ( vehicle, false ) 
                        fadeCamera ( true ) 
                        takePlayerMoney(250) 
                        outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                    end 
                    , 2000, 1 
                ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", UKMarker, fixUK ) 

Thanks you fixed it

Link to comment

Another issue D: It outputs the message 3 times, when you go and get the vehicle fixed.

  
function fixUK ( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
            local vehicle = getPedOccupiedVehicle ( hitPlayer ) 
            if not ( vehicle ) then outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) return end 
            local vehicleHealth = getElementHealth ( vehicle ) 
            if vehicleHealth <= 950 then 
                fadeCamera ( false ) 
                --toggleAllControls ( false ) 
                setElementFrozen ( vehicle, true ) 
                setTimer ( 
                    function ( ) 
                        fixVehicle ( vehicle ) 
                        --toggleAllControls ( true ) 
                        setElementFrozen ( vehicle, false ) 
                        fadeCamera ( true ) 
                        takePlayerMoney(250) 
                        outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                    end 
                    , 2000, 1 
                ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", UKMarker, fixUK ) 
  
  
function fixUSA ( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
            local vehicle2 = getPedOccupiedVehicle ( hitPlayer ) 
            if not ( vehicle2 ) then outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) return end 
            local vehicleHealth2 = getElementHealth ( vehicle2 ) 
            if vehicleHealth2 <= 950 then 
                fadeCamera ( false ) 
                --toggleAllControls ( false ) 
                setElementFrozen ( vehicle2, true ) 
                setTimer ( 
                    function ( ) 
                        fixVehicle ( vehicle2 ) 
                        --toggleAllControls ( true ) 
                        setElementFrozen ( vehicle2, false ) 
                        fadeCamera ( true ) 
                        takePlayerMoney(250) 
                        outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                    end 
                    , 2000, 1 
                ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", USAMarker, fixUSA ) 
  
  
function fixUK ( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
            local vehicle3 = getPedOccupiedVehicle ( hitPlayer ) 
            if not ( vehicle3 ) then outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) return end 
            local vehicleHealth3 = getElementHealth ( vehicle3 ) 
            if vehicleHealth3 <= 950 then 
                fadeCamera ( false ) 
                --toggleAllControls ( false ) 
                setElementFrozen ( vehicle3, true ) 
                setTimer ( 
                    function ( ) 
                        fixVehicle ( vehicle3 ) 
                        --toggleAllControls ( true ) 
                        setElementFrozen ( vehicle3, false ) 
                        fadeCamera ( true ) 
                        takePlayerMoney(250) 
                        outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                    end 
                    , 2000, 1 
                ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", UKMarker, fixUK ) 
  
  
function fixUK ( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
            local vehicle4 = getPedOccupiedVehicle ( hitPlayer ) 
            if not ( vehicle4 ) then outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) return end 
            local vehicleHealth4 = getElementHealth ( vehicle4 ) 
            if vehicleHealth4 <= 950 then 
                fadeCamera ( false ) 
                --toggleAllControls ( false ) 
                setElementFrozen ( vehicle4, true ) 
                setTimer ( 
                    function ( ) 
                        fixVehicle ( vehicle4 ) 
                        --toggleAllControls ( true ) 
                        setElementFrozen ( vehicle4, false ) 
                        fadeCamera ( true ) 
                        takePlayerMoney(250) 
                        outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                    end 
                    , 2000, 1 
                ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", UKMarker, fixUK ) 
  

P.S The markers are created before the script don't worry

Link to comment

try this:

function fixScript( hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then 
            local vehicle = getPedOccupiedVehicle ( hitPlayer ) 
            if not ( vehicle ) then outputChatBox ( "You need to be in a vehicle!", 255, 0, 0 ) return end 
            local vehicleHealth = getElementHealth ( vehicle ) 
            if vehicleHealth <= 950 then 
                fadeCamera ( false ) 
                --toggleAllControls ( false ) 
                setElementFrozen ( vehicle, true ) 
                setTimer ( 
                    function ( ) 
                        fixVehicle ( vehicle ) 
                        --toggleAllControls ( true ) 
                        setElementFrozen ( vehicle, false ) 
                        fadeCamera ( true ) 
                        takePlayerMoney(250) 
                        outputChatBox ( "Your vehicle was fixed for $250!", 255, 0, 0 ) 
                    end 
                    , 2000, 1 
                ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", UKMarker, fixScript ) 
addEventHandler ( "onClientMarkerHit", USAMarker,fixScript) 
addEventHandler ( "onClientMarkerHit", RUSMarker,fixScript) 
addEventHandler ( "onClientMarkerHit", GERMarker,fixScript) 

Edited by Guest
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...