Jump to content

balance.lua + sound


Meva

Recommended Posts

Hi, guys :)

I have balance.lua script and it work yes, but I wanted to add sounds "player move to axis/allies". 

 

modname = "balance"

version = "0.1"
 
function et_InitGame(levelTime,randomSeed,restart)
et.RegisterModname(modname .. " " .. version)
end
 
unevenDiff = 2
max_unevenTime = 15
max_unevenDiff = 4
 
axisPlayers = {}
alliedPlayers = {}
unevenTime = 15
 
function et_RunFrame( levelTime )
   local numAlliedPlayers = table.getn( alliedPlayers )
   local numAxisPlayers = table.getn( axisPlayers )
   if numAlliedPlayers >= numAxisPlayers + max_unevenDiff then
      local clientNum = alliedPlayers[ numAlliedPlayers ]
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " r" )
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
      et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS\"" ) 
   elseif numAxisPlayers >= numAlliedPlayers + max_unevenDiff then
      local clientNum = axisPlayers[ numAxisPlayers ]
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " b" )
et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
 et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES\"" ) 
   elseif numAlliedPlayers >= numAxisPlayers + unevenDiff then
      if unevenTime > 0 then
         if tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 then
            local clientNum = alliedPlayers[ numAlliedPlayers ]
            et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " r" )
et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS\"" ) 
         end
      else
         unevenTime = tonumber( levelTime )
      end
   elseif numAxisPlayers >= numAlliedPlayers + unevenDiff then
      if unevenTime > 0 then
         if tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 then
            local clientNum = axisPlayers[ numAxisPlayers ]
            et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " b" )
et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES\"" ) 
         end
      else
         unevenTime = tonumber( levelTime )
      end
   else
      unevenTime = -1
   end
end
 
function et_ClientSpawn( clientNum, revived, teamChange, restoreHealth )
   if teamChange ~= 0 then
      local team = tonumber( et.gentity_get( clientNum, "sess.sessionTeam" ) )
      -- these were the teamnumbers prior to the move
      local numAlliedPlayers = table.getn( alliedPlayers )
      local numAxisPlayers = table.getn( axisPlayers )
      if team == 1 then
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               table.remove( alliedPlayers, i )
               break
            end
         end
         -- this should not happen but still check for it to avoid doubles
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               return
            end
         end
         -- make sure a player who (got) moved when teams were uneven doesn't get moved right back
         if numAlliedPlayers >= numAxisPlayers + unevenDiff then
            table.insert( axisPlayers, 1, clientNum )
         else
            table.insert( axisPlayers, clientNum )
         end
      elseif team == 2 then
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               table.remove( axisPlayers, i )
               break
            end
         end
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               return
            end
         end
         if numAxisPlayers >= numAlliedPlayers + unevenDiff then
            table.insert( alliedPlayers, 1, clientNum )
         else
            table.insert( alliedPlayers, clientNum )
         end
      else
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               table.remove( alliedPlayers, i )
               return
            end
         end
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               table.remove( axisPlayers, i )
               return
            end
         end
      end
   end
end
 
function et_ClientDisconnect( clientNum )
   for i, num in ipairs( alliedPlayers ) do
      if num == clientNum then
         table.remove( alliedPlayers, i )
         return
      end
   end
   for i, num in ipairs( axisPlayers ) do
      if num == clientNum then
         table.remove( axisPlayers, i )
         return
      end
   end
end

And doesn't work :< I'm put on other team but can not hear sound... please help me :<

Edited by Meva
Link to comment
Share on other sites

  • 3 weeks later...

Hello,

I know that this is topic about sound in ballance cfg, but i have question about cfg balance so i think that this subject is correct.

 

Is it possible to balance team only to 12 lvl? I mean, i want to balance all players without admins over 12 lvl.

Yes it is, right before you move the player, check to see if their level is 12 or higher, if its 12 or higher then return to reload the script and check again.

 if et.G_shrubbot_level(_clientNum) >= 12 then return end
Edited by Purple
Link to comment
Share on other sites

Thanks it really help me out.

One more think.

 

When i need to put this cmd? Because there is few places where is putteam.

 
modname = "balance"
version = "0.1"
 
function et_InitGame(levelTime,randomSeed,restart)
	et.RegisterModname(modname .. " " .. version)
end
 
unevenDiff = 2
max_unevenTime = 15
max_unevenDiff = 4
 
