ETMods.net

N!tmod, a Wolfenstein: Enemy Territory Modification!

You are not logged in.

Announcement

You can donate to help us keeping services online.

#1 05-Apr-13 14:48:25

Kode
Member
Registered: 20-Mar-13
Posts: 17

Changing weapon cvars based on player count

I used Nitrox's Dynamic Cvar Changer and updated it for the settings I wanted, but it doesnt seem to work:

-- Dynamic Cvar Changer
-- LUA by N!trox*
-- This script can be useful if admins want to modify weapon restrictions 
-- depending on how many players are playing (spectators are ignored).
-- It was first created to allow admins to dynamically change g_TDMScore 
-- on N!tmod server running TeamDeathMatch gametype.
-- This script should be compatible with ANY mod that supports LUA.
-- Website: www.etmods.net
-- eMail: admin@etmods.net
-- IRC: #nitmod @ freenode
--------------------------------------------------------------------------------
-- Ver 1.0 (June 3rd 2010)
-- - Initial version, was only called on ClientUserinfoChanged
--------------------------------------------------------------------------------
-- Ver 1.1
-- - Added: "nitrox_AdjustCvarValue" function
-- - Added: Real Time playercount
-- - Modified: Don't call et.trap_Cvar_Set when not needed
--------------------------------------------------------------------------------
-- Ver 1.2
-- - Added: basic bitwise operations
--------------------------------------------------------------------------------

MODNAME = "Dynamic Cvar Changer"
MODVERSION = "1.2"

function et_InitGame(leveltime, randomseed, restart)
	et.RegisterModname(string.format("%s %s", MODNAME, MODVERSION))
	maxClients = tonumber(et.trap_Cvar_Get("sv_maxclients")) - 1;
	numPlayingClientsBackup = 0;
	et.G_Print("++++\n-- 'Dynamic Cvar Changer' v" .. MODVERSION .. " LUA Module Loaded!\n-- By N!trox* @ www.etmods.net\n++++\n");
end

function testflag(set, flag)
  return set % (2*flag) >= flag
end

function setflag(set, flag)
  if set % (2*flag) >= flag then
    return set
  end
  return set + flag
end

function clrflag(set, flag) -- clear flag
  if set % (2*flag) >= flag then
    return set - flag
  end
  return set
end

function et_RunFrame(leveltime)
	local numPlayingClients = 0;
	for i=0, maxClients do
		if (tonumber(et.gentity_get(i, "sess.sessionTeam")) == 1) or (tonumber(et.gentity_get(i, "sess.sessionTeam")) == 2) then
			numPlayingClients = numPlayingClients + 1;
		end
	end
	
	nitrox_AdjustCvarsValues( numPlayingClients );
end


function nitrox_AdjustCvarsValues( numclients )
	local weaponFlagsStr = et.trap_Cvar_Get("g_weapons");
	local weaponFlags = tonumber(weaponFlagsStr);
	
	if(numPlayingClientsBackup == 0 and numclients == 0) then
		return;
	elseif (numPlayingClientsBackup == numclients) then
		return;
	end
	
	numPlayingClientsBackup = numclients;
	
	if(numclients >= 14) then
		if(not testflag(weaponFlags, 4)) then
			weaponFlags = setflag(weaponFlags, 4);
			et.G_Print("Enabled bomb!\n");
		end
	else 
		if(testflag(weaponFlags, 4)) then
			weaponFlags = clrflag(weaponFlags, 4);
		end
	end
		
	weaponFlagsStr = string.format(weaponFlags);
	
	et.trap_Cvar_Set("g_weapons", weaponFlagsStr)

	if (numclients < 10) then
		et.trap_Cvar_Set("team_maxTripmines", "0")	
		et.trap_Cvar_Set("team_maxRifleGrenades", "0")	
		et.trap_Cvar_Set("team_maxPanzers", "0")	
		et.trap_Cvar_Set("team_maxLandmines", "6")	
		et.trap_Cvar_Set("team_maxFlamers", "0")	
	elseif (numclients >= 10 and numclients < 12) then
		et.trap_Cvar_Set("team_maxTripmines", "1")	
		et.trap_Cvar_Set("team_maxRifleGrenades", "1")	
		et.trap_Cvar_Set("team_maxPanzers", "0")	
		et.trap_Cvar_Set("team_maxLandmines", "7")	
		et.trap_Cvar_Set("team_maxFlamers", "0")
	elseif (numclients >= 12 and numclients < 14) then
		et.trap_Cvar_Set("team_maxTripmines", "1")	
		et.trap_Cvar_Set("team_maxRifleGrenades", "1")	
		et.trap_Cvar_Set("team_maxPanzers", "1")	
		et.trap_Cvar_Set("team_maxLandmines", "10")	
		et.trap_Cvar_Set("team_maxFlamers", "1")
	elseif (numclients >= 14 and numclients < 16) then
		et.trap_Cvar_Set("team_maxTripmines", "1")	
		et.trap_Cvar_Set("team_maxRifleGrenades", "1")	
		et.trap_Cvar_Set("team_maxPanzers", "1")	
		et.trap_Cvar_Set("team_maxLandmines", "11")	
		et.trap_Cvar_Set("team_maxFlamers", "1")
	elseif (numclients >= 16 and numclients < 18) then
		et.trap_Cvar_Set("team_maxTripmines", "1")	
		et.trap_Cvar_Set("team_maxRifleGrenades", "1")	
		et.trap_Cvar_Set("team_maxPanzers", "1")	
		et.trap_Cvar_Set("team_maxLandmines", "12")	
		et.trap_Cvar_Set("team_maxFlamers", "1")
	elseif (numclients >= 18) then
		et.trap_Cvar_Set("team_maxTripmines", "2")	
		et.trap_Cvar_Set("team_maxRifleGrenades", "2")	
		et.trap_Cvar_Set("team_maxPanzers", "2")	
		et.trap_Cvar_Set("team_maxLandmines", "16")	
		et.trap_Cvar_Set("team_maxFlamers", "2")

	end

end

It just doesnt seem to do anything, I ran lua_modules and it said it was loaded.

Even worse it seemed to override default settings in the server.cfg I have:
set team_maxPanzers            "0"

but with this loaded people could choose to have a panzer even though it was only 4v4 so I had to take it back off again.

Also the default in server.cfg is to allow teams to have 1 tripmine, the lua is supposed to disable it on less than 5v5 yet it was available on 4v4

Any ideas?

Last edited by Kode (05-Apr-13 14:50:31)

Offline

#2 05-Apr-13 18:56:45

Micha
Member
From: Germany
Registered: 11-Feb-13
Posts: 38
Website

Re: Changing weapon cvars based on player count

I downloaded the lua you posted and it works for me. Are you sure you didn't messed up anything in it?
You should put luas like this (example):
set lua_modules "luaname.lua luablub.lua weapon.lua setlevel.lua"

Offline

#3 05-Apr-13 19:47:29

Kode
Member
Registered: 20-Mar-13
Posts: 17

Re: Changing weapon cvars based on player count

Weird, that's what I did, and if I hadn't it wouldn't (I assume) have shown up in the output of lua_modules also if there was something messed up in it surely it wouldn't have worked for you either?

I'll try it again though, so I just need to do a !readconfig or would a server restart be needed?

Offline

#4 06-Apr-13 11:34:07

Micha
Member
From: Germany
Registered: 11-Feb-13
Posts: 38
Website

Re: Changing weapon cvars based on player count

Readconfig command is just for shrubbot and settings files. You need to do a map change or reset. I always do !reset
You can check if the lua is loaded with /lua_status

Offline

Board footer

Powered by FluxBB