Bean666 Posted June 9, 2016 Share Posted June 9, 2016 it only works when there is 1 player in the team ,when i add 1 more player in the team ,the text above the players in the team disappears. addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Army") then if v == localPlayer then return end dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) Link to comment
Anubhav Posted June 9, 2016 Share Posted June 9, 2016 dxDrawTextOnElement is defined? It should be this: addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Army") then if not v == localPlayer then dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end end) The problem is when you're looping through a table, localPlayer (the client running the script), when that player element comes, it will stop the loop completely by using return. If there were 10 players and his number was first on table, it would not show it. Use "not". Link to comment
Bean666 Posted June 9, 2016 Author Share Posted June 9, 2016 doesnt work doesnt show the Text EDIT: I tried this and it works , he can see mine too, we are both in same team but , it's showing the text for me too. i want players to see other's people's text only , not theirs too. addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Military") then if not v == localPlayer then return end dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) Link to comment
..:D&G:.. Posted June 9, 2016 Share Posted June 9, 2016 doesnt work doesnt show the TextEDIT: I tried this and it works , he can see mine too, we are both in same team but , it's showing the text for me too. i want players to see other's people's text only , not theirs too. addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Military") then if not v == localPlayer then return end dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Military") then if v == localPlayer then return end dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) Link to comment
Bean666 Posted June 9, 2016 Author Share Posted June 9, 2016 [quote name=..&G:..] doesnt work doesnt show the TextEDIT: I tried this and it works , he can see mine too, we are both in same team but , it's showing the text for me too. i want players to see other's people's text only , not theirs too. addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Military") then if not v == localPlayer then return end dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Military") then if v == localPlayer then return end dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) it's the same as my code given at the very top, if i use this code, it works! i won't be able to see my own text and see other people's text, but when there are 2 or more players in the "Team", the text is not showing up anymore. Link to comment
..:D&G:.. Posted June 9, 2016 Share Posted June 9, 2016 It's not the same, you used this: if not v == localPlayer then return end and I used: if v == localPlayer then return end Also, use this: addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Military") then if not v == localPlayer then dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) Because when the script gets to you when it loops through the table, it will stop, and will not carry on to the other players, and you don't really need a "return" for this function. Link to comment
Bean666 Posted June 9, 2016 Author Share Posted June 9, 2016 [quote name=..&G:..]It's not the same, you used this: if not v == localPlayer then return end and I used: if v == localPlayer then return end Also, use this: addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Military") then if not v == localPlayer then dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) Because when the script gets to you when it loops through the table, it will stop, and will not carry on to the other players, and you don't really need a "return" for this function.*sigh* anyways it's almost the same as anubhav's code just with 1 less end what's the difference? Link to comment
..:D&G:.. Posted June 9, 2016 Share Posted June 9, 2016 This if not v == localPlayer then is not the same as this if not v == localPlayer then return end This will loop though all the players in a random order (I think): for k,v in ipairs(getElementsByType("player")) do So this: if not v == localPlayer then will be called every time the function gets to a player from the table, so if you have "return" in there and the function gets to you (the localPlayer) will stop the function therefore stopping the loop. Also: [quote name=..&G:..]When the script gets to you when it loops through the table, it will stop, and will not carry on to the other players, and you don't really need a "return" for this function. Link to comment
Bean666 Posted June 9, 2016 Author Share Posted June 9, 2016 THIS IS Anubhav's CODE it didn't seem to work but ill try again! ill tell u the result tomorrow or later! EDIT : Not working , not showing text above player head addEventHandler("onClientRender", getRootElement(), function () for k,v in ipairs(getElementsByType("player")) do if getPlayerTeam(v) == getTeamFromName("Army") then if not v == localPlayer then dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end end) Link to comment
Bean666 Posted June 9, 2016 Author Share Posted June 9, 2016 not working , text dont appear Link to comment
Enargy, Posted June 9, 2016 Share Posted June 9, 2016 addEventHandler("onClientRender", getRootElement(), function () local theTeam = getTeamFromName("Army") if not theTeam then return end for k,v in ipairs(getPlayersInTeam(theTeam)) do if v ~= localPlayer then dxDrawTextOnElement(v,"Army",1,20,0,255,0,255,1,"bankgothic") end end end) 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