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 20-Mar-13 12:57:44

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

Custom command to set level

We have several user levels
8 is a new member
level 12+ has access to setlevel
However, I want to restrict level 12 to only allow them to set users to level 8 something like the following where I remove the flag setlevel from 12 and make them use !member instead

**********
name = member
exec = !setlevel [1] 8
desc = Sets a user as a new member level 8
levels = 12, 13, 14, 15, 16, 17, 18, 19, 20

But I don't think that will work as 1) I'm not sure you can use an admin command (!setlevel) in the exec? and 2) if I remove the flag setlevel from 12 it wouldn't work anyway would it?

Is there any way to do this?

Offline

#2 20-Mar-13 20:29:56

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

Re: Custom command to set level

Add the following code into a .lua file (create a .txt file and just rename it to maxsetlevel.lua)
Alternative download it here: http://www.mnwa.bplaced.net/ftpfiles/Lua/

--setlevel command
setlevel_cmd 	= "!setlevel"

--Maximal level to set
maxlevel 		= 8

--Admins over/same level are allowed to setlevel each value
allowedadmins 	= 20

--Text which is shown to the admins
text = "^1WARNING: ^3Maximal value of setlevel command is^1"

----------------------end of config-----------------------------

function et_ClientCommand(clientNum, command)
	local arg0 = string.lower(et.trap_Argv(0))
	if arg0 == "say" or arg0 == "say_team" or arg0 == "say_buddy" or arg0 == "say_teamnl" then
		if string.find(et.trap_Argv(1), "^" .. setlevel_cmd .. "") then
			if et.trap_Argv(2) then
				if tonumber(et.trap_Argv(3)) > maxlevel and tonumber(et.G_shrubbot_level(clientNum)) < allowedadmins then
					et.trap_SendServerCommand(clientNum,"chat \""..text.." "..maxlevel.."\"")
					return 1
				end
			end
		end
	end
	return 0
end
---------------------------------------------------------------------

Put this lua into your mod folder and search in your server.cfg for lua_modules "" and add maxsetlevel.lua.
set lua_modules"maxsetlevel.lua"

Last edited by Micha (20-Mar-13 20:34:17)

Offline

#3 21-Mar-13 11:00:48

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

Re: Custom command to set level

Wow, thanks for that, the only thing is if it's overwriting the setlevel command rather than a new command it will affect other members as well.

Basically if possible

Level 12 can max set a user to 8
Level 13 can max set a user to 10
Level 14 & 15 can max set a user to 11
Level 16 can max set a user to 12
Level 17 can max set a user to 14

Or if it makes it easier admins 16 and below can only set a member to a level 4 below their own, level 17 - 20 it works as it normally would

Last edited by Kode (21-Mar-13 11:03:20)

Offline

#4 21-Mar-13 20:40:36

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

Re: Custom command to set level

I tested the following lua on etpub so I don't know if the lua works correctly. Just give an answer here tongue

--Script made for Kodes needs :P

--Setlevel command (!setlevel will work with this too)
setlevel_cmd 	= "!set"

--Admins over/same level are allowed to setlevel each value
allowedadmins 	= 18

--getadminlevel is the level of the executing admin
--maxlevel is the maximal level he is allowed to set
level_table = {
	{ getadminlevel = 11, 			maxlevel = 8, }, --this line is the new maxlevelrest
        { getadminlevel = 12, 			maxlevel = 8, },
	{ getadminlevel = 13, 			maxlevel = 10, },
	{ getadminlevel = 14, 			maxlevel = 11, },
	{ getadminlevel = 15, 			maxlevel = 11, },  
	{ getadminlevel = 16, 			maxlevel = 12, },  
	{ getadminlevel = 17, 			maxlevel = 14, },     	
}

--Text which is shown to the admins
text = "^1WARNING: ^3You are just allowed to use "..setlevel_cmd.." till^1"

----------------------end of config-----------------------------