axisPlayers = {}
alliedPlayers = {}
unevenTime = 15
 
function et_RunFrame( levelTime )
	local numAlliedPlayers = table.getn( alliedPlayers )
	local numAxisPlayers = table.getn( axisPlayers )
		if numAlliedPlayers >= numAxisPlayers + max_unevenDiff then
			if et.G_shrubbot_level(clientNum) >= 12 then return end
			local clientNum = alliedPlayers[ numAlliedPlayers ]
			et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " r" )
			et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
			et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS\"" ) 
		elseif numAxisPlayers >= numAlliedPlayers + max_unevenDiff then
			if et.G_shrubbot_level(clientNum) >= 12 then return end
			local clientNum = axisPlayers[ numAxisPlayers ]
			et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " b" )
			et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
			et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES\"" ) 
		elseif numAlliedPlayers >= numAxisPlayers + unevenDiff then
		if unevenTime > 0 then
			if tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 then
				if et.G_shrubbot_level(clientNum) >= 12 then return end
				local clientNum = alliedPlayers[ numAlliedPlayers ]
				et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " r" )
				et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
				et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS\"" ) 
			end
		else
			unevenTime = tonumber( levelTime )
		end
		
		elseif numAxisPlayers >= numAlliedPlayers + unevenDiff then
			if unevenTime > 0 then
				if et.G_shrubbot_level(clientNum) >= 12 then return end
				if tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 then
					local clientNum = axisPlayers[ numAxisPlayers ]
					et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " b" )
					et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
					et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES\"" ) 
			end
			else
				unevenTime = tonumber( levelTime )
			end
		else
			unevenTime = -1
   end
end
 
function et_ClientSpawn( clientNum, revived, teamChange, restoreHealth )
   if teamChange ~= 0 then
      local team = tonumber( et.gentity_get( clientNum, "sess.sessionTeam" ) )
      -- these were the teamnumbers prior to the move
      local numAlliedPlayers = table.getn( alliedPlayers )
      local numAxisPlayers = table.getn( axisPlayers )
      if team == 1 then
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               table.remove( alliedPlayers, i )
               break
            end
         end
         -- this should not happen but still check for it to avoid doubles
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               return
            end
         end
         -- make sure a player who (got) moved when teams were uneven doesn't get moved right back
         if numAlliedPlayers >= numAxisPlayers + unevenDiff then
            table.insert( axisPlayers, 1, clientNum )
         else
            table.insert( axisPlayers, clientNum )
         end
      elseif team == 2 then
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               table.remove( axisPlayers, i )
               break
            end
         end
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               return
            end
         end
         if numAxisPlayers >= numAlliedPlayers + unevenDiff then
            table.insert( alliedPlayers, 1, clientNum )
         else
            table.insert( alliedPlayers, clientNum )
         end
      else
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               table.remove( alliedPlayers, i )
               return
            end
         end
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               table.remove( axisPlayers, i )
               return
            end
         end
      end
   end
end
 
function et_ClientDisconnect( clientNum )
   for i, num in ipairs( alliedPlayers ) do
      if num == clientNum then
         table.remove( alliedPlayers, i )
         return
      end
   end
   for i, num in ipairs( axisPlayers ) do
      if num == clientNum then
         table.remove( axisPlayers, i )
         return
      end
   end
end
Link to comment
Share on other sites

maybe now it work:

 

 

 

modname = "balance"
version = "0.1"

function et_InitGame(levelTime,randomSeed,restart)
    et.RegisterModname(modname .. " " .. version)
end

unevenDiff = 2
max_unevenTime = 15
max_unevenDiff = 4

axisPlayers = {}
alliedPlayers = {}
unevenTime = 15

function et_RunFrame( levelTime )
    local numAlliedPlayers = table.getn( alliedPlayers )
    local numAxisPlayers = table.getn( axisPlayers )
        if numAlliedPlayers >= numAxisPlayers + max_unevenDiff then
            if et.G_shrubbot_level(clientNum) >= 12 then return end
            local clientNum = alliedPlayers[ numAlliedPlayers ]
            et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " r" )
            et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS\"" )
        elseif numAxisPlayers >= numAlliedPlayers + max_unevenDiff then
            if et.G_shrubbot_level(clientNum) >= 12 then return end
            local clientNum = axisPlayers[ numAxisPlayers ]
            et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " b" )
            et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES\"" )
        elseif numAlliedPlayers >= numAxisPlayers + unevenDiff then
        if unevenTime > 0 then
            if tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 then
                if et.G_shrubbot_level(clientNum) >= 12 then return end
                local clientNum = alliedPlayers[ numAlliedPlayers ]
                et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " r" )
                et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1AXIS\"" )
            end
        else
            unevenTime = tonumber( levelTime )
        end
        
        elseif numAxisPlayers
