Jump to content

[HELP]Autoteams


Dany Alex

Recommended Posts

[2015-11-20 19:46:34] WARNING: [gameplay]/autoteams/server.lua:54: Bad argument @ 'setPlayerTeam' [Expected player at argument 1] 
[2015-11-20 19:46:34] WARNING: [gameplay]/autoteams/server.lua:56: Bad argument @ 'getPlayerName' [Expected element at argument 1] 
[2015-11-20 19:46:34] ERROR: [gameplay]/autoteams/server.lua:56: bad argument #1 to 'find' (string expected, got boolean) 

---------------do not change or touch this---------- 
Names={} 
Tags={} 
Colors={} 
ACL={} 
-------------------------------------------------------------- 
  
---------------------------Clanurile--------------------------------------- 
  
local names ={"Staff"} 
local tags  ={"RPP|"} 
local colors ={"#FF9900"} 
local acls ={"none"} 
-------- load------------ 
  
function loadTeams() 
 for i,name in pairs(names) do 
Names[i]=name 
end 
  
for i,tag in pairs(tags) do 
Tags[i]=tag 
end 
  
for i,color in pairs(colors) do 
Colors[i] = color 
end 
  
  
for i,acl in pairs(acls) do 
ACL[i] = acl 
end 
 end 
  
  
addEventHandler("onResourceStart",getRootElement(),loadTeams) 
  
--------------------------------------------------- 
  
----- move on start------------------ 
  
function moveOnStart() 
for i,player in pairs(getElementsByType("player")) do 
check(player) 
end 
end 
  
addEventHandler("onResourceStart",getRootElement(),moveOnStart) 
------------------------------------------------------------------------- 
  
-----------check---------------------------- 
  
function check (player) 
setPlayerTeam(player,nil) 
 for i,tag in pairs(tags) do 
    if string.find(getPlayerName(player),tag) then 
local account=getPlayerAccount(player) 
   if ACL[i]~="none" and not  isObjectInACLGroup ( "user." ..getAccountName(account) , aclGetGroup ( ACL[i] ) ) then 
return end 
local name = Names[i] 
local color = Colors[i] 
  if  not getTeamFromName(name) then 
createTeam(name,getColorFromString(color)) 
end 
local team = getTeamFromName(name) 
setPlayerTeam(player,team) 
  
end 
   end 
      end 
  
  
-------------------------------- 
  
  
----------remove Empty Team ---------- 
  
function remove() 
 for t,teams in pairs(names) do 
 local team = getTeamFromName(teams) 
  if team then 
     if  countPlayersInTeam ( team )==0 then 
         destroyElement(team) 
end 
   end 
       end 
          end 
  
----------------------------------------------------- 
  
-------NickChange------------- 
  
function nick(old,new) 
setTimer(check,1000,1,source) 
setTimer(remove,1500,1) 
end 
  
addEventHandler("onPlayerChangeNick",getRootElement(),nick) 
--------------------------------------------- 
  
-------Join-------------------------------- 
  
function join() 
setTimer(check,4000,1,source) 
end 
  
addEventHandler("onPlayerJoin",getRootElement(),join) 
------------------------------- 
  
---------Quit--------------------- 
  
function quit(player) 
setTimer(remove,1000,1) 
end 
  
addEventHandler("onPlayerQuit",getRootElement(),quit) 
------------------------------------ 
  
---------Login--------------------- 
  
function login() 
setTimer(check,1000,1,source) 
setTimer(remove,1500,1) 
end 
  
addEventHandler("onPlayerLogin",getRootElement(),login) 
------------------------------------ 
  
---------Logout--------------------- 
  
function logout() 
setTimer(check,1000,1,source) 
setTimer(remove,1500,1) 
end 
  
addEventHandler("onPlayerLogout",getRootElement(),logout) 
------------------------------------ 

Link to comment

Well, you can remove the function moveOnStart since it won't really be doing anything. It will always give you that error when the server is started, it may work whenever a resource is started though - so long as there are players.

If you want to prevent the error from showing up, simply add an if statement.

if(player) then 
   check(player) 
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...