Jump to content

SOLVED!


Sex*

Recommended Posts

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

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

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

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

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

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

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