>= numAlliedPlayers + unevenDiff then
            if unevenTime > 0 then
                if et.G_shrubbot_level(clientNum) >= 12 then return end
                if tonumber( levelTime ) - unevenTime >= max_unevenTime * 1000 then
                    local clientNum = axisPlayers[ numAxisPlayers ]
                    et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. " b" )
                    et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^4ALLIES\"" )
            end
            else
                unevenTime = tonumber( levelTime )
            end
        else
            unevenTime = -1
end
end

function et_ClientSpawn( clientNum, revived, teamChange, restoreHealth )
if teamChange ~= 0 then
local team = tonumber( et.gentity_get( clientNum, "sess.sessionTeam" ) )
-- these were the teamnumbers prior to the move
local numAlliedPlayers = table.getn( alliedPlayers )
local numAxisPlayers = table.getn( axisPlayers )
if team == 1 then
for i, num in ipairs( alliedPlayers ) do
if num == clientNum then
table.remove( alliedPlayers, i )
break
end
end
-- this should not happen but still check for it to avoid doubles
for i, num in ipairs( axisPlayers ) do
if num == clientNum then
return
end
end
-- make sure a player who (got) moved when teams were uneven doesn't get moved right back
if numAlliedPlayers >= numAxisPlayers + unevenDiff then
table.insert( axisPlayers, 1, clientNum )
else
table.insert( axisPlayers, clientNum )
end
elseif team == 2 then
for i, num in ipairs( axisPlayers ) do
if num == clientNum then
table.remove( axisPlayers, i )
break
end
end
for i, num in ipairs( alliedPlayers ) do
if num == clientNum then
return
end
end
if numAxisPlayers >= numAlliedPlayers + unevenDiff then
table.insert( alliedPlayers, 1, clientNum )
else
table.insert( alliedPlayers, clientNum )
end
else
for i, num in ipairs( alliedPlayers ) do
if num == clientNum then
table.remove( alliedPlayers, i )
return
end
end
for i, num in ipairs( axisPlayers ) do
if num == clientNum then
table.remove( axisPlayers, i )
return
end
end
end
end
end

function et_ClientDisconnect( clientNum )
for i, num in ipairs( alliedPlayers ) do
if num == clientNum then
table.remove( alliedPlayers, i )
return
end
end
for i, num in ipairs( axisPlayers ) do
if num == clientNum then
table.remove( axisPlayers, i )
return
end
end
end
Link to comment
Share on other sites

  • 3 weeks later...

Eh no, it's still not working. I'll try this all and nothing.

Could you correct this somehow? Maybe you could figure it out what could be wrong in this cmd.

 

Thanks a lof for this all replays:)

Do me a favor. fill this out and let me know.

 

Mod:

version:

Did you include the file in your server config?(lua_modules "name.lua":

What is your problem?:

Link to comment
Share on other sites

  • 2 weeks later...

Our(Mine and Sentrosii) mod is silent 0.8.3 We would like to have autobalance option in our server. Our problem is in adminlevel. We would like to have a script which move all players without adminlvl >= 12. We would be very grateful if someone would help us write it. Sorry for my English :)

Edited by Pixelowy
Link to comment
Share on other sites

Our(Mine and Sentrosii) mod is silent 0.8.3 We would like to have autobalance option in our server. Our problem is in adminlevel. We would like to have a script which move all players without adminlvl >= 12. We would be very grateful if someone would help us write it. Sorry for my English :)

Interesting I did not know that 8.3 was around.

 

I am only aware of 8.2.

Link to comment
Share on other sites

  • Management

Fixed version. I've fixed it for Pixelowy on his request, but I will share it here, so that everyone can have some use of it.

modname = "balance"
version = "0.2"
 
function et_InitGame(levelTime,randomSeed,restart)
	et.RegisterModname(modname .. " " .. version)
end
 
unevenDiff = 2
max_unevenTime = 15
max_unevenDiff = 4
 
axisPlayers = {}
alliedPlayers = {}
unevenTime = 15
immuneLvl = 12

function putTeam(clientNum, team)
	if clientNum == -1 then return end

	local teamStr
	if ( team == "AXIS" ) then
		teamStr = " r"
	else
		teamStr = " b"
	end
		
	et.trap_SendConsoleCommand( et.EXEC_APPEND, "putteam " .. clientNum .. teamStr )
	et.trap_SendConsoleCommand( et.EXEC_APPEND, "playsound playermove.wav\n" )
	et.trap_SendServerCommand(-1, "chat \"balancing teams... " .. et.gentity_get( clientNum, "pers.netname" ) .. "^7 moved to ^1" .. team .. "\"" ) 
end	

function longEnough(levelTime)
	return (tonumber(levelTime) - unevenTime >= max_unevenTime * 1000)
end

-- check if the level can be moved
function goodLevel(clientNum)
	return ( et.G_shrubbot_level(clientNum) < immuneLvl)
end

-- pick player from the team specified by the parameter
-- pick only players with lower than immuneLvl level
-- return -1 if not found
function pickPlayer(team)
	if team == "AXIS" then
		for clientNum = #axisPlayers,1,-1 do
			if goodLevel(axisPlayers[clientNum]) then
				return axisPlayers[clientNum]
			end
        	end
	else
		for clientNum = #alliedPlayers,1,-1 do
			if goodLevel(alliedPlayers[clientNum]) then
				return alliedPlayers[clientNum]
			end
        	end
	end

	-- not found -- all higher admins?
	return -1
end

function pickFromAndMove(from, to)
	local clientNum = pickPlayer(from)
	putTeam(clientNum, to)
end


function et_RunFrame( levelTime )
	local numAlliedPlayers = table.getn( alliedPlayers )
	local numAxisPlayers = table.getn( axisPlayers )
	
	if numAlliedPlayers >= numAxisPlayers + max_unevenDiff then
		pickFromAndMove("ALLIES", "AXIS")
	elseif numAxisPlayers >= numAlliedPlayers + max_unevenDiff then
		pickFromAndMove("AXIS", "ALLIES")	
	elseif numAlliedPlayers >= numAxisPlayers + unevenDiff then
		if unevenTime > 0 then
			if longEnough(levelTime) then
				pickFromAndMove("ALLIES", "AXIS")
			end
		else
			unevenTime = tonumber( levelTime )
		end
	elseif numAxisPlayers >= numAlliedPlayers + unevenDiff then
		if unevenTime > 0 then
			if longEnough(levelTime) then
				pickFromAndMove("AXIS", "ALLIES")
			end
		else
			unevenTime = tonumber( levelTime )
		end
	else
		unevenTime = -1
   	end
end
 
function et_ClientSpawn( clientNum, revived, teamChange, restoreHealth )
   if teamChange ~= 0 then
      local team = tonumber( et.gentity_get( clientNum, "sess.sessionTeam" ) )
      -- these were the teamnumbers prior to the move
      local numAlliedPlayers = table.getn( alliedPlayers )
      local numAxisPlayers = table.getn( axisPlayers )
      if team == 1 then
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               table.remove( alliedPlayers, i )
               break
            end
         end
         -- this should not happen but still check for it to avoid doubles
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               return
            end
         end
         -- make sure a player who (got) moved when teams were uneven doesn't get moved right back
         if numAlliedPlayers >= numAxisPlayers + unevenDiff then
            table.insert( axisPlayers, 1, clientNum )
         else
            table.insert( axisPlayers, clientNum )
         end
      elseif team == 2 then
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               table.remove( axisPlayers, i )
               break
            end
         end
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               return
            end
         end
         if numAxisPlayers >= numAlliedPlayers + unevenDiff then
            table.insert( alliedPlayers, 1, clientNum )
         else
            table.insert( alliedPlayers, clientNum )
         end
      else
         for i, num in ipairs( alliedPlayers ) do
            if num == clientNum then
               table.remove( alliedPlayers, i )
               return
            end
         end
         for i, num in ipairs( axisPlayers ) do
            if num == clientNum then
               table.remove( axisPlayers, i )
               return
            end
         end
      end
   end
end
 
function et_ClientDisconnect( clientNum )
   for i, num in ipairs( alliedPlayers ) do
      if num == clientNum then
         table.remove( alliedPlayers, i )
         return
      end
   end
   for i, num in ipairs( axisPlayers ) do
      if num == clientNum then
         table.remove( axisPlayers, i )
         return
      end
   end
end
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...