Jump to content

Arrow in Head


Recommended Posts

Posted

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 ) 
  
  
  

Posted

you added the getElementPosition, it is not necessary to use it if you gonna attach the marker to player. putting or not , it work perfectly but defining the position of an element is necessary do; x, y, z = getElementPosition(...)

EDIT: you put an 'end' of more.

Posted

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) 

Posted
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) 

Posted

Actually you do need table instead of variable, if you wish to have more than one marker at more than one player head.

Posted
Actually you do need table instead of variable, if you wish to have more than one marker at more than one player head.

Didn't understand but yea i want the arrow for who use the command

Posted

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) 

Posted
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

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