Forum

> > CS2D > Scripts > ban system is not working. (script)
Forums overviewCS2D overview Scripts overviewLog in to reply

English ban system is not working. (script)

5 replies
To the start Previous 1 Next To the start

old ban system is not working. (script)

muxarus
User Off Offline

Quote
Hello us nrealSoftWare.de!
Today im updating my server in CS2D and i got one problem...
I know, my script is too small and very easy to make.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
addhook("say","adminCommands")
function adminCommands(id,txt)
		if string.sub(txt,1,6)=="!name " then
			local nametoban = string.sub(txt,7) --hmm variable won't to set
		end
		if string.sub(txt,1,6)=="!time " then
			local timetoban = string.sub(txt,7)
		end
		if string.sub(txt,1,8)=="!reason " then
			local reasontoban = string.sub(txt,9) --also there
		end
		if(txt=="!banname") then
			if nametoban~="" then
				if reasontoban~="" then
					if timetoban~="" then
						parse("banname "..nametoban.." "..timetoban.." "..reasontoban)
						nametoban = ""
						timetoban = ""
						reasontoban = ""
					else
						msg2(id,color[3].."Use !time 'time there' to switch time to ban")
					end
				else
					msg2(id,color[3].."Use !reason 'reason' to switch reason to ban")
				end
			else
				msg2(id,color[3].."Use !name 'name there' to switch name to ban")
			end
		end
	return 1
end

old Re: ban system is not working. (script)

The Gajos
BANNED Off Offline

Quote
> Use this:
function toTable(txt,match)
	local cmd = {}
	if not match then match = '[^%s]+' end
	for word in string.gmatch(txt,match) do
		table.insert(cmd,word)
	end
	return cmd
end


> How is it work?
> for word in string.gmatch("Hello Lua user", "%a+") do print(word) end
Hello
Lua
user

old Re: ban system is not working. (script)

VADemon
User Off Offline

Quote
You're declaring local variables inside the if-condition. Once it has reached it's end:
1
2
3
4
5
if () then 
local var=5
print(var)
end -- as of this line var is deleted
print(var)
you can't access it anymore. Read a tutorial on Variable Scoping and if you'll have questions left, come again to ask.

old Re: ban system is not working. (script)

The Gajos
BANNED Off Offline

Quote
> Something like this:

function toTable(txt,match)
	local cmd = {}
	if not match then match = '[^%s]+' end
	for word in string.gmatch(txt,match) do
		table.insert(cmd,word)
	end
	return cmd
end

addhook("say","adminCommands")
function adminCommands(id,txt)
	local cmd = toTable(txt)
	if cmd[1] == "!name" then --here isn't "!name " but "!name", just without spacebar
		local nametoban = cmd[2]
	end
	...

old Re: ban system is not working. (script)

VADemon
User Off Offline

Quote
@user The Gajos: No, nothing like "that". You did the exact mistake I was talking about, local nametoban = cmd[2] is only "visible" inside that if-condition, you can't use it afterwards.
@user muxarus: I've looked at your code again. You don't need the local variables at all, as you want it to work after submitting different commands. 1) Make them global. Furthermore, to avoid conflicts with other possible admins, 2) make these variables "personal", put them into a table like that:
1
2
3
4
banCommand = {}
banCommand.nametoban = {}
banCommand.timetoban = {}
banCommand.reasontoban = {}
Then, to assign values into each admin's personal table use this:
1
banCommand.nametoban[ id ] = string.sub(9999)
This way, nobody except the admin with ID id will be able to interfere with his command. Write a reply if the explanation wasn't clear enough.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview