Jump to content

Players and teams show on parent


freudo

Recommended Posts

for i,team in pairs(getElementsByType("team")) do
		if (tonumber(countPlayersInTeam(team))>=1) then
			for v,playerTeam in ipairs (getPlayersInTeam(team)) do
				
				if getElementParent(playerTeam) == arenaElement then
					local teams = getTeamFromName ( tostring(team) )
					if not teams then
						if not team == scoreboard["teamName"][team] then
							table.insert(scoreboard,{"teamName",team})
						end
					end
				end
				if getElementParent(playerTeam) == arenaElement then
					
					table.insert(scoreboard,{"player",playerTeam})
				end
			end
		end
	end

I'm using this. but if team player have 2 and more creating new team names in scoreboard. How to solve this problem please help me.

Link to comment
8 hours ago, freudo said:

I'm using this. but if team player have 2 and more creating new team names in scoreboard. 

That is because you are placing a loop inside a loop. What exactly are you trying to achieve? You need to simplify / optimize your code, try not to put a loop inside another loop. 

Instead of this:

for i,team in pairs(getElementsByType("team")) do
		if (tonumber(countPlayersInTeam(team))>=1) then
			for v,playerTeam in ipairs (getPlayersInTeam(team)) do
				
				if getElementParent(playerTeam) == arenaElement then
					local teams = getTeamFromName ( tostring(team) )
					if not teams then
						if not team == scoreboard["teamName"][team] then
							table.insert(scoreboard,{"teamName",team})
						end
					end
				end
				if getElementParent(playerTeam) == arenaElement then
					
					table.insert(scoreboard,{"player",playerTeam})
				end
			end
		end
	end

Maybe try this:

local team = getElementsByType("team")
local teamCount = countPlayersInTeam ( team )
	if teamCount >= 1 then
	for v,playerTeam in ipairs (getPlayersInTeam(team)) do
		if getElementParent(playerTeam) == arenaElement then
			local teams = getTeamFromName ( tostring(team) )
			if not teams then
				if not team == scoreboard["teamName"][team] then
					table.insert(scoreboard,{"teamName",team})
				end
			end
		end
		if getElementParent(playerTeam) == arenaElement then	
			table.insert(scoreboard,{"player",playerTeam})
		end
	end
end

I don't know what you're trying to achieve but I removed the first loop you had which might be the cause of the problem you have. 

also tonumber in countPlayersInTeam is not necessary.

Edited by Bean666
Link to comment

it doesn't work.

function Scoreboard.playersShow()
    scoreboard = {}
	local arenaElement = getElementParent(localPlayer)
	if getElementData(localPlayer,"mode") == "Competitive" then
		for i,player in pairs(exports["CCS"]:export_getPlayersAndSpectatorsInArena(arenaElement)) do
			table.insert(scoreboard,{"player",player})
		end
		return
	end
	for i,player in pairs(exports["CCS"]:export_getPlayersAndSpectatorsInArena(arenaElement)) do
		if not getPlayerTeam(player) then
			table.insert(scoreboard,{"player",player})
		end
	end
	for i,team in pairs(getElementsByType("team")) do
		if (tonumber(countPlayersInTeam(team))>=1) then

			local teams = getTeamFromName ( tostring(team) )
			if not teams then
				table.insert(scoreboard,{"teamName",team})
			end
			for v,playerTeam in ipairs (getPlayersInTeam(team)) do
				if getElementParent(playerTeam) == arenaElement then
					
					table.insert(scoreboard,{"player",playerTeam})
				end
			end
		end
	end

end

full code this.

Link to comment
8 hours ago, freudo said:

it doesn't work.



function Scoreboard.playersShow()
    scoreboard = {}
	local arenaElement = getElementParent(localPlayer)
	if getElementData(localPlayer,"mode") == "Competitive" then
		for i,player in pairs(exports["CCS"]:export_getPlayersAndSpectatorsInArena(arenaElement)) do
			table.insert(scoreboard,{"player",player})
		end
		return
	end
	for i,player in pairs(exports["CCS"]:export_getPlayersAndSpectatorsInArena(arenaElement)) do
		if not getPlayerTeam(player) then
			table.insert(scoreboard,{"player",player})
		end
	end
	for i,team in pairs(getElementsByType("team")) do
		if (tonumber(countPlayersInTeam(team))>=1) then

			local teams = getTeamFromName ( tostring(team) )
			if not teams then
				table.insert(scoreboard,{"teamName",team})
			end
			for v,playerTeam in ipairs (getPlayersInTeam(team)) do
				if getElementParent(playerTeam) == arenaElement then
					
					table.insert(scoreboard,{"player",playerTeam})
				end
			end
		end
	end

end

full code this.

I have no idea what you're trying to do but i can see that your problem is "creating new team names in scoreboard right?" i'm assuming that's because of the amount of loops you have anyway try this:

function Scoreboard.playersShow()
    scoreboard = {}
	local arenaElement = getElementParent(localPlayer)
	if getElementData(localPlayer,"mode") == "Competitive" then
		for i,player in pairs(exports["CCS"]:export_getPlayersAndSpectatorsInArena(arenaElement)) do
			table.insert(scoreboard,{"player",player})
		end
		return
	end
	for i,player in pairs(exports["CCS"]:export_getPlayersAndSpectatorsInArena(arenaElement)) do
		if not getPlayerTeam(player) then
			table.insert(scoreboard,{"player",player})
		end
	end
	local team = getElementsByType("team")
	local teamCount = countPlayersInTeam ( team )
	if teamCount >= 1 then
		local teams = getTeamFromName ( tostring(team) )
		if not teams then
			table.insert(scoreboard,{"teamName",team})
		end
		for v,playerTeam in ipairs (getPlayersInTeam(team)) do
			if getElementParent(playerTeam) == arenaElement then
				table.insert(scoreboard,{"player",playerTeam})
			end
		end
	end
end

and tell me what doesn't work, if this doesn't work, explain your problem properly, and make sure to check /debugscript 3 if there are any errors.

also i'm confused on what you're trying to do with this:

for v,playerTeam in ipairs (getPlayersInTeam(team)) do
	if getElementParent(playerTeam) == arenaElement then
		table.insert(scoreboard,{"player",playerTeam})
	end
end

 

Edited by Bean666
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...