function et_ClientCommand(clientNum, command)
    local cmd = string.lower(command)
	local arg0 = string.lower(et.trap_Argv(0))
	if arg0 == "say" or arg0 == "say_team" or arg0 == "say_buddy" or arg0 == "say_teamnl" then
		if string.find(et.trap_Argv(1), "^" .. setlevel_cmd .. "") then
			if et.trap_Argv(2) and tonumber(et.trap_Argv(3)) then --if admin typed in console
				for _, line in ipairs(level_table) do
					if tonumber(et.G_shrubbot_level(clientNum)) <= line.getadminlevel then
						local maxlevel = line.maxlevel
						if tonumber(et.trap_Argv(3)) > maxlevel then
							et.trap_SendServerCommand(clientNum,"chat \""..text.." "..maxlevel.."\"")
							return 1
						end
					end
				end
			else --if admin typed in chat window
				for _, line in ipairs(level_table) do
					local findnumber = string.gfind(et.trap_Argv(1), "%s"..line.maxlevel.."") --need a way to find the number. "et.trap_Argv(1)" is always the whole text (!set name number).
					if findnumer == nil then et.trap_SendServerCommand(clientNum,"chat \"^3Use console to use '"..setlevel_cmd.."' command, please. Open it with ^\"") return 1 end
					--[[ --Took it out since I don't know a way to find out the number
					if tonumber(et.G_shrubbot_level(clientNum)) <= line.getadminlevel then
						local maxlevel = line.maxlevel
						if tonumber(findnumber) > maxlevel then
							et.trap_SendServerCommand(clientNum,"chat \""..text.." "..maxlevel.."\"")
							return 1
						end
					end
					--]]
				end
			end
		end
	elseif string.find(cmd, "^" .. setlevel_cmd .. "") then --in case admin used a slash (/) before ! -> /!set player 4
		if et.trap_Argv(1) then
			for _, line in ipairs(level_table) do
				if tonumber(et.G_shrubbot_level(clientNum)) <= line.getadminlevel then
					local maxlevel = line.maxlevel
					if tonumber(et.trap_Argv(2)) > maxlevel then
						et.trap_SendServerCommand(clientNum,"chat \""..text.." "..maxlevel.."\"")
						return 1
					end
				end
			end
		end
	end
	return 0
end
---------------------------------------------------------------------

Last edited by Micha (25-Mar-13 11:43:38)

Offline

#5 22-Mar-13 10:10:11

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

Re: Custom command to set level

big_smile you rock, I will give it a try tonight, thanks so much for that smile

Offline

#6 23-Mar-13 13:05:52

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

Re: Custom command to set level

Hi again, sorry to be a pain but it doesn't seem to work.

In server.cfg I have:

//=============================LUA==========================//

set lua_modules               "balanceteams.lua"
set lua_modules               "maxlevel.lua"

and maxlevel.lua is in the nitmod folder

It just doesnt seem to do anything at all, any ideas for somethiing i've done wrong?

Offline

#7 23-Mar-13 13:18:58

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

Re: Custom command to set level

Ahh extra lua files should be space seperated right?

*edit* That still doesn't work =/

*edit2*

The Lua file is being loaded, just sin't working:
Lua API: showing lua information ( 2 modules loaded )
VM Modname                  Signature                                Filename               
-- ------------------------ ---------------------------------------- ------------------------
0                          6B8DCC3A3F2986896FEDC200564AD3DD1E292E9D balanceteams.lua       
1                          25DACADDE6D508F56B79D6130C87B39292409929 maxlevel.lua           
-- ------------------------ ---------------------------------------- ------------------------

Last edited by Kode (23-Mar-13 13:34:56)

Offline

#8 23-Mar-13 15:42:01

Grandad
BETA Tester
Registered: 29-Dec-11
Posts: 168

Re: Custom command to set level

If you run "nitmod-2.2-091712" that might be the problem. I was not able to run lua with that one.

And, yes, space seperated.

Offline

#9 23-Mar-13 16:56:53

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

Re: Custom command to set level

The balance teams lua works though, we are running nitmod_2.2.1_r772

Offline

#10 24-Mar-13 01:07:44

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

Re: Custom command to set level

I will download this mod and try it on local host. Should be a mod problem since it worked on etpub tongue
Where can I get nitmod_2.2.1_r772?

*EDIT*
I tested on nitmod 2.2 and I fixed a little error. Re download the lua above and it should work.

Last edited by Micha (24-Mar-13 01:42:22)

Offline

#11 24-Mar-13 14:29:34

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

Re: Custom command to set level

Hi Micha,

Thanks for everything you have done so far, I'm sure it must be something I'm doing wrong, lol.

I reuploaded the lua.

Tried !readconfig asked a level 17 to set someone who was level 13 to 16 and they were set to 16 so he set him back to 13

I tried restarting the server and the same thing happened.

Could I put something in the code to output a message to the person doing !setlevel so we can debug if the script is even getting executed?

I'm a PHP dev, so I have a basic understanding of what the script is doing, but I have zero experience with lua so don't really know where to start to fix it.

*edit*
I tried adding an extra et.trap_SendServerCommand(clientNum,"chat \""..text.." "..maxlevel.."\"")

after

local arg0 = string.lower(et.trap_Argv(0))

to try and debug if the script was being executed.

Then I did a !readconfig

Nothing displayed when I tried it (level 20)

So either the script isn't being executed, !readconfig doesn't reload the lua and I would need to do a server restart, or I can't just put a SendServerCommand in without setting the return status right after it? If i've read it correctly, return 0 will continue with the normal execution of !setlevel whereas return 1 should interrupt it, but like I said, I don't know enough about it really.

Last edited by Kode (24-Mar-13 14:38:40)

Offline

#12 24-Mar-13 22:25:07

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

Re: Custom command to set level

Lol, it's started working big_smile

Offline

#13 24-Mar-13 22:34:29

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

Re: Custom command to set level

Kode wrote:

Lol, it's started working big_smile

I updated the lua once again. It should fix all ways I know now -> console, chat window, console with a / before !set
I think your guy used chat window so it didn't worked.

Offline

#14 24-Mar-13 23:29:49

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

Re: Custom command to set level

elseif tonumber(et.trap_Argv(3)) <= maxlevelrest and tonumber(et.G_shrubbot_level(clientNum)) < allowedadmins then

Should that not be

elseif tonumber(et.trap_Argv(3)) > maxlevelrest and tonumber(et.G_shrubbot_level(clientNum)) < allowedadmins then

because weirdly if a level 12 tries to set a member to less than 8 (i.e. level 1- 7) they get the message they can only set till 8 although I would have thought they would get caught by the if and not fall to the elseif

http://bayimg.com/hakKhAAEp <-- example

it's not really an issue though, the rest seems to work fine, just trying to understand it

Offline

#15 24-Mar-13 23:57:06

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

Re: Custom command to set level

Ok this is really weird, it seems to work sometimes but not others.

one of the level 12s gets the warning whatever level they try to set (screenshot above) the level 17 could set any level up to 16 (max should have been 14) I set him to 12 and he could set users to any level except 8 where he got a warning, I set him back to 17 and then he could only set up to level 14, then randomly a few minutes later he could set up to 16 again.  For some other members it seems to work as expected.

Offline

#16 25-Mar-13 01:16:08

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

Re: Custom command to set level

Micha wrote:
Kode wrote:

Lol, it's started working big_smile

I updated the lua once again. It should fix all ways I know now -> console, chat window, console with a / before !set
I think your guy used chat window so it didn't worked.


I just saw this message, the lua I've been using was the version before, I will update to the latest one and see if that makes any difference, sorry for the confusion

Offline

#17 25-Mar-13 11:40:30

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

Re: Custom command to set level

Kode wrote:
Micha wrote:
Kode wrote:

Lol, it's started working big_smile

I updated the lua once again. It should fix all ways I know now -> console, chat window, console with a / before !set
I think your guy used chat window so it didn't worked.


I just saw this message, the lua I've been using was the version before, I will update to the latest one and see if that makes any difference, sorry for the confusion


I updated it once again and it should work 100% now. I tested all cases on me.
Sorry for this but my brain failed tongue

Offline

#18 25-Mar-13 12:15:58

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

Re: Custom command to set level

heh, bet you wish you never tried to help wink

I will test it out when I get home.

can I change:
text = "^1WARNING: ^3You are just allowed to use "..setlevel_cmd.." till^1"
to
text = "^1WARNING: ^3You are just allowed to use !setlevel till^1"

because you have changed setlevel_cmd to !set which is better because it will work with shortcuts like !setl but !set doesnt actually work for changing the level so might confuse people

Offline

#19 25-Mar-13 17:55:47

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

Re: Custom command to set level

Kode wrote:

heh, bet you wish you never tried to help wink

I will test it out when I get home.

can I change:
text = "^1WARNING: ^3You are just allowed to use "..setlevel_cmd.." till^1"
to
text = "^1WARNING: ^3You are just allowed to use !setlevel till^1"

because you have changed setlevel_cmd to !set which is better because it will work with shortcuts like !setl but !set doesnt actually work for changing the level so might confuse people

Sure you can set it to everything you want.

Offline

#20 25-Mar-13 18:52:03

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

Re: Custom command to set level

heh, was just checking that changing it wouldn't break anything smile

Offline

#21 04-Apr-13 22:33:56

Gauki
BETA Tester
From: Germany
Registered: 30-Aug-12
Posts: 114
Website

Re: Custom command to set level

nitroy and micha should work together smile i think they can create the best mods ever ^^


DooC_sigbanner.gif

Offline

Board footer

Powered by FluxBB