Jump to content

Functions: isEventAlreadyHandled, isPlayerInMarker


50p

Recommended Posts

ifEventAlreadyHandled

: addEventHandler: is already handled - Line:

This message comes if you want to addEventHandler the same function. How to avoid it?

To avoid it I have to use a boolean variable which is set to true when I add the handler and is set to false when I remove the handler. So I know if the event was handled already or not.

If we had isEvenAlreadyHandled we didn't have to do the trick that I do.

isPlayerInMarker

Same trick here. We have to create a variable and set it to true when player enters marker or to false when player leaves marker. That's the way I created isPlayerInBank in bank script to check whether player can use commands.

Link to comment

events problem:

(not tested)

_events = {} 
_addEventHandler = addEventHandler 
function addEventHandler ( event, element, function ) 
    if ( _addEventHandler ( event, element, function ) ) then 
        _events.insert ( { event, element, function } ) 
        return true 
    end 
    return false 
end 
  
_removeEventHandler = removeEventHandler 
function removeEventHandler ( event, element, function ) 
    for i, event in ipairs ( _events ) do 
        if ( ( event[1] == event ) and ( event[2] == element ) and ( event[3] == function ) ) then 
            _events.remove ( i ) 
        end 
    end 
    return _removeEventHandler ( event, element, function ) 
end 
  
function isEventHandled ( event, function ) 
    for i, event in ipairs ( _events ) do 
        if ( ( event[1] == event ) and ( event[2] == element ) and ( event[3] == function ) ) then 
            return true 
        end 
    end 
    return false 
end 
  

and isPlayerInMarker, mta is not going to use low level functions like that, player is an element and markers have ther own col shape so

function isPlayerInMarker ( player, marker ) 
    return isElementWithinColShape ( player, getElementColShape ( marker ) ) 
end 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...