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 212 13 14338 339 Next To the start

old Re: Lua Scripts/Questions/Help

DC
Admin Off Offline

Quote
no. function parameters are NOT global of course.
moreover "function sample.ads.join(id,id)" is nonsense. you use the same variable twice.

sample for a global variable in your code:
1
sample.ads.myglobal=5


and once again: you shouldn't use sample.xxx.yyy! you should rename it. for example vrkiller.xxx

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
I need help about infinive ammo.
Couse I dont know if possible to make it for one id.
So its possible? And how?

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
vrkiller has written
why do it not work for me

I don't know whats going on with the join script, but If you wanted, when player says "speedmodon" to get speed and "speedmodoff" to be normal, here you go:

1
2
3
4
5
6
7
8
9
10
addhook("say","player_say")
function player_say(id,txt)
	if(txt=="speedmodon") then
		parse("speedmod "..id.." 100")
		msg("DOOOMMMEdddd!")
	elseif(txt=="speedmodoff") then
		parse("speedmod "..id.." 0")
		msg("DOOOMMMEdddd!")
	end
end

old Re: Lua Scripts/Questions/Help

wups
User Off Offline

Quote
Isn't this method much better then on/off?

1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("say","say1")
function say1(p,t) 
if (t=="!speed") then
	
	if (player(p,"speedmod") > 0) then
		parse("speedmod "..p.." 0")
		msg2(p, "You can now run normal!")
	else 
		parse("speedmod "..p.." 40")
		msg2(p, "You can now run faster!")
	end
end
end

old Re: Lua Scripts/Questions/Help

Somaz
User Off Offline

Quote
Quote
How to make bots stay in team after round restart (in tt)? Because they always balance, even without mp_teambalance 1.


I think something like this should do:

1
2
3
4
5
6
7
8
addhook("team","botcheck")
function botcheck(id, team)
	if player(id,"bot")==true then
		if team==2 then
			return 1
		end
	end
end

This should prevent the bots from ever joining CT.

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
I need a script:
If a player says !pay , he must say the ID and NUMBER he wants money to be transfered.
Example

Player1:
!pay 2 120
(player 1 would loose 120$)

Player2: (you got money from player "name")
gets 120$

old Re: Lua Scripts/Questions/Help

Silent_Control
User Off Offline

Quote
wups has written
Hmm, why does this thread looks more like a request thread this days, instead of a help/question thread.


Because people really need help with Lua :). Help is a request.

old Re: Lua Scripts/Questions/Help

RAVENOUS
BANNED Off Offline

Quote
Admirdee has written
Skipper has written
Where does the SPY in classes.lua get the Stealth Suit from?!


it get from script


IT'S NECESSARY

edit: No, i mean where in the script.

old Re: Lua Scripts/Questions/Help

Alpha Beta
User Off Offline

Quote
Skipper has written
Admirdee has written
Skipper has written
Where does the SPY in classes.lua get the Stealth Suit from?!


it get from script


IT'S NECESSARY

edit: No, i mean where in the script.

At this line:
1
parse ("setarmor "..id.." 206")

old Re: Lua Scripts/Questions/Help

RAVENOUS
BANNED Off Offline

Quote
okay, new problem.

This lua-script doesn't work, but I don't know why.

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
-----------------------
-- INITIAL SETUP     --
-----------------------
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
sample.classes.class=initArray(32)
function sample.classes.classmenu(id)
	menu(id,"Select your Class,Soldat|M4A1+HE,Spion|Unsichtbarkeit,Arbeiter|Kann bauen,Aufklärer|Scout+M3,Attentäter|Granaten,Arzt|Heilen")	
end


-----------------------
-- TEAM -> CLASS     --
-----------------------
addhook("team","sample.classes.team")
function sample.classes.team(id,team)
	if (team>0) then
		sample.classes.classmenu(id)
	end
end


-----------------------
-- SERVERACTION      --
-----------------------
addhook("serveraction","sample.classes.serveraction")
function sample.classes.serveraction(id)
	sample.classes.classmenu(id)
end


-----------------------
-- CLASS SELECTION   --
-----------------------
addhook("menu","sample.classes.menu")
function sample.classes.menu(id,menu,sel)
	if (menu=="Select your Class") then
		if (sel>=0 and sel<=6) then
			sample.classes.class[id]=sel
			if (player(id,"health")>0) then
				parse("killplayer "..id)
			end
		end
	end
end


-----------------------
-- SPAWN             --
-----------------------
addhook("spawn","sample.classes.spawn")
function sample.classes.spawn(id)
	-- Soldat
	if (sample.classes.class[id]<=1) then
		parse ("setmaxhealth "..id.." 150")
		parse ("setarmor "..id.." 100")
		parse ("speedmod "..id.." -1")
		return "32,1,51";
	end
	-- Spion
	if (sample.classes.class[id]==2) then
		parse ("setmaxhealth "..id.." 100")
		parse ("setarmor "..id.." 206")
		parse ("speedmod "..id.." 5")
		return "21,1";
	end
	-- Arbeiter
	if (sample.classes.class[id]==3) then
		parse ("setmaxhealth "..id.." 100")
		parse ("setarmor "..id.." 50")
		return "10,2,74";
	end
	-- Aufklärer
	if (sample.classes.class[id]==4) then
		parse ("setmaxhealth "..id.." 75")
		parse ("setarmor "..id.." 203")
		return "10,34,53";
	end
	-- Attentäter
	if (sample.classes.class[id]==5) then
		parse ("setmaxhealth "..id.." 75")
		parse ("setarmor "..id.." 0")
		parse ("speedmod "..id.." 15")
		return "4,51,72,73,76,69";
	end
	-- Arzt
	if (sample.classes.class[id]==6) then
		parse ("setmaxhealth "..id.." 125")
		parse ("setarmor "..id.." 204")
                msg2(id,"©255255255Use Claw to heals you friend!@C")
		return "78,20,52";
	end
end


-----------------------------
-- MEDIC WEAPON --
-----------------------------
addhook("hit","claw_heal")
function claw_heal(id,source,weapon,hpdmg,apdmg)
	if(weapon == 78) then
	parse ("sethealth "..id.." "..player(id,"health")+10) 
	end
end


-----------------------
-- NO BUYING         --
-----------------------
addhook("buy","sample.classes.buy")
function sample.classes.buy()
	return 1
end


-----------------------
-- NO COLLECTING     --
-----------------------
addhook("walkover","sample.classes.walkover")
function sample.classes.walkover(id,iid,type)
	if (type>=61 and type<=68) then
		return 0
	end
	return 1
end


-----------------------
-- NO DROPPING       --
-----------------------
addhook("drop","sample.classes.drop")
function sample.classes.drop()
	return 1
end


-----------------------
-- NO DEAD DROPPING  --
-----------------------
addhook("die","sample.classes.die")
function sample.classes.die()
	return 1
end

Please help me!!!111one
edited 3×, last 11.06.09 10:04:16 pm

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
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
To the start Previous 1 212 13 14338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview