Jump to content

[QUESTION] isElementAttached


Chrimam

Recommended Posts

addCommandHandler ( "blip", 
  
for i , elements in pairs(getAttachedElements(player)) do 
  
 if getElementType(elements) == "blip" then 
            if ( isElement ( blip ) ) then 
  
                destroyElement ( blip ) 
  
            else 
  
                local x, y, z = getElementPosition ( player ) 
  
                blip = createblip ( TheBlipID) 
  
                attachElements ( blip, player, 0, 0, 2 ) 
  
            end 
  
  
        end 
  
    end 
  
) 

Link to comment

This is what I'm trying to do actually. Hope you understand and help :)

-- partial name function start by TAPL 
function getPlayerFromNamePart(name) 
    if name then  
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player  
            end 
        end 
    end 
    return false 
end 
-- partial name function end by TAPL 
  
g_Local = getLocalPlayer() 
  
function followTarget(g_Local, cmd, target) 
    tPlayer = getPlayerFromNamePart(target) 
        if not target then 
         outputChatBox("You have to type a player name.") 
        end 
            if target == g_Local then 
                outputChatBox("You can't follow yourself.") 
            else tMark = createBlipAttachedTo( tPlayer, 0, 2, 255, 255, 255, 255, 0, 99999.0, g_Local) -- if it's not attached already. otherwise, don't attach. 
            end 
end 
  
  
function unfollowTarget(g_Local, cmd, target) 
-- unfollowing thing here by checking if the target is followed already. 
end 
  
addCommandHandler("follow", followTarget) 
addCommandHandler("unfollow", unfollowTarget) 

Link to comment

Fixed also some little bugs

-- partial name function start by TAPL 
function getPlayerFromNamePart(name) 
    if name then 
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player 
            end 
        end 
    end 
    return false 
end 
  
  
g_Local = getLocalPlayer() 
  
function followTarget(g_Local, cmd, target) 
if not target then 
outputChatBox("You have to type a player name.") 
elseif target then 
tPlayer = getPlayerFromNamePart(target) 
if tPlayer == g_Local then 
outputChatBox("You can't follow yourself.") 
else  
if not isElement ( tMark ) then 
tMark = createBlipAttachedTo( tPlayer, 0, 2, 255, 255, 255, 255, 0, 99999.0, g_Local) 
elseif isElement ( tMark ) then 
destroyElement ( tMark ) 
tMark = createBlipAttachedTo( tPlayer, 0, 2, 255, 255, 255, 255, 0, 99999.0, g_Local) 
end 
end 
end 
end 
  
function unfollowTarget(g_Local, cmd, target) 
if isElement ( tMark ) then 
destroyElement ( tMark ) 
end 
end 
  
addCommandHandler("follow", followTarget) 
addCommandHandler("unfollow", unfollowTarget) 

Link to comment

If you want to target more players then you must use tables, much faster than cheking if something is attached on the player :P

-- partial name function start by TAPL 
function getPlayerFromNamePart(name) 
    if name then 
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player 
            end 
        end 
    end 
    return false 
end 
  
  
g_Local = getLocalPlayer() 
  
local followTable = {} 
  
  
function followTarget(g_Local, cmd, target) 
if not target then 
outputChatBox("You have to type a player name.") 
elseif target then 
local tPlayer = getPlayerFromNamePart(target) 
if tPlayer == g_Local then 
outputChatBox("You can't follow yourself.") 
elseif not ( isElement ( followTable[tPlayer] ) ) then  
followTable[tPlayer] = createBlipAttachedTo( tPlayer, 0, 2, 255, 255, 255, 255, 0, 99999.0, g_Local) 
elseif ( isElement ( followTable[tPlayer] ) ) then  
outputChatBox("You are already following this player.") 
end 
end 
end 
  
  
function unfollowTarget(g_Local, cmd, target) 
if not target then 
outputChatBox("You have to type a player name.") 
elseif target then 
local tPlayer = getPlayerFromNamePart(target) 
if isElement (followTable[tPlayer]) then 
destroyElement ( followTable[tPlayer] ) 
end 
end 
end 
  
addCommandHandler("follow", followTarget) 
addCommandHandler("unfollow", unfollowTarget) 

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