Jump to content
  • 0

team system


beamer

Question

good afternoon! help me please!

when a player leaves the server, the team in which he was a member remains in the tab
how to make it so that when ALL team members exit, its name is removed from the tab? below is a snippet of code that might help you

 

local inPlayerTeam = {}

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
	function()
 executeSQLQuery("CREATE TABLE IF NOT EXISTS tab_team(name TEXT, login TEXT, level NUMERIC, r NUMERIC, g NUMERIC, b NUMERIC)")
		local res = executeSQLQuery("SELECT * FROM tab_team WHERE level = ?", 1)
		if #res > 0 then
			for _, t in ipairs(res) do
 createTeam(t.name, t.r, t.g, t.b)
			end
		end
 outputDebugString("Create "..(#res).." teams")
	end
)

addEventHandler('onClientRender', root, function()
	for i, team in ipairs(getElementsByType('team')) do 
		local players = getPlayersInTeam(team)
		if (#players == 0) then
 destroyElement(team)
		
	
endendend)

addEventHandler("onResourceStop", getResourceRootElement(getThisResource()),
	function()
		for _, t in ipairs(getElementsByType("team")) 
 destroyElement(t)
		
 outputDebugString("All teams are removed")
	end
)

addEventHandler("onPlayerLogin", getRootElement(),
	function(_, account)
		local login = getAccountName(account)
 setElementData(source, "tab_team:login", login)
		local res = executeSQLQuery("SELECT name FROM tab_team WHERE login = ?", login)
		if #res > 0 then
 setPlayerTeam(source, getTeamFromName(res[1].name))
		end
	end
)

addEventHandler("onPlayerQuit", getRootElement(),
	function()
		if inPlayerTeam[source] then
 inPlayerTeam[source] = destroyElement(team)
		
	
endend)

 

Link to comment

1 answer to this question

Recommended Posts

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...