Jump to content

Stop function


Recommended Posts

Hi,

My script works, but i get some warning and error. I wanted to know how stop the function for avoid get this error, i try the "return" but it doesn't work.

myblip1 = createBlip ( 1177,-1323,329.48090,22)  -- LOS SANTOS 
marker1 = createMarker( 1177,-1323,13,"cylinder",1.5,255,0,0,225,getRootElement())  -- LOS SANTOS 
setBlipVisibleDistance( myblip1, 1500 ) 
  
myblip2 = createBlip ( -2651.3,626.7,329.48090,22)  -- SF 
marker2 = createMarker( -2651.3,626.7,13.5,"cylinder",1.5,255,0,0,225,getRootElement()) --SF 
setBlipVisibleDistance( myblip2, 1500 ) 
  
myblip3 = createBlip ( 1608,1821,329.48090,22) -- LV 
marker3 = createMarker( 1608,1821,9.5,"cylinder",1.5,255,0,0,225,getRootElement()) -- LV 
setBlipVisibleDistance( myblip3, 1500 ) 
  
function health ( hitElement, matchingDimension )   
    if isPedInVehicle ( hitElement ) then 
        outputChatBox ("You are in a vehicle", hitElement, 0 ,255, 0 ) 
        else 
            local ph = getElementHealth(hitElement) 
            local ap = getPedArmor(hitElement)  
                if ap < 100 then 
                setPedArmor ( hitElement, 100 ) 
                takePlayerMoney( hitElement, 250 ) 
                outputChatBox ("You have set your armor to 100 for 250$.", hitElement, 0 ,255, 0 ) 
                end 
                if ph < 100 then 
                outputChatBox ( "You have set your health to 100 for 250$.", hitElement, 0, 255, 0 ) 
                setElementHealth ( hitElement, 100 ) 
                setPedArmor ( hitElement, 100 ) 
                takePlayerMoney( hitElement, 250) 
                end 
    end     
end 
        addEventHandler( "onMarkerHit", marker1, health ) 
 function health ( hitElement, matchingDimension )   
    if isPedInVehicle ( hitElement ) then 
        outputChatBox ("You are in a vehicle", hitElement, 0 ,255, 0 ) 
        else 
            local ph = getElementHealth(hitElement) 
            local ap = getPedArmor(hitElement)  
                if ap < 100 then 
                setPedArmor ( hitElement, 100 ) 
                takePlayerMoney( hitElement, 250 ) 
                outputChatBox ("You have set your armor to 100 for 250$.", hitElement, 0 ,255, 0 ) 
                end 
                if ph < 100 then 
                outputChatBox ( "You have set your health to 100 for 250$.", hitElement, 0, 255, 0 ) 
                setElementHealth ( hitElement, 100 ) 
                setPedArmor ( hitElement, 100 ) 
                takePlayerMoney( hitElement, 250) 
                end 
    end     
end 
        addEventHandler( "onMarkerHit", marker2, health ) 
  
function health ( hitElement, matchingDimension )   
    if isPedInVehicle ( hitElement ) then 
        outputChatBox ("You are in a vehicle", hitElement, 0 ,255, 0 ) 
        else 
            local ph = getElementHealth(hitElement) 
            local ap = getPedArmor(hitElement)  
                if ap < 100 then 
                setPedArmor ( hitElement, 100 ) 
                takePlayerMoney( hitElement, 250 ) 
                outputChatBox ("You have set your armor to 100 for 250$.", hitElement, 0 ,255, 0 ) 
                end 
                if ph < 100 then 
                outputChatBox ( "You have set your health to 100 for 250$.", hitElement, 0, 255, 0 ) 
                setElementHealth ( hitElement, 100 ) 
                setPedArmor ( hitElement, 100 ) 
                takePlayerMoney( hitElement, 250) 
                end 
    end     
end 
        addEventHandler( "onMarkerHit", marker3, health )         
  
  
  
         
  

The error : When someone go on the marker with a vehicle, it's said :

- Warning at line 55 Bad argument @ IsPedinVehicle expected ped at argument 1, got vehicle

- Warning at line 59 Bad argument @ GetPedArmor expected ped at argument 1, got vehicle

- Error at line 60 attempt to compare bolean with number.

By the way if you can say me how to make different marker use the same function :)

Thank you :)

Link to comment

Parameter "source" in onMarkerHit event returns marker, not player. The hitElement argument is correct, do not change it.

This should return no warnings & I cleaned up code a bit for you.

local markers = { 
    createMarker(1177, -1323, 13, "cylinder", 1.5, 255, 0, 0, 225, getRootElement()), 
    createMarker(-2651.3, 626.7, 13.5, "cylinder", 1.5, 255, 0, 0, 225, getRootElement()), 
    createMarker(1608, 1821, 9.5, "cylinder", 1.5, 255, 0, 0, 225, getRootElement()) 
} 
  
myblip1 = createBlip(1177, -1323, 329.48090, 22)  -- LOS SANTOS 
setBlipVisibleDistance(myblip1, 1500) 
  
myblip2 = createBlip(-2651.3, 626.7, 329.48090, 22)  -- SF 
setBlipVisibleDistance(myblip2, 1500 ) 
  
myblip3 = createBlip(1608, 1821, 329.48090, 22) -- LV 
setBlipVisibleDistance(myblip3, 1500) 
  
function health(hitElement, matchingDimension) 
    for i=1, #markers do 
        if source == markers[i] then 
            if getElementType(hitElement) == "player" then 
                if isPedInVehicle(hitElement) then 
                    outputChatBox("You are in a vehicle", hitElement, 0 ,255, 0) 
                else 
                    local ph = getElementHealth(hitElement) 
                    local ap = getPedArmor(hitElement) 
                    if ap < 100 then 
                        setPedArmor(hitElement, 100) 
                        takePlayerMoney(hitElement, 250) 
                        outputChatBox("You have set your armor to 100 for 250$.", hitElement, 0 ,255, 0) 
                    end 
                    if ph < 100 then 
                        outputChatBox("You have set your health to 100 for 250$.", hitElement, 0, 255, 0) 
                        setElementHealth(hitElement, 100) 
                        setPedArmor(hitElement, 100) 
                        takePlayerMoney(hitElement, 250) 
                    end 
                end 
            end 
            break 
        end 
    end 
end 
addEventHandler("onMarkerHit", root, health) 

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