Jump to content

Remaning players team


freudo

Recommended Posts

 

If the remaining players have the same team, I want to end the game. Can you help me?

This code only one player send to winner element.

if #game[gameID].players <= 1 then 
     endGame(gameID, game[gameID].players[1])
end

 

I wrote this code, but I'm not sure.

if game[gameID].players and getElementData(game[gameID].players, "gang") then 
	endGame(gameID, game[gameID].players)
end

Thanks.

Link to comment
local playerGame = getElementData(source, "player:game") or false 
if playerGame and playerGame[1] then 
	local gameID = playerGame[1]
	for k,v in ipairs(game[gameID].players) do 
		if v == source then 
			table.remove(game[gameID].players, k)
		end
	end
	if #game[gameID].players <= 1 then 
		endGame(gameID, game[gameID].players[1])
	end
end

full code, anyone help me?

Link to comment
34 minutes ago, barikat said:

local playerGame = getElementData(source, "player:game") or false 
if playerGame and playerGame[1] then 
	local gameID = playerGame[1]
	for k,v in ipairs(game[gameID].players) do 
		if v == source then 
			table.remove(game[gameID].players, k)
		end
	end
	if #game[gameID].players <= 1 then 
		endGame(gameID, game[gameID].players[1])
	end
end

full code, anyone help me?

who is the source?

source

 

  1. local playerGame = getElementData(source, "player:game") or false

show us your full code with your event we can't help you without it

 

Edited by Master_MTA
Link to comment
function endGame(id, winner)
	if isElement(winner) then
		outputChatBox(getPlayerName(winner).." has won the game!", root, 255,255,255,true)
	end
end

function onPlayerWasted(totalAmmo, killer, killerWeapon)
	local playerGame = getElementData(source, "player:game") or false 
	if playerGame and playerGame[1] then 
		local gameID = playerGame[1]
		for k,v in ipairs(game[gameID].players) do 
			if v == source then 
				table.remove(game[gameID].players, k)
			end
		end
		if getElementData(source,"gang") then
			for k,v in ipairs(getElementsByType ( "player" )) do
				if getElementData(v,"gang") == getElementData(source, "gang") then
					endGame(gameID, game[gameID].players[v])
				end
			end
		else
			if #game[gameID].players <= 1 then 
				endGame(gameID, game[gameID].players[1])
			end
		end
	end
end

 

I wrote this, but it does not work.

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