Forum

> > CS2D > Scripts > Making an Admin script?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Making an Admin script?

28 replies
Page
To the start Previous 1 2 Next To the start

old Making an Admin script?

Louie
User Off Offline

Quote
I'm trying to make an Admin script but i have a question:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ADMIN = {}
MOD = {}
GUARD = {}
VIP = {}

for id = 1, 32 do
    ADMIN[id] = {140639} 
    MOD[id] = {0}
    GUARD[id] = {0}
    VIP[id] = {0}
end
--Commands
addhook("say","kicking")
function kicking(id,txt)
if (txt == "!kick "..id) and ADMIN[id] == {player(id,"usgn")} or MOD[id] == {player(id,"usgn")} or GUARD[id] == {player(id,"usgn")}  then
parse("kick "..player)
    end
end
I just wanna know is that correct way of what im doing? so that the kick command can only be used by Admin,Mod and Mod2.

Admin/mod comment

Please don't use spoiler around code (use more instead). Also only use it when your code is very long /DC

old Re: Making an Admin script?

Dousea
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
admin = {140639}
moderator = {}
guard = {}
vip = {}

function ismember(id, member)
	for none, usgn in pairs(_G[member]) do
		if (usgn == player(id, "usgn")) then
			return true
		end
	end
	
	return false
end

addhook("say", "sayhook")

function sayhook(id, text)
	if (text:sub(1, 5) == "!kick") then
		if (ismember(id, "admin") or ismember(id, "moderator") or ismember(id, "guard")) then
			if (type(tonumber(text:sub(7, #text)) == "number") then
				parse("kick " .. text:sub(7, #text))
			else
				msg2(id, "\169255255255ERROR: wrong parameter type (got, " .. text:sub(7, #text) .. ", number expected)")
			end
		end
	end
end

old Re: Making an Admin script?

THEMUD
User Off Offline

Quote
Use this for more comfort:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ADMIN = {140639}
MOD = {}
GUARD = {}
VIP = {}

addhook("say","kicking")
function kicking(id,txt)

if(player(id,"usgn") == ADMIN[id] or player(id,"usgn") ==  MOD[id] or player(id,"usgn") == GUARD[id])
then
if (sub.string(1, 5) == "!kick") 
then
man = sub.string(7, 8)
parse("kick "..man)
end
end
end

old Re: Making an Admin script?

THEMUD
User Off Offline

Quote
user eledah has written
@user Louie: Even if you don't want use another admin script, you can still learn how to code from them, do it please.
@user THEMUD: Stop stupiditing
1
"ADMIN[id]"


I put "ADMIN [id]" because he made a variable called "ADMIN" and the [id] for its index/value.

old Re: Making an Admin script?

Louie
User Off Offline

Quote
Though how do i make it that a player can kick or ban a player using menu buttons?
EDIT: Forgot to ask tho,is it possible to use a variable that is in another file(like u want to use a variable in your script but that variable is in another folder and file) ?
edited 1×, last 02.02.15 03:51:15 pm

old Re: Making an Admin script?

Infinite Rain
Reviewer Off Offline

Quote
@user THEMUD:
Here's how it's done:
1
2
3
4
5
for k, v in pairs(ADMIN) do
 if player(id, 'usgn') == v then
  --Do the shit needed
 end
end
^ That is an example of how one of the parts of the script can be made.

@user Inflexion:
The fuck? Lmao.

old Re: Making an Admin script?

Louie
User Off Offline

Quote
Well, can someone show me how to do the kick/ban/mute of a player through menu buttons?
EDIT: Yea the !kick thing works but it always shows the message even if i had put return 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("say","kicksay")
function kicksay(id,text)
for none, usgn in ipairs(ADMIN,MOD) do
if player(id,'usgn') == usgn then
  if (text:sub(1, 5) == "!kick") then
     if (type(tonumber(text:sub(7, #text)) == "number")) then
        parse("kick "..text:sub(7, #text))
             return 1
     else msg2("©255000000Not Authorized!")
                end
            end
        end
    end
end
edited 1×, last 03.02.15 09:06:24 am

old Re: Making an Admin script?

Bowlinghead
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
ADMIN = {140639,1} -- type usgn here ("," to seperate)

function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
mute = initArray(32) -- create array (32 slots for 32 possible ids)

reason = "admin script!"
addhook("serveraction","menu")
function menu(id,b)
	for i=1,#ADMIN do
		if player(id,"usgn")==ADMIN[i] then -- "admin" check
          		menu("Whats up?,Kick,Ban,Mute")
     		end
	end
end

addhook("menu","menuhook")
function menuhook(id,t,b)
	if t=="Whats up?" then
		if b==1 then
			-- TODO: selection of the player that gets kicked (id=playerID that gets kicked)
			parse("kick "..id.." "..reason)
		elseif b==2 then
			-- TODO: selection of the player that gets banned (id=playerID that gets banned)
			parse("ban "..id.." "..reason)
		elseif b==3 then
			-- TODO: selection of the player that gets muted (id=playerID that gets muted)
			mute[id] = 1 -- player gets muted
		end
	end
end

addhook("say","sayhook")
function sayhook(id,txt)
	if mute[id]==1 then -- if he got muted
		msg2(id,"You are not allowed to speak with other people!") -- optional text
		return 1; -- dont show text
	end
end

addhook("leave","left")
function left(id)
	mute[id] = 0 -- the ID gets 0 if player leaves (else a new one that joines isn´t able to speak)
end
-- untested

Your script might look like this.
edited 4×, last 03.02.15 08:55:25 am

old Re: Making an Admin script?

Louie
User Off Offline

Quote
@user Bowlinghead: Ok but i still have one problem,this is part of my code.
1
2
3
4
5
6
7
8
9
addhook("say","kicksay")
function kicksay(id,text)
for none, usgn in ipairs(ADMIN) do
if player(id,'usgn') == usgn then
  if text:sub(1, 5) == "!kick" then --KICK
     kickid = text:sub(6, 7)
     kickreason = text:sub(8)
    parse("kick "..kickid.." "..kickreason)
return 1
even though i put an return 1 to it,it still shows the message in-game,it kicks the player but the message still appears,like i say !kick 2 the player with id 2 gets kicked but the !kick 2 message still appears in-game,how do i fix that?

old Re: Making an Admin script?

Bowlinghead
User Off Offline

Quote
Ehm...
You need to add "end"s to your code.
Like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("say","kicksay")
function kicksay(id,text)
	for none, usgn in ipairs(ADMIN) do
		if player(id,'usgn') == usgn then
  			if text:sub(1, 5) == "!kick" then --KICK
    	 			kickid = text:sub(6, 7)
     				kickreason = text:sub(8)
    				parse("kick "..kickid.." "..kickreason)
				return 1
			end
		end
	end
end
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview