Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Scripts/Questions/Help

6,770 replies
Page
To the start Previous 1 236 37 38338 339 Next To the start

old Help me!!!

Nigga Jesus
User Off Offline

Quote
I need to make a "keys" (that is, front door keys, lock keys, that sort of keys, etc) system for my server in the lua. I know it must have something to do with parse("trigger"..house1.."") and something to do with saving a file, or something like that however how do i do it! btw i need it ready to copy-paste because when i put lua codes in or when i edit lua codes such as the samples, it says that its missing a bracket at a place i havent touched/isnt missing a single bracket! PLEASE PLEASE PREETY PLEASE!!! Ill give them my anti zombie/terrorists fortress map...

old Re: Lua Scripts/Questions/Help

PlayerNoob
User Off Offline

Quote
Does Anyone know how to make the command

"!broadcast" work?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("say","say1")
function say1(id,txt)

	if (player(id,"usgn")==1) then

	elseif (player(id,"usgn")==7079) then
	msg("©000000255"..player(id,"name").." (ADMIN): "..txt.."")
	
	elseif (player(txt)=="!broadcast") then
	msg("©000255000"..player(id,"name")..":"..txt.."")


return 1
end
end

above code does not work...




EDIT:
Also, how do you make a timer for it?
and... how to saycenter......
and...how to make this command...


1
2
if (txt=="!freeze") then parse ("speedmod"..p..)
	if (txt=="!makect") then parse ("makect"..p..)
--So, you can freeze yourself
--so you can forget about the 1 change team per round...
edited 2×, last 08.08.09 06:16:47 pm

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
PlayerNoob has written
Does Anyone know how to make the command

"!broadcast" work?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("say","say1")
function say1(id,txt)

	if (player(id,"usgn")==1) then

	elseif (player(id,"usgn")==7079) then
	msg("©000000255"..player(id,"name").." (ADMIN): "..txt.."")
	
	elseif (player(txt)=="!broadcast") then
	msg("©000255000"..player(id,"name")..":"..txt.."")


return 1
end
end


Your best bet right now is to just use the !broadcast capability in amx2d, otherwise you'll have to write a whole suite of helper functions to get it up and working.

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
!register urname urpassword
!login admin pass
@authset urname superadmin
@logout
!login urname urpassword

old Re: Lua Scripts/Questions/Help

-0nyX-
User Off Offline

Quote
Flacko has written
This is a basic VIP-MOD-ADMIN script.
To make it work, you should create a .txt file in CS2D folder and change the variable "usersfiledir_" to the path to your file.
This is how the user database should look (Users can register anyways):

