Jump to content

Nearest Vehicle repair


gerlachmax123

Recommended Posts

Why this doesnt work?

function getNearestVehicle( player ) 
    local x, y, z = getElementPosition( player ) 
    local prevDistance 
    local nearestVehicle 
    for i, v in ipairs( getElementsByType( "vehicle" ) ) do 
        local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( v ) ) 
        if distance <= ( prevDistance or distance + 1 ) then 
            prevDistance = distance 
            nearestVehicle = v 
        end 
    end 
    return nearestVehicle or false 
end 
  
function doSomethingWithTheNearestVeh( player ) 
    local vehicle = getNearestVehicle( player )  
    if vehicle then 
        if not getPedOccupiedVehicle( player ) then 
            if isfeuerwehr ( player ) then 
                if (getPedWeapon (player) == 42) then 
                    if (getElementHealth ( vehicle ) <= 255 
                       setPedAnimation( player, "FLAME", "FLAME_fire" )  
                       setTimer( setPedAnimation, 15000, 1, player )  
                       setElementHealth( vehicle, 255 )  
                    else 
                        outputChatBox ( "Dieses Fahrzeug brennt nicht!", player, 125, 0, 0 ) 
                    end                  
                else 
                    outputChatBox ( "Du hast keinen Feuerloescher!", player, 125, 0, 0 ) 
                end 
            else     
                outputChatBox ( "Du bist kein Mitglied der Feuerwehr!", player, 125, 0, 0 ) 
            end 
        else     
            outputChatBox ( "Du musst vor der Motorhaube des Fahrzeuges stehen!", player, 125, 0, 0 ) 
        end 
    end 
end 
addCommandHandler( "loeschen", doSomethingWithTheNearestVeh ) 

And how i can set the distance to 5m ?

So I can repair the Vehicle (thats burning) only in 5 m

Link to comment

So?

function getNearestVehicle( player ) 
    local x, y, z = getElementPosition( player ) 
    local prevDistance 
    local nearestVehicle 
    for i, v in ipairs( getElementsByType( "vehicle" ) ) do 
        local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( v ) ) 
        if distance <= ( prevDistance or distance + 1 ) then 
            prevDistance = distance 
            nearestVehicle = v 
        end 
    end 
    return nearestVehicle or false 
end 
  
function doSomethingWithTheNearestVeh( player ) 
    local vehicle = getNearestVehicle( player )  
    local x1, y1, z1 = getElementPosition ( vehicle ) 
    local x2, y2, z2 = getElementPosition ( player ) 
    if vehicle then 
        if not getPedOccupiedVehicle( player ) then 
            if isfeuerwehr ( player ) then 
                if (getPedWeapon (player) == 42) then 
                    if getDistanceBetweenPoints3D ( x1, y1, z1, x2, y2, z2 ) < 5 then 
                        if (getElementHealth ( vehicle ) <= 255 
                            setPedAnimation( player, "FLAME", "FLAME_fire" )  
                            setTimer( setPedAnimation, 15000, 1, player )  
                            setElementHealth( vehicle, 255 )  
                        else 
                            outputChatBox ( "Dieses Fahrzeug brennt nicht!", player, 125, 0, 0 ) 
                        end      
                    else 
                        outputChatBox ( "Hier ist kein Fahrzeug zum Reparieren!", player, 125, 0, 0 ) 
                    end 
                else 
                    outputChatBox ( "Du hast keinen Feuerloescher!", player, 125, 0, 0 ) 
                end 
            else     
                outputChatBox ( "Du bist kein Mitglied der Feuerwehr!", player, 125, 0, 0 ) 
            end 
        else     
            outputChatBox ( "Du musst vor der Motorhaube des Fahrzeuges stehen!", player, 125, 0, 0 ) 
        end 
    end 
end 
addCommandHandler( "loeschen", doSomethingWithTheNearestVeh ) 

Link to comment
function getNearestVehicle( player ) 
    local x, y, z = getElementPosition( player ) 
    local prevDistance 
    local nearestVehicle 
    for i, v in ipairs( getElementsByType( "vehicle" ) ) do 
        local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( v ) ) 
        if distance <= ( prevDistance or distance + 1 ) then 
            prevDistance = distance 
            nearestVehicle = v 
        end 
    end 
    return nearestVehicle or false 
end 
  
function doSomethingWithTheNearestVeh( player ) 
    local vehicle = getNearestVehicle( player )  
    local x1, y1, z1 = getElementPosition ( vehicle ) 
    local x2, y2, z2 = getElementPosition ( player ) 
    if vehicle then 
        if not getPedOccupiedVehicle( player ) then 
            if isfeuerwehr ( player ) then 
                if (getPedWeapon (player) == 42) then 
                    if getDistanceBetweenPoints3D ( x1, y1, z1, x2, y2, z2 ) < 5 then 
                        if (getElementHealth ( vehicle ) <= 255 ) then 
                            setPedAnimation( player, "FLAME", "FLAME_fire" )  
                            setTimer( setPedAnimation, 15000, 1, player )  
                            setElementHealth( vehicle, 255 )  
                        else 
                            outputChatBox ( "Dieses Fahrzeug brennt nicht!", player, 125, 0, 0 ) 
                        end      
                    else 
                        outputChatBox ( "Hier ist kein Fahrzeug zum Reparieren!", player, 125, 0, 0 ) 
                    end 
                else 
                    outputChatBox ( "Du hast keinen Feuerloescher!", player, 125, 0, 0 ) 
                end 
            else     
                outputChatBox ( "Du bist kein Mitglied der Feuerwehr!", player, 125, 0, 0 ) 
            end 
        else     
            outputChatBox ( "Du musst vor der Motorhaube des Fahrzeuges stehen!", player, 125, 0, 0 ) 
        end 
    end 
end 
addCommandHandler( "loeschen", doSomethingWithTheNearestVeh ) 

Link to comment

Thanks. Bare in mind that it may seem basic now and some features not working properly if at all but I'm doing all I can do make it as bug free as possible. My first approach was wrong when I kept adding new things and fixed a few bugs now and then. Currently, I wait for people to report bug or give requests for new features before I start working on a new version so that I can fix the bugs first. Anyway, this is going off topic. If you want you can post in MTASE topic or PM with requests. I will also need a tester.

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...