Jump to content

Why is this being triggered?


Recommended Posts

Why is this being triggered before the addEventHandler is being triggered?

function MarkerHit() 
    destroyElement(injured) 
    destroyElement(marker1) 
    destroyElement(blipp) 
end 

It is just automatically destroying the elements before the marker is being hit!

Link to comment
Where is the handler?

Most likely not bound to a specific marker, but all markers.

Here it is,

function enterVehicle ( thePlayer, seat, jacked ) -- when a player enters a vehicle 
    if ( ambVehicle[getElementModel ( source )] ) and ( ambSkin[getElementModel ( thePlayer )] ) then 
        outputChatBox ( "RADIO: An accident has happened, all units respond!", client, 0, 0, 200) 
        injured = createPed (233, 1203, -1520, 14) 
        setPedAnimation(injured, "CRACK" ,"crckidle2", 150000000, true) 
        blipp = createBlipAttachedTo(injured, 22) 
        local marker1 = createMarker(500.03125, -1319.93359375, 14.099959373474, "cylinder", .5, 0, 222, 0, 100) 
        attachElements (marker1, injured) 
        addEventHandler( "onMarkerHit", marker1, MarkerHit ) 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) 
  
function MarkerHit() 
    destroyElement(injured) 
    destroyElement(marker1) 
    destroyElement(blipp) 
end 
  
  
  

Link to comment

I'm guessing that it's because the ped you're attaching the marker to is triggering onMarkerHit because marker gets positioned right where that ped is. To avoid this use a check in MarkerHit function:

  
function MarkerHit(hitElement) 
    if hitElement ~= injured then 
          destroyElement(injured) 
          destroyElement(marker1) 
          destroyElement(blipp) 
    end 
end 
  

Link to comment
I'm guessing that it's because the ped you're attaching the marker to is triggering onMarkerHit because marker gets positioned right where that ped is. To avoid this use a check in MarkerHit function:
  
function MarkerHit(hitElement) 
    if hitElement ~= injured then 
          destroyElement(injured) 
          destroyElement(marker1) 
          destroyElement(blipp) 
    end 
end 
  

Perfect, thank you!

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