Jump to content

Arrow in Head


Recommended Posts

ok can some one test this i'm not in my home to test it will it work? please test it

function arrow ( thePlayer ) 
    getElementPosition ( thePlayer ) 
    createMarker ( 0, 0, 0, "arrow", .75, 255, 0, 0, 175 ) 
    attachElements ( arrow, thePlayer, 0, 0, 2 ) 
    end 
end 
addCommandHandler ( "aduty", arrow ) 
  
  
  

Link to comment

like

function arrow ( thePlayer ) 
     local arrow = createMarker ( 0, 0, 0, "arrow", .75, 255, 0, 0, 175 ) 
     local duty = getElementData(thePlayer, "duty") or 0 
     if duty == 0 then 
    attachElements ( arrow, thePlayer, 0, 0, 2 ) 
else 
    destroyElement ( arrow ) 
end 
end 
end 
addCommandHandler("aduty",arrow) 

Link to comment
local arrow --define it local first, otherwise the variable will be lost as soon as the function is executed and reaches the end of it - it won't be there when you run the function again, thus you wouldn't be able to delete that marker. 
function arrowFunction ( thePlayer ) --conflict detected. Both the actual arrow and the function were stored under the same variable. 
  local duty = getElementData(thePlayer, "duty") or 0 
  if duty == 0 then 
    arrow = createMarker ( 0, 0, 0, "arrow", .75, 255, 0, 0, 175 ) 
    attachElements ( arrow, thePlayer, 0, 0, 2 ) 
  else 
    destroyElement ( arrow ) 
  end 
end 
addCommandHandler("aduty", arrowFunction) 

Link to comment

I don't know what the purpose of the element data, but i assume that you have some other code control the element data 'duty'.

arrowTable = {} 
  
addCommandHandler("aduty", 
function(player) 
    local duty = getElementData(player, "duty") or 0 
    if duty == 0 then 
        if not isElement(arrowTable[player]) then 
            arrowTable[player] = createMarker(0, 0, 0, "arrow", 0.75, 255, 0, 0, 175) 
        end 
        attachElements(arrowTable[player], player, 0, 0, 2) 
    else 
        if isElement(arrowTable[player]) then 
            destroyElement(arrowTable[player]) 
            arrowTable[player] = nil 
        end 
    end 
end) 
  
addEventHandler("onPlayerQuit", root, 
function() 
    if isElement(arrowTable[player]) then 
        destroyElement(arrowTable[player]) 
        arrowTable[player] = nil 
    end 
end) 

Link to comment
I don't know what the purpose of the element data, but i assume that you have some other code control the element data 'duty'.
arrowTable = {} 
  
addCommandHandler("aduty", 
function(player) 
    local duty = getElementData(player, "duty") or 0 
    if duty == 0 then 
        if not isElement(arrowTable[player]) then 
            arrowTable[player] = createMarker(0, 0, 0, "arrow", 0.75, 255, 0, 0, 175) 
        end 
        attachElements(arrowTable[player], player, 0, 0, 2) 
    else 
        if isElement(arrowTable[player]) then 
            destroyElement(arrowTable[player]) 
            arrowTable[player] = nil 
        end 
    end 
end) 
  
addEventHandler("onPlayerQuit", root, 
function() 
    if isElement(arrowTable[player]) then 
        destroyElement(arrowTable[player]) 
        arrowTable[player] = nil 
    end 
end) 

Yea i have another code for duty

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