DLmass Posted April 22, 2016 Share Posted April 22, 2016 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
Walid Posted April 22, 2016 Share Posted April 22, 2016 old it's not defined in your code. replace it with oldTeam. Link to comment
DLmass Posted April 22, 2016 Author Share Posted April 22, 2016 old it's not defined in your code. replace it with oldTeam. Sorry typo. It's already oldTeam Link to comment
Walid Posted April 22, 2016 Share Posted April 22, 2016 (edited) Nvm i thought that you are using a custom function. Sorry i'm using the phone. Edited April 22, 2016 by Guest Link to comment
DLmass Posted April 22, 2016 Author Share Posted April 22, 2016 Bad argument @ 'countPlayersInTeam' [Expected team at argument 1, got string 'TEST_TEAM'] Link to comment
nxFairlywell Posted April 22, 2016 Share Posted April 22, 2016 Bad argument @ 'countPlayersInTeam' [Expected team at argument 1, got string 'TEST_TEAM'] countPlayersInTeam(getTeamFromName ( old )) Link to comment
DLmass Posted April 22, 2016 Author Share Posted April 22, 2016 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
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