Jump to content

Encountered weird problem


DLmass

Recommended Posts

Okay so basically I am using the built-in team functions for my gang-system. I've encountered some weird issues with it. The thing is that it works when I execute it with runcode but not at the actual script. I'm trying to check if there is players left in the team and if there is no one, it's supposed to get deleted. Well the script is self-explanatory. Help me please!

I literally have no idea what I am suppose to add, maybe you can point my mistake out?

Thanks in advance :)

Runcode

  
createTeam("MTA_TEST_TEAM", 255, 0, 0) 
  
if (countPlayersInTeam(getTeamFromName("MTA_TEST_TEAM")) == 0) then 
    destroyElement(getTeamFromName("MTA_TEST_TEAM")) 
end 
  

Script

  
addEvent( "onPlayerChangeTeam", true ) 
function onPlayerChangeTeam(newTeam, oldTeam)    
    if (countPlayersInTeam(old) == 0) then 
        destroyElement(old) 
    end 
end 
addEventHandler("onPlayerChangeTeam", root, onPlayerChangeTeam) 
  
_setPlayerTeam = setPlayerTeam 
function setPlayerTeam ( player, newTeam ) 
    if not player or not newTeam then return false end 
    
    local oldTeam = getPlayerTeam(player) 
    
    if (oldTeam) then 
        triggerEvent("onPlayerChangeTeam", player, newTeam, oldTeam) 
    end 
    
    return _setPlayerTeam(player, newTeam) 
end 
  

Link to comment

Got some help from Emile on #mta.scripting and he solved my issue. He is what he did and I am also posting this just incase others want to use it. Please lock this topic!

  
addEvent( "onPlayerChangeTeam", true ) 
function onPlayerChangeTeam(newTeam, oldTeam) 
    outputDebugString("Changed from "..getTeamName(oldTeam).." to "..getTeamName(newTeam).." successfully") 
    
    if (countPlayersInTeam(oldTeam) == 0) then 
        destroyElement(oldTeam) 
    end 
end 
addEventHandler("onPlayerChangeTeam", root, onPlayerChangeTeam) 
  
_setPlayerTeam = setPlayerTeam 
function setPlayerTeam ( player, newTeam ) 
    if not player or not newTeam then return false end 
    
    local oldTeam = getPlayerTeam(player) 
    _setPlayerTeam(player, newTeam) 
    if (oldTeam) then 
        triggerEvent("onPlayerChangeTeam", player, newTeam, oldTeam) 
    end 
    
    return true 
end 
  

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