Forum

> > CS2D > Scripts > Error when i edited HC Admin Script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Error when i edited HC Admin Script

14 replies
To the start Previous 1 Next To the start

old Error when i edited HC Admin Script

Louie
User Off Offline

Quote
So i was trying to edit HC Admin Script but i'm having problems with the kick command:
1
2
3
4
5
6
7
8
function mod_kick_command(p,id,reason)
    if not hc.is_vip(id) then
       hc.exec(p,"kick "..id.." "..reason)
	elseif hc.is_vip(id) then
	   msg2(p,hc.RED.."Error,cannot kick VIP or higher!")
       return false
	end
end
I want it to be that i can kick a player and specify a reason to why i kicked him, so i added the "reason" argument to the kick function
but when i try to test it then it then it doesn't work and also gives me this error:
1
Error: sys/lua/hc/core/main.lua:109: bad argument #1 to 'player' (number expected, got string)
Please help i've been trying to solve this myself for a week now but i can't seem to get it to work

old Re: Error when i edited HC Admin Script

Mr_Magnifice
User Off Offline

Quote
you dont need to edit main.lua because there is already function "reason". Just when you write !kick command put + reason. There was problem as i see "Error,cannot kick VIP or higher!" you tried to kick VIP, you cannot do that with hc script. Download again HC script and replace old main.lua with your, do not touch they again. HC script already have "reason" with kick command on.

old Re: Error when i edited HC Admin Script

Louie
User Off Offline

Quote
@user Mr_Magnifice: I didn't edit main.lua but i re-installed HC Admin script so now i tried this:
1
2
3
function mod_kick_command(p,id,reason)
	hc.exec(p,"kick "..id.." "..tostring(reason))
end
if i do it like that then it works, though i always have to put quotes in the reason so it will show. But whenever i try to do it like this:
1
2
3
4
5
6
7
function mod_kick_command(p,id,reason)
    if hc.get_level(id) < hc.VIP then
	   hc.exec(p,"kick "..id.." "..tostring(reason))
	elseif hc.get_level(id) >= hc.VIP then
	   msg2(p,hc.RED.."Cannot kick VIP or higher!")
	end
end
then i get that error again:
1
bad argument #1 to 'player'(number expected,got string)
I don't know why i get that error when i try to add the "hc.get_level" or the "hc.is_vip"

old Maybe This

apex2d
User Off Offline

Quote
function mod_kick_command(---> p <---,id,reason)
if hc.get_level(id) < hc.VIP then
hc.exec(p,"kick "..id.." "..tostring(reason))
elseif hc.get_level(id) >= hc.VIP then
msg2(p,hc.RED.."Cannot kick VIP or higher!")
end
end

old Re: Error when i edited HC Admin Script

eledah
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function hc.moderation.kick_say_command(p, id)
	local array = {}
	local kick_reason = ""
	array = explode(" ", id)
	for i=2, #array do
		kick_reason = kick_reason.." "..array[i]
	end
	hc.exec(p, "kick " .. array[1]..' "'..kick_reason..'"')
end

function explode(div,str)
  if (div=='') then return false end
  local pos,arr = 0,{}
  for st,sp in function() return string.find(str,div,pos,true) end do
    table.insert(arr,string.sub(str,pos,st-1))
    pos = sp + 1
  end
  table.insert(arr,string.sub(str,pos))
  return arr
end

Edit this one as you please.

old Re: Error when i edited HC Admin Script

Nekomata
User Off Offline

Quote
1
hc.exec(p, "kick " .. array[1].." "..kick_reason..)
Fixed. This will also prevent any ban.lst bugs like this:
1
banip    123.456.789.1 0 "reason"
Yes, that actually happens.

old Re: Error when i edited HC Admin Script

Louie
User Off Offline

Quote
@user eledah: @user Nekomata: I tried it but when i try out the kick command then it doesn't work and i also get this error:
1
sys/lua/hc/core/commands.lua:96: attempt to call field 'function'(a nil value)
And i haven't even edited anything in that file(commands.lua)
Please help.

old Re: Error when i edited HC Admin Script

eledah
User Off Offline

Quote
Paste this
1
hc.add_say_command("kick", hc.moderation.kick_say_command, hc.MODERATOR1, "<id>", "Kick a player.")

inside "function hc.moderation.init()", in moderation.lua

old Re: Error when i edited HC Admin Script

Louie
User Off Offline

Quote
@user Ajmin: Ok i will reinstall HC Admin Script again and copy-paste it.

//Edit: LOL i found out the problem:
1
hc.add_say_command("kick", mod_kick_command, hc.MODERATOR1, "<id> <[reason]>", "Kick someone. You can also specify a reason.")
Apparently i specified the function "mod_kick_command" there but when i copy/pasted the kick function:
1
hc.moderation.kick_say_command
so the script was attempting to call a nil value.Now i fixed the function name and i tested it and it worked:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
hc.add_say_command("kick", mod_kick_command, hc.MODERATOR1, "<id> <[reason]>", "Kick someone. You can also specify a reason.")

function reason_string(div,str)
    if (div=='') then return false end
       local pos,arr = 0,{}
    for st,sp in function() return str:find(div,pos,true) end do
       table.insert(arr,str:sub(pos,st-1))
       pos = sp + 1
    end
    table.insert(arr,str:sub(pos))
    return arr
end

function mod_kick_command(p, id)
    local array = {}
    local kick_reason = ""
    array = reason_string(" ", id)
    for i = 2, #array do
        kick_reason = kick_reason.." "..array[i]
    end

    hc.exec(p, "kick " .. array[1]..' "'..kick_reason..'"')
end
thank you so much @user eledah:,@user Nekomata: you guys helped me alot

//EDIT2//: Though when i try to put in the:
1
2
3
4
if hc.get_level(array[1]) < hc.VIP then
       hc.exec(p, "kick " .. array[1]..' "'..kick_reason..'"')
	elseif hc.get_level(array[1]) >= hc.VIP then
	   msg2(p,hc.RED.."Cannot kick VIP or higher")
Even if i added the hc.get_level things(so i VIP or higher cant be kicked) i was still able to kick myself from the server lol.
edited 2×, last 09.05.15 02:35:00 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview