Forum

> > CS2D > Scripts > Always having this error with kick command?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Always having this error with kick command?

8 replies
To the start Previous 1 Next To the start

old Always having this error with kick command?

Louie
User Off Offline

Quote
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
owner = {140639}
rank = {}
ladm = {}

for id = 1,32 do
  rank[id] = 0
end

ladm.commands = {
      preffix = "!";
{"kick",level = 2,concat = 2,func = "kickCmd"};
{"ban",level = 3,concat = 2,func = "banCmd"};
}

addhook("join","setrank")
function setrank(id)
   for _, a in ipairs(owner) do
       if player(id,"usgn") == a then
           rank[id] = 5
       end
   end
end

addhook("say","ladm.say")
function ladm.say(id,txt)
     if string.sub(txt, 1, 1) == ladm.commands.preffix then
		local found = false
		local list = ladm.commands
		local txt = string.match(txt, "%p(.*)")
		local call = string.match(txt, "(.-)%s") or txt
		for key, command in ipairs(list) do
			local insert = table.insert
			local gmatch = string.gmatch
			local concat = table.concat
			found = false
			if #command > 1 then for _, name in ipairs(command) do if call == name then found = true end end
			elseif call == command[1] then found = true end

			if found == true then
				local params = {}
				local procCmd = false
				for word in gmatch(txt,"%S+") do if not procCmd and word == call  then procCmd = true else insert(params, tonumber(word) or word) end end

				if command.concat then
					params[command.concat] = concat(params, " ", command.concat)
					for i = command.concat + 1, #params do params[i] = nil end
				end

				if command.params then
					insert(params, 1, command.params)
					params = concat(params, " ")
					parse(params)
					return 1
				end

				local func, err = pcall(loadstring(command.func.."(...)"), id, unpack(params))
				if err then msg2(id,"Lua Error:"..err) ; print(err) end
				break
	              elseif key == #list then msg2(id,"Error,invalid command!") end
		end return 1
	end
end

function kickCmd(id,a,rs)
   if rank[id] > rank[a] then
      parse("kick "..a.." "..rs)
      msg(player(id,"name").." kicked "..player(a,"name").." for "..rs)
   
   elseif rank[id] <= rank[a] then
      msg2(id,"Cannot kick "..player(a,"name"))
      msg2(a,player(id,"name").." is trying to kick you!")
   end
end

function banCmd(id,t,rs)
   if rank[id] > rank[t] then
      parse("banusgn "..t.." 0 "..rs)
      parse("banip "..t.." 0 "..rs)
      msg(player(id,"name").." banned "..player(t,"name").." for "..rs)
   elseif rank[id] <= rank[t] then
      msg2(id,"Cannot ban "..player(t,"name"))
      msg2(t,player(id,"name").." is trying to ban you!")
   end
end
When i type in something like "!kick 2" (without quotes) yeah it kicks the player but it doesn't show the message, its supposed to show a message like: "player kicked player 2 for "reason" but instead it gives out an error
1
sys/lua/main.lua:67: attempt to concatenate a boolean value
BUT when i type something like "!ban 2" (without quotes) then it bans the player and shows the message(like "player banned player 2 for "reason").
Its really weird that if i use the kick command then it gives an error and doesn't show the message but if its the ban command i use then it fully works . Anyone who can help me would be good , i've been trying to fix that problem alot of times but i just can't fix it by myself .

old Re: Always having this error with kick command?

eledah
User Off Offline

Quote
You're calling for the player's name right after he's kicked.
1
2
parse("kick "..a.." "..rs)
msg(player(id,"name").." kicked "..player(a,"name").." for "..rs)
Should be
1
2
msg(player(id,"name").." kicked "..player(a,"name").." for "..rs)
parse("kick "..a.." "..rs)

old Re: Always having this error with kick command?

_Yank
User Off Offline

Quote
@user Louie: Simply because you chosen the wrong file to learn from. You should have picked something like file cs2d Command Processor or file File does not exist (15866) as they are more simple and less advanced (I think).

Anyways, about the fact of using my code, you're free to modify or use it as long you keep it for yourself and include my license on the file.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview