Robbster

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 ) 

Share this post


Link to post
local vehicleHealth = getElementHealth ( playerVehicle ) 

You see ( playerVehicle ) This argument should be ( vehicle ) .

Share this post


Link to post

I changed that Pre[T]ege, but now it says I need to be in a vehicle when i go through the marker

Share this post


Link to post
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 ) 

Share this post


Link to post

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 ) 

Share this post


Link to post

And you are taking the money on client side, bad idea.

Note: Using this function client side (not recommended) will not change a players money server side.

Share this post


Link to post
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

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

Isn't the code from each function the same? if so, then you can just use one function, that would be a lot more efficient.

Share this post


Link to post
And you are taking the money on client side, bad idea.

Note: Using this function client side (not recommended) will not change a players money server side.

It's a fake money also the fix vehicle .

:roll:

Share this post


Link to post

He has to use triggerServerEvent to take/fix it server side.

Share this post


Link to post

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.