Sex* Posted March 26, 2013 Share Posted March 26, 2013 (edited) Solved. Edited April 6, 2013 by Guest Link to comment
PaiN^ Posted March 26, 2013 Share Posted March 26, 2013 function removeTeams ( ) for t,teams in pairs( getElementsByType ( 'team' ) ) do if countPlayersInTeam ( teams ) ==0 then destroyElement(teams) end end end setTimer ( removeTeams, 1000, 0 ) Link to comment
ZL|LuCaS Posted March 26, 2013 Share Posted March 26, 2013 So i want to make that if team is empty then it gets destroyed. No errors.This is my team creating thing: function createTeamsOnStart () local MainTeam = createTeam ( "The Professionals", 250, 50,0) end addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) And i tried something with removing team: function remove() for t,teams in pairs(MainTeam) do local MainTeam = getTeamFromName(teams) if team then if countPlayersInTeam ( team )==0 then destroyElement(team) end end end end the function remove () is not called? Link to comment
Sex* Posted March 26, 2013 Author Share Posted March 26, 2013 LuCas what do you mean? Pain, now it destroys the team but it doesnt create the team then player from team joins(team gets players). And it also doesnt let me create from admin panel because the clan is deleted before(because no players in new clan). Link to comment
PaiN^ Posted March 26, 2013 Share Posted March 26, 2013 now it destroys the team but it doesnt create the team then player from team joins(team gets players) I don't understand ! And it also doesnt let me create from admin panel because the clan is deleted before(because no players in new clan). Well that because it checks the teams every second, You can do it as a command by : addCommandHandler Or you can make the timer longer ! Link to comment
ZL|LuCaS Posted March 26, 2013 Share Posted March 26, 2013 function remove() for t,teams in pairs(MainTeam) do local team = getTeamFromName(teams) if team then if countPlayersInTeam ( team )==0 then destroyElement(team) end end end end function createTeamsOnStart () local MainTeam = createTeam ( "The Professionals", 250, 50,0) end addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) function login() setTimer(remove,1500,1) end addEventHandler("onPlayerLogin",getRootElement(),login) function logout() setTimer(remove,1500,1) end addEventHandler("onPlayerLogout",getRootElement(),logout) you have to trigger function remove () Link to comment
Sex* Posted March 27, 2013 Author Share Posted March 27, 2013 pain, thats not a very good solution. LuCas, that didnt work. Link to comment
Castillo Posted March 27, 2013 Share Posted March 27, 2013 function createTeamsOnStart ( ) MainTeam = createTeam ( "The Professionals", 250, 50, 0 ) end addEventHandler ( "onResourceStart", resourceRoot, createTeamsOnStart ) addEventHandler ( "onPlayerQuit", root, function ( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end ) Link to comment
Sex* Posted March 28, 2013 Author Share Posted March 28, 2013 function createTeamsOnStart ( ) MainTeam = createTeam ( "The Professionals", 250, 50, 0 ) end addEventHandler ( "onResourceStart", resourceRoot, createTeamsOnStart ) addEventHandler ( "onPlayerQuit", root, function ( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 0 ) then destroyElement ( MainTeam ) end end end ) Doesnt work. Link to comment
Castillo Posted March 28, 2013 Share Posted March 28, 2013 Oh yeah, my bad, I put "== 0" and it should have been: "== 1", copy it again. Link to comment
Sex* Posted March 29, 2013 Author Share Posted March 29, 2013 Oh yeah, my bad, I put "== 0" and it should have been: "== 1", copy it again. But then it destroys the team if one player is in team i think? Link to comment
Castillo Posted March 29, 2013 Share Posted March 29, 2013 No, look, when that player is about to leave, the only player that is there is him, so it destroys it. Link to comment
Sex* Posted March 29, 2013 Author Share Posted March 29, 2013 It still doesnt work, i replaced that onPlayerQuit with onPlayerLogout because then i can test it at local server and then i can see if team gets really destroyed. addEventHandler ( "onPlayerLogout", getRootElement(), function ( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end ) Link to comment
Castillo Posted March 29, 2013 Share Posted March 29, 2013 The code I posted above worked for me, when I left the server, it destroyed the team. Link to comment
PaiN^ Posted March 30, 2013 Share Posted March 30, 2013 It still doesnt work, i replaced that onPlayerQuit with onPlayerLogout because then i can test it at local server and then i can see if team gets really destroyed. addEventHandler ( "onPlayerLogout", getRootElement(), function ( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end ) I don't think logging out kick you of the team ( Unless you have a script to do that ! ) .. + Solidsnake's code works perfectly ! Link to comment
Sex* Posted March 30, 2013 Author Share Posted March 30, 2013 The code I posted above worked for me, when I left the server, it destroyed the team. And how did you test it? It recreated the team if player from the team joined? EDIT: Tested solidsnake one and disconnected and connected again(didnt log in) but the team was still there. Link to comment
Castillo Posted March 30, 2013 Share Posted March 30, 2013 I tested that single script, maybe you got something else messing around. Link to comment
Sex* Posted March 31, 2013 Author Share Posted March 31, 2013 I got it like this... function createTeamsOnStart () local MainTeam = createTeam ( "The Professionals", 250, 50,0) end addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) function setTeam() local account = getPlayerAccount(source) local team = getAccountData (account, "team") if (team) and getTeamFromName(team) then setPlayerTeam(source, getTeamFromName(team)) end end addEventHandler("onPlayerLogin",root,setTeam) function save() local team = getPlayerTeam(source) local account = getPlayerAccount(source) if (team) and not isGuestAccount(account) then setAccountData(account, "team", getTeamName(team)) end end addEventHandler("onPlayerQuit", getRootElement(), save) function unassignTeam() local theTeam = getPlayerTeam ( source ) if theTeam then setPlayerTeam ( source, nil ) end end addEventHandler("onPlayerLogout",getRootElement(), unassignTeam ) addEventHandler ( "onPlayerQuit", root, function ( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end ) function remove( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end function login() setTimer(remove,1500,1) end addEventHandler("onPlayerLogin",getRootElement(),login) function logout() setTimer(remove,1500,1) end addEventHandler("onPlayerLogout",getRootElement(),logout) addEventHandler("onPlayerQuit", getRootElement(), logout) Link to comment
Sex* Posted March 31, 2013 Author Share Posted March 31, 2013 So whats messing up my script? Link to comment
Sex* Posted April 1, 2013 Author Share Posted April 1, 2013 Remove local in line 2. Well now one time it really destroyed my team but sometimes not. But it doesnt create it again... Link to comment
iPrestege Posted April 1, 2013 Share Posted April 1, 2013 Try : function createTeamsOnStart () MainTeam = createTeam ( "The Professionals", 250, 50,0) end addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) function setTeam() local account = getPlayerAccount(source) local team = getAccountData (account, "team") if (team) and getTeamFromName(team) then setPlayerTeam(source, getTeamFromName(team)) end end addEventHandler("onPlayerLogin",root,setTeam) function save() local team = getPlayerTeam(source) local account = getPlayerAccount(source) if (team) and not isGuestAccount(account) then setAccountData(account, "team", getTeamName(team)) end end addEventHandler("onPlayerQuit", getRootElement(), save) function unassignTeam() local theTeam = getPlayerTeam ( source ) if theTeam then setPlayerTeam ( source, nil ) end end addEventHandler("onPlayerLogout",getRootElement(), unassignTeam ) addEventHandler ( "onPlayerQuit", root, function ( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end ) function remove( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end function login() setTimer(remove,500,0) end addEventHandler("onPlayerLogin",getRootElement(),login) function logout() setTimer(remove,500,0) end addEventHandler("onPlayerLogout",getRootElement(),logout) addEventHandler("onPlayerQuit", getRootElement(), logout) Link to comment
Sex* Posted April 2, 2013 Author Share Posted April 2, 2013 Try : function createTeamsOnStart () MainTeam = createTeam ( "The Professionals", 250, 50,0) end addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) function setTeam() local account = getPlayerAccount(source) local team = getAccountData (account, "team") if (team) and getTeamFromName(team) then setPlayerTeam(source, getTeamFromName(team)) end end addEventHandler("onPlayerLogin",root,setTeam) function save() local team = getPlayerTeam(source) local account = getPlayerAccount(source) if (team) and not isGuestAccount(account) then setAccountData(account, "team", getTeamName(team)) end end addEventHandler("onPlayerQuit", getRootElement(), save) function unassignTeam() local theTeam = getPlayerTeam ( source ) if theTeam then setPlayerTeam ( source, nil ) end end addEventHandler("onPlayerLogout",getRootElement(), unassignTeam ) addEventHandler ( "onPlayerQuit", root, function ( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end ) function remove( ) if ( getPlayerTeam ( source ) == MainTeam ) then if ( countPlayersInTeam ( MainTeam ) == 1 ) then destroyElement ( MainTeam ) end end end function login() setTimer(remove,500,0) end addEventHandler("onPlayerLogin",getRootElement(),login) function logout() setTimer(remove,500,0) end addEventHandler("onPlayerLogout",getRootElement(),logout) addEventHandler("onPlayerQuit", getRootElement(), logout) Doesnt delete the team... Link to comment
TAPL Posted April 2, 2013 Share Posted April 2, 2013 @Mr.Pres[T]ege, creating infinite timer each time a player login? That's probably will crash/lag the server after lots of logins. Remove local in line 2. Well now one time it really destroyed my team but sometimes not. But it doesnt create it again... The script won't do a thing by itself. EDIT: function createTeamsOnStart() MainTeam = createTeam("The Professionals", 250, 50, 0) end addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) function setTeam(_, account) local team = getAccountData(account, "team") if (team) then if not getTeamFromName(team) then MainTeam = createTeam(team, 250, 50, 0) end setPlayerTeam(source, MainTeam) end end addEventHandler("onPlayerLogin", root, setTeam) function save() local team = getPlayerTeam(source) local account = getPlayerAccount(source) if (team) and not isGuestAccount(account) then setAccountData(account, "team", getTeamName(team)) remove() end end addEventHandler("onPlayerQuit", root, save) function unassignTeam() if getPlayerTeam(source) then setPlayerTeam(source, nil) remove() end end addEventHandler("onPlayerLogout", root, unassignTeam) function remove() if (getPlayerTeam(source) == MainTeam) then if (countPlayersInTeam(MainTeam) == 0) then destroyElement(MainTeam) end end end Link to comment
Sex* Posted April 3, 2013 Author Share Posted April 3, 2013 @Mr.Pres[T]ege, creating infinite timer each time a player login? That's probably will crash/lag the server after lots of logins. Remove local in line 2. Well now one time it really destroyed my team but sometimes not. But it doesnt create it again... The script won't do a thing by itself. EDIT: function createTeamsOnStart() MainTeam = createTeam("The Professionals", 250, 50, 0) end addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) function setTeam(_, account) local team = getAccountData(account, "team") if (team) then if not getTeamFromName(team) then MainTeam = createTeam(team, 250, 50, 0) end setPlayerTeam(source, MainTeam) end end addEventHandler("onPlayerLogin", root, setTeam) function save() local team = getPlayerTeam(source) local account = getPlayerAccount(source) if (team) and not isGuestAccount(account) then setAccountData(account, "team", getTeamName(team)) remove() end end addEventHandler("onPlayerQuit", root, save) function unassignTeam() if getPlayerTeam(source) then setPlayerTeam(source, nil) remove() end end addEventHandler("onPlayerLogout", root, unassignTeam) function remove() if (getPlayerTeam(source) == MainTeam) then if (countPlayersInTeam(MainTeam) == 0) then destroyElement(MainTeam) end end end Bad argument at line 36 "getPlayerTeam" 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