Quote
[USGNID#] [PRIVILEGE] [COLOR] [AUTOSAY ON/OFF] [USERNAME]

USGNID#: USGN ID number of player, this is required to log in
PRIVILEGE: 1=Vip; 2=Mod; 3=Admin;
COLOR: Chatting color...
AUTOSAY ON/OFF: If it's 1, the player talks as a VIP/MOD/ADMIN, otherwise, it talks like a normal player.
USERNAME: Optional, not important


Here's the code:

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
if flacko==nil then flacko={} end
flacko.admins={}

usersfiledir_="sys/lua/flacko/database/users.txt"

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

function clearfile(filedir)
	local clear = assert(io.open(filedir,"w"))
	clear:write()
	clear:close()
end

function flacko.admins.message(color,txt,center) 
	if(center==0) then
		parse("msg ©"..color..txt)

	elseif(center==1) then
		parse("msg ©"..color..txt.."@C")
	end
	--PARAMETERS: 1-RGB| 2-Text| 3-Centered?
end

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

function flacko.admins.savedata(filedir,id)
	if(flacko.admins.loggedin[id] and player(id,"usgn")>0) then
		local usgn = player(id,"usgn")
	
		local file = assert(io.open(filedir,"r"))
		database = file:read("*all")
		file:close()
		
		local linestable = {}
		local count = 0
		for line in database:lines() do
			linestable[count] = line
		end
			
		local wordsinline = toTable(linestable[flacko.admins.usernumber[id]])
	
		if(linestable[flacko.admins.usernumber[id]]~=nil) then
			clearfile(filedir)
	
			local appendrewrite = assert(io.open(filedir,"a"))
			for i=1,#linestable do
				if(i+1~=flacko.admins.usernumber[id]) then
					appendrewrite:write(linestable[i],"\n")
				elseif (i+1 == flacko.admins.usernumber[id]) then
					appendrewrite:write(usgn," ",flacko.admins.playerpower[id]," ",flacko.admins.colors[id]," ",flacko.admins.autosay[id]," ",flacko.admins.loggedin[id],"\n")
				end
			end
			appendrewrite:close()
			return 1
		else
		print("ERROR WHILE SAVING DATA!")
		return nil
		end
	end
end

function loginuser(filedir,id)
	local usgn = player(id,"usgn")
	counter = 1
	for line in io.lines(filedir) do
		local parses = toTable(line)
		counter = counter+1
		if (tonumber(parses[1])==usgn) then
			flacko.admins.playerpower[id] = tonumber(parses[2])
			flacko.admins.colors[id] = parses[3]
			flacko.admins.autosay[id] = tonumber(parses[4])
			parse("sv_msg2 "..id.." Logged in as "..parses[5])
			flacko.admins.loggedin[id]=parses[5]
			flacko.admins.usernumber[id] = counter
			break
		end
	end
end

function flacko.admins.help1menu(id)
	menu(id,"Help #1,War Machine,Ninja,Calibur,Bomber,Sniper,Engineer,Commander")
end

flacko.admins.playerpower = initArray(32,0)
flacko.admins.colors = initArray(32,"050150255")
flacko.admins.autosay = initArray(32,0)
flacko.admins.usernumber = initArray(32,0)
flacko.admins.loggedin = initArray(32,nil)

addhook("say","flacko.admins.say")
function flacko.admins.say(id,txt)


	if(string.sub(txt,0,1)=="!") then
		local text = toTable(txt)
		
		if(text[1]=="!login") then --Logs in with user
			if(player(id,"usgn")>0) then
				loginuser(usersfiledir_,id)
				return 1
			end
		end
		
		if(text[1]=="!changecolor") then --Changecolor(Vip,Mod,Admin)
			if(flacko.admins.playerpower[id]>0) then
				flacko.admins.colors[id]= text[2]
				if(string.len(flacko.admins.colors[id])~=9) then
					flacko.admins.colors[id]=000255000
				end
				if(flacko.admins.colors[id]==nil) then
					flacko.admins.colors[id] = 000255000
				end
				return 1
			end
		end
		
		if(text[1]=="!restart") then --Restart(Mod,Admin)
			if(flacko.admins.playerpower[id]>1) then
				parse("restart")
				return 1
			end
		end

		if(text[1]=="!register") then --Register a new user
			if(player(id,"usgn")>0 and text[2]) then
				local usgnid = player(id,"usgn")
				local fid = assert(io.open("sys/lua/flacko/database/users.txt","a"))
				if(fid~=nil) then
					fid:write(usgnid," 1 128128128 1 ",text[2],"\n")
					fid:close()
					parse("sv_msg2 "..id.." User '"..text[2].."' created!")
				end
				return 1
			end
		end			
			
		if(text[1]== "!say") then --Toggle autosay(VIP,MOD and ADMIN)
			if(flacko.admins.playerpower[id]>0) then
				if(flacko.admins.autosay[id]==0) then
					flacko.admins.autosay[id] = 1
				elseif(flacko.admins.autosay[id]==1) then
					flacko.admins.autosay[id] = 0
				end
				return 1
			end
		end
		
		if(text[1]=="!byteam") then
			if(flacko.admins.playerpower[id]>1) then
				for i=1,32 do
					if(player(i,"exists")) then
						local name = player(i,"name")
						local nlength1 = string.len(text[2])
						
						if text[3] then
							local nlength2 = string.len(text[3])
						end
						
						if(string.sub(name,0,nlength1) == text[2]) then
							parse("maket "..i)
						
						elseif(string.sub(name,0,nlength2) == text[3]) then
							parse("makect "..i)
						end
					end
				end
				return 1
			end
		end		
		
		if(text[1]=="!swapteams") then --Invert teams (Mods & Admins)
			if(flacko.admins.playerpower[id]>1) then
				for i=1,32 do
					if(player(i,"team")==1) then
						parse("makect "..i)
				
					elseif(player(i,"team")==2) then
						parse("maket "..i)
					end
				end
				return 1
			end
		end
		
		if(text[1]=="!ban") then
			if(flacko.admins.playerpower[id]==3) then -- Banname (Admin)
				flacko.admins.message("000255255",player(id,"name").." has banned "..player(text[2],"name"),0)
				parse("banname "..text[2])
				return 1
			end
		end
			
		if(text[1]=="!changeteam") then --Change team (Mod & Admin)
			if(flacko.admins.playerpower[id]>1) then
				if(text[3]=="1") then
					parse("maket "..text[2])
				elseif(text[3]=="2") then
					parse("makect "..text[2])
				elseif(text[3]=="3") then
					parse("makespec "..text[2])
				end
				return 1
			end
		end
		
		if(text[1]=="!kick") then --Kick (Mods and Admins)
			if(flacko.admins.playerpower[id]>1) then
				flacko.admins.message("000255255",player(id,"name").." has kicked "..player(text[2],"name"),0)
				parse("kick "..text[2])
			end
			return 1
		end
		
		if(text[1]=="!save") then --Saves data
			flacko.admins.savedata(usersfiledir_,id)
			if(flacko.admins.savedata(usersfiledir_,id)==1) then
				parse("sv_msg2 "..id.." Saved!")
				return 1
			end
		end
		
		if(text[1]=="!map") then --Change map (Admins only)
			if(flacko.admins.playerpower[id]==3) then
				message = string.gsub(txt,"!map ","")
				parse("sv_map "..message)
			end
		end
	end
	
	if(flacko.admins.autosay[id]==1) then
		if(flacko.admins.playerpower[id]==2) then
			flacko.admins.message(flacko.admins.colors[id],player(id,"name").."(MOD): "..txt,0)
			return 1
		elseif(flacko.admins.playerpower[id]==3) then
			flacko.admins.message(flacko.admins.colors[id],player(id,"name").."(ADMIN): "..txt,0)
			return 1
		elseif(flacko.admins.playerpower[id]==1) then
			flacko.admins.message(flacko.admins.colors[id],player(id,"name").."(VIP): "..txt,0)
			return 1
		end
	end
end

addhook("leave","flacko.admins.leave")
function flacko.admins.leave(id)
	flacko.admins.savedata(usersfiledir_,id)
	flacko.admins.playerpower[id] = 0
	flacko.admins.colors[id]= "050150255"
	flacko.admins.autosay[id] = 0
	flacko.admins.usernumber[id] = 0
	flacko.admins.loggedin[id]=nil
end

addhook("join","flacko.admins.join")
function flacko.admins.join(id)
	if(player(id,"usgn")>0) then
		loginuser(usersfiledir_,id)
	end
end


Im having trouble understanding how to properly use this script. Ive used some scripts on my server and know how to install them properly but this particular script is a little to complicated for my brain power.
Any help will be greatly appreciated!
Reply please ASAP.

old Re: Lua Scripts/Questions/Help

Vibhor
User Off Offline

Quote
First thing i wanna ask is that how to install wc3 script
and second if i use mods then will i be able to join server and how will i look

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Vibhor has written
First thing i wanna ask is that how to install wc3 script
and second if i use mods then will i be able to join server and how will i look

If you are using mod and joining some other server...
It wont give you anything. Lua scripts only for hoster side.

Anyway instalation:
Download zip and extract it in cs2d folder

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Onyx
I wouldn't suggest to use my script, it's very unstable.
I provided it to help people that might need help writing their own script.

old Re: Lua Scripts/Questions/Help

-0nyX-
User Off Offline

Quote
Flacko has written
@Onyx
I wouldn't suggest to use my script, it's very unstable.
I provided it to help people that might need help writing their own script.


Then is there any other lua scriot like that with the abillities to have colored text, auto say, etc? Ive had no luck finding any quite like the one I saw. Or even the one thats on LaG and TGV Servers.
To the start Previous 1 236 37 38338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview