Chrimam Posted August 13, 2013 Share Posted August 13, 2013 Can i use isElementAttached with createBlipAttachedTo? Let's say I want to make make a blip on a player by typing /blip player. if it already has a blip, it will destroy it. will isElementAttached work here? if not, how can i detect if a blip attached to someone? Link to comment
bandi94 Posted August 13, 2013 Share Posted August 13, 2013 for i , elements in pairs(getAttachedElements(player)) do if getElementType(elements) == "blip" then -- there is a blip attached to the player end end Link to comment
isa_Khamdan Posted August 13, 2013 Share Posted August 13, 2013 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
Chrimam Posted August 13, 2013 Author Share Posted August 13, 2013 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
denny199 Posted August 13, 2013 Share Posted August 13, 2013 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
Chrimam Posted August 13, 2013 Author Share Posted August 13, 2013 if not isElement ( tMark ) then tMark = createBlipAttachedTo( tPlayer, 0, 2, 255, 255, 255, 255, 0, 99999.0, g_Local) These lines would be useless if i want to follow more than 1 player. Thanks for the corrections tho Link to comment
denny199 Posted August 13, 2013 Share Posted August 13, 2013 If you want to target more players then you must use tables, much faster than cheking if something is attached on the player -- 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
Chrimam Posted August 13, 2013 Author Share Posted August 13, 2013 Thanks I will test it asap. If some errors occur and i can't fix, i will be here waiting for your help Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now