Forum

> > CS2D > Scripts > ADD & REMOVE VIP
Forums overviewCS2D overview Scripts overviewLog in to reply

English ADD & REMOVE VIP

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

old Re: ADD & REMOVE VIP

Gaios
Reviewer Off Offline

Quote
user SektoR_ has written
Hi all! I'm here again to ask how do I add a command @addvip <usgn> or <id> (vip to add to the server) and @removevip <usgn> or <id> (to remove vip). Not forgetting that the vip will have rights to some skins and others.

Please show me how!

@user SektoR_I'll do all the code for you if you give me something in return.

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
function Array(s,v)
	local a = {}
	for i = 1,s do
		a[i] = v
	end
	return a
end
vip = Array(32,0)

function LoadAccount(id)
	local usgn = player(id,"usgn")
	if usgn > 0 then
		local file = io.open("sys/lua/"..usgn..".txt","r")
		if file then
			vip[id] = tonumber(file:read());
		end
	end
end

function SaveAccount(id,level)
	local usgn = player(id,"usgn")
	if usgn > 0 then
		local file = io.open("sys/lua/"..usgn..".txt","w")
		file:write(level)
		file:close()
	end
end

addhook("join","_joinHook")
function _joinHook(id)
	vip[id] = 0
	LoadAccount(id)
	if vip[id] == 1 then
		msg2(id,"©000255000You are VIP!@C")
	end
end

addhook("say","_sayHook")
function _sayHook(id,txt)
for pl = 1,32 do
	if txt == "!addvip "..pl.."" then
		vip[pl] = 1
		SaveAccount(pl,1)
		return 1
	elseif txt == "!removevip "..pl.."" then
		vip[pl] = 0
		SaveAccount(pl,0)
		return 1
	end
end
end
edited 1×, last 09.10.12 02:06:48 pm

old Re: ADD & REMOVE VIP

Suprise
BANNED Off Offline

Quote
Better if you make a folder to every Usgn. Otherwise lua folder will get spammed!

old Re: ADD & REMOVE VIP

Gaios
Reviewer Off Offline

Quote
user Suprise has written
Better if you make a folder to every Usgn. Otherwise lua folder will get spammed!


Let him add folder.
edit for SaveAccount and LoadAccount change:
1
2
local file = io.open("sys/lua/"..usgn..".txt","r")
local file = io.open("sys/lua/"..usgn..".txt","w")
on
1
2
local file = io.open("sys/lua/saves/"..usgn..".txt","r")
local file = io.open("sys/lua/saves/"..usgn..".txt","w")

You must create folder: saves

old Re: ADD & REMOVE VIP

Suprise
BANNED Off Offline

Quote
@user Gaios: Also better not add vip if he is already, don't you think?^^

Change this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("say","_sayHook")
function _sayHook(id,txt)
for pl = 1,32 do
     if txt == "!addvip "..pl.."" then
          vip[pl] = 1
          SaveAccount(pl,1)
          return 1
     elseif txt == "!removevip "..pl.."" then
          vip[pl] = 0
          SaveAccount(pl,0)
          return 1
     end
end
end

to

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
addhook("say","_sayHook")
function _sayHook(id,txt)
	for pl = 1,32 do
		if txt == "!addvip "..pl.."" then
			if vip[pl] == 0 then
				vip[pl] = 1
				SaveAccount(pl,1)
				msg2(pl,"©255255255You're now VIP!")
				return 1
			else
				msg2(id,"©255000000Error: The player you wanted to add is already VIP!")
			end
		elseif txt == "!removevip "..pl.."" then
			if vip[pl] == 1 then
				vip[pl] = 0
				SaveAccount(pl,0)
				msg2(pl,"©255255255Your vip status has been removed!")
				return 1
			else
				msg2(id,"©255000000Error: This guy is NOT VIP!")
			end
		end
	end
end

This looks better

old Re: ADD & REMOVE VIP

sheeL
User Playing CS2D

Quote
See, only a bit example

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
addhook("serveraction","a")
function a(if,a)
	if a == 1 then
		if vip[id] == 1 then
		menu(id,"Test,A,B,C")
		else
		msg2(id,"©255255255Error, Only VIP Acess the Menu !")
		end
	end
end

addhook("menu","b")
function b(id,t,b)
	if t == "Test" then 
		if b == 1 then
			msg("123")
		elseif b == 2 then
			msg("1234")
		elseif b == 3 then
			msg("12345")
		end
	end
end

addhook("say","c") 
function c(id,t
		if vip[id] == 1 then 
			if t == "!on"
			msg("©255255255 VIP : "..player(id,"name").." ON.")
		else
			msg2(id,"©255255255 Error, Commands Only to Vips")
			return 1
		end
	end
end
edited 1×, last 09.11.14 07:14:42 pm

old Re: ADD & REMOVE VIP

Suprise
BANNED Off Offline

Quote
I tab'd it if you don't mind
And changed some things in it.

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
addhook("serveraction","_action")
function _action(id,action)
	if action == 1 then
		if vip[id] == 1 then
			menu(id,"Test,A,B,C") -- THE MENU
		else
			   --It's pointless to put Error text, in my opinon.
		end
	end
end

addhook("menu","_menu")
function _menu(id,title,button)
	if title == "Test" then -- TITTLE OF MENU
		if button == 1 then -- B = BUTTONS IN MENU
			msg("123") --You can use menu(id,"Test2") too!
		elseif button == 2 then
			msg("1234")
		elseif button == 3 then
			msg("12345")
		end
	end
end

addhook("say","_say")
function _say(id,t)
	if t == "!on" then
		if vip[id] == 1 then
			msg("©255255255"..player(id,"name").." |VIP| "..txt)
			return 1
		else
			msg2(id,"©255255255This command is only for Vip/Admin!")
		end
	end
end

old Re: ADD & REMOVE VIP

SektoR_
User Off Offline

Quote
@user Suprise - @user Gaios: When executed, this error appears: [...]:861: attempt to call field 'open' (a nil value)

The 861 line is this:
1
local file = io.open("sys/lua/OCP 2.0/OCP config/"..usgn..".txt","r")

What to do?

old Re: ADD & REMOVE VIP

sheeL
User Playing CS2D

Quote
user SektoR_ has written
@user Suprise - @user Gaios: When executed, this error appears: [...]:861: attempt to call field 'open' (a nil value)

The 861 line is this:
1
local file = io.open("sys/lua/OCP 2.0/OCP config/"..usgn..".txt","r")

What to do?


Post the Script complete...

old Re: ADD & REMOVE VIP

SektoR_
User Off Offline

Quote
user sheeL has written
user SektoR_ has written
@user Suprise - @user Gaios: When executed, this error appears: [...]:861: attempt to call field 'open' (a nil value)

The 861 line is this:
1
local file = io.open("sys/lua/OCP 2.0/OCP config/"..usgn..".txt","r")

What to do?


Post the Script complete...


Look there!
Recalling that is giving the error on line 33.

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
list_adm = {00000}


--                   ADM

function ADMS(id)
	for _, usgn in ipairs(list_adm) do
		if (player(id,"usgn") == usgn) then
			return true
		end
	end
	return false
end


--                  ARRAY

function initArray(m)
local array = {}
	for i = 1, m do array[i]=0
	end
return array
end


--                   CODE

vip = initArray(32,0)

function LoadAccount(id)
     local usgn = player(id,"usgn")
     if usgn > 0 then
          local file = io.open("sys/lua/OCP 2.0/OCP config/"..usgn..".txt","r") -- Line error.
          if file then
               vip[id] = tonumber(file:read());
          end
     end
end

function SaveAccount(id,level)
     local usgn = player(id,"usgn")
     if usgn > 0 then
          local file = io.open("sys/lua/OCP 2.0/OCP config/"..usgn..".txt","w")
          file:write(level)
          file:close()
     end
end

addhook("join","_joinHook")
function _joinHook(id)
     vip[id] = 0
     LoadAccount(id)
     if vip[id] == 1 then
          msg2(id,"©000255000You are VIP!@C")
     end
end

addhook("say","_sayHook")
function _sayHook(id,txt)
		if ADMS(id) then
	for pl = 1,32 do
          if txt == "!addvip "..pl.."" then
               if vip[pl] == 0 then
                    vip[pl] = 1
                    SaveAccount(pl,1)
                    msg2(pl,"©255255255You're now VIP!")
                    return 1
               else
                    msg2(id,"©255000000Error: The player you wanted to add is already VIP!")
               end
          elseif txt == "!removevip "..pl.."" then
               if vip[pl] == 1 then
                    vip[pl] = 0
                    SaveAccount(pl,0)
                    msg2(pl,"©255255255Your vip status has been removed!")
                    return 1
               else
                    msg2(id,"©255000000Error: This guy is NOT VIP!")
               end
          end
     end
	 end -- if ADMS
end
edited 1×, last 16.10.12 04:20:29 am

old Re: ADD & REMOVE VIP

Gaios
Reviewer Off Offline

Quote
Spoiler >


Maybe, you dont have folder OCP 2.0 and OCP Config.
When I am going to computer, then I fix the bug.

old Re: ADD & REMOVE VIP

SektoR_
User Off Offline

Quote
user Gaios has written
Spoiler >


Maybe, you dont have folder OCP 2.0 and OCP Config.
When I am going to computer, then I fix the bug.


But I created the folder!
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview