Jump to content

"state" problem


MohammedX

Recommended Posts

Posted (edited)

hey community i want a little help here i have problem with state i want to take all the players team state and make them on the numbers like if the number 5 and someone died after 4 like this

this is my attempt but the number still at the limit of 0 and I want it like what I said above i do not know what problem and when the count ends (3 2 1 go) the numbe zero turns into 1 :/

homeName = ""

function get_team_alive_players(enemy)

	local team_name = homeName
	if enemy then
		team_name = enemyName
	end

	local team = getTeamFromName(team_name)
	if team then

		local players = getPlayersInTeam(team)
		if type(players) == "table" and #players > 0 then

			local output = {}
			for i,player in pairs(players) do

				local alive = getElementData(player,"state")
				if alive ~= "alive" then
					alive = false
				end

				local t = {name = getPlayerName(player), alive = alive}
				do
					table.insert(output,t)
				end
			end

			return output
		end
	end

	return false
end


----------
homeName = ""
local homeTeam = getTeamFromName(homeName)
---
aliveH = getElementData(homeTeam, "alive") or "none"	
				do
					dxDrawText(aliveH,posX,posY,posX+sizeX+row_size+row_size-5,posY+row_size,tocolor(255,255,255,alpha),clanwar_data_fontSize*1.2,clanwar_data_font,"right","center",false,false,false)
				end

SERVER

team = {}

addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),
function(startedRes)
	if getResourceName(getThisResource()) == getResourceName(startedRes) then
		team[3] = createTeam ( "Spectators", 255, 255, 255 )
			if homeColor == "Blue" then
				team[1] = createTeam ( homeName, 255,255,99 )
			elseif homeColor == "Red" then
				team[1] = createTeam ( homeName, colour.r,colour.g,colour.b)
				end
			if enemyColor == "Blue" then
				team[2] = createTeam ( enemyName, 255,255,99 )
			elseif enemyColor == "Red" then
				team[2] = createTeam ( enemyName, colour.r,colour.g,colour.b)
				
			end
				
		setElementData(team[1], "points", 0)
		setElementData(team[1], "alive", 0)
		setElementData(team[2], "points", 0)
		setElementData(team[2], "alive", 0)
		local totalRounds = tonumber(get("totalRounds")) or 20
		setElementData(team[1] and team[2], "currentRound", 0)
		setElementData(team[1] and team[2], "totalRounds", totalRounds)
		setElementData(team[1] and team[2], "warState", "Waiting")
		--setElementData(team[1], "left", Maps)
		setElementData(team[1], "warState", "Waiting")
			--setGameType ( gameTypeName )
	end
end
)

addEvent("onRaceStateChanging")
addEventHandler("onRaceStateChanging",getRootElement(),
function(old, new)
	if old == "Running" and new == "GridCountdown" then
		setElementData(team[1], "alive", countPlayersInTeam(team[1]))
		setElementData(team[2], "alive", countPlayersInTeam(team[2]))
	local players = getElementsByType("player")
		for k,v in ipairs(players) do
		local thePlayer = v
		local playerTeam = getPlayerTeam (thePlayer)
			if ( playerTeam ) then
			local teamName = getTeamName(playerTeam)
					-- Kill spectators
				if teamName == "Spectators" then
					setTimer(
						function()
							setElementHealth(thePlayer,0)
						end
						,50, 1)
				end
			end
		end
	end
end
)

i hope one helpe me because i'm so confused why state not work quickly

Edited by MohammedX
fix mistake

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