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 2331 332 333338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Yasday
User Off Offline

Quote
1
rcon lua "table.insert(admins,THE-USGN)"

use this with rcon
THE-USGN should be the usgn

edit:
io.open("blabla.txt","a")
with the param "a" it will automatically write the text at the end of the file.

edit2:
yeah sry forgot that
edited 1×, last 22.12.10 10:10:31 pm

old Re: Lua Scripts/Questions/Help

DannyDeth
User Off Offline

Quote
@Yasday:
Actually it writes at the End-of-file character, if there is no new-line character before it it will write onto the same line which will cause errors.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
What do you exactly mean by "byte code reading"?
Probably you don't really know what you're asking.

Byte is simply used as ASCII char from 0 to 255.
I've made some int to char saving functions old time ago. (Code is bellow)
Of course, I recommend to use Lee's reminiscent blitz functions.
I guess you still can find them in early pages of this thread.

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
function WriteInt(Stream,Int)
	local ByteStr = tostring(Int)
	local Byte0 = string.len(ByteStr)
	local i
	Stream:write(string.char(Byte0))
	for i = 1, Byte0, 1 do
		Stream:write(string.char(string.sub(ByteStr,i,i)+1))
	end
end

function ReadInt(StreamString)
	local Stream = _G[StreamString]
	local Byte0 = tonumber(string.byte(string.sub(Stream,1,1)))
	local Int = tonumber(ByteToString(string.sub(Stream,2,Byte0 + 1)))
	_G[StreamString] = string.sub(Stream,Byte0 + 2)
	return(Int)
end

function ByteToString(String)
	local Slice
	local Str = ""
	for Slice = 1, string.len(String), 1 do
		Str = Str..tonumber(string.byte(string.sub(String,Slice,Slice))) - 1
	end
	return(Str)
end
edited 1×, last 23.12.10 12:09:14 am

old Re: Lua Scripts/Questions/Help

shironeko
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
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
yourmon = {}
use = 1
first = {}
copyright=string.char(169)

addhook ("spawn","span")
function span(id)

if yourmon[id]==nil then
yourmon[id] = 0
end

if first[id] == nil then
first[id] = 111111
if (io.open("user/"..player(id,"usgn")..".txt")~=nil) then
msg2 (id,""..copyright.."000255000Loaded!")
for l in io.lines("user/"..player(id,"usgn")..".txt") do
mof = tonumber(l)
if mof ~=nil then
yourmon[id] = mof
end
end


else
msg2 (id,""..copyright.."255000000Sorry, no savefile found!")
end

end
end


addhook ("serveraction","ser")
function ser(id,ac)
if (ac==1 and use==1) then
goldmenu(id)
end
end

function goldmenu(id)
checkk = player(id,"money")+yourmon[id]
menu (id,"drop money,500,1000,5000,10000,50000,100000,200000,500000")
end



addhook ("menu","meno")
function meno(id,menu,sel)
if (menu=="drop money") then
if sel>=1 and sel<=9 then
goldmenu(id)
end
if yourmon[id]~= nil then
checkmonx = player(id,"money")+yourmon[id]
yourmon[id] = yourmon[id] + player(id,"money")
parse ("setmoney "..id.." 0")
else
checkmonx = ""
end


if sel==1 and checkmonx >=500 then
parse ("spawnitem 67 "..(player(id,"tilex")).." "..(player(id,"tiley")))
yourmon[id] = yourmon[id] - 500
end
if sel==2 and checkmonx >=1000 then
parse ("spawnitem 68 "..(player(id,"tilex")).." "..(player(id,"tiley")))
yourmon[id] = yourmon[id] - 1000
end
if sel==3 and checkmonx >=5000 then
yourmon[id] = yourmon[id] - 5000
for i=1,5 do
parse ("spawnitem 68 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end

if sel==4 and checkmonx >=10000 then
yourmon[id] = yourmon[id] - 10000
for i=1,10 do
parse ("spawnitem 68 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
if sel==5 and checkmonx >=50000 then
yourmon[id] = yourmon[id] - 50000
for i=1,50 do
parse ("spawnitem 68 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
if sel==6 and checkmonx >=100000 then
yourmon[id] = yourmon[id] - 100000
parse ("spawnitem 56 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
if sel==7 and checkmonx >=200000 then
yourmon[id] = yourmon[id] - 200000
parse ("spawnitem 56 "..(player(id,"tilex")).." "..(player(id,"tiley")))
parse ("spawnitem 56 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
end
end

if sel==8 and checkmonx >=500000 then
yourmon[id] = yourmon[id] - 500000
for i=1,5 do
parse ("spawnitem 56 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
end
end
end




addhook ("join","jo")
function jo(id)
yourmon[id] = 0
end



addhook ("second","sec")
function sec()
for id=1,32 do
if(player(id,"exists")) then

if yourmon[id] ~= nil then
hud(id)
checkk = player(id,"money")+yourmon[id]
if checkk~=nil and checkk<10000 then
yourmon[id] = 0
parse ("setmoney "..id.." "..checkk)
hud(id)
end
end




if (player(id,"money")>10000) then
chec = player(id,"money") - 10000
parse ("setmoney "..id.." "..(player(id,"money")-chec))
yourmon[id] = yourmon[id] + chec
end

if(player(id,"money")<10000) then
chec = 10000 - player(id,"money")
if yourmon[id]~=nil then
if yourmon[id] >=chec then
yourmon[id] = yourmon[id] - chec
parse ("setmoney "..id.." "..(player(id,"money")+chec))
hud(id)
end
end
end
end
end
end


function hud(id)
txt = (""..copyright.."000255000Money(+10000):"..yourmon[id].."$")
x = 15
y = 430
idd = 15
parse('hudtxt2 '..id..' '..idd..' "'..txt..'" '..x..' '..y)
end

addhook ("walkover","walken")
function walken(id,iid,type,ain,a,mode)

if (type==66) then
if player(id,"money")>=100 then
yourmon[id] = yourmon[id] + 100
parse ("setmoney "..id.." "..player(id,"money")-100)
end
elseif (type==67) then
if player(id,"money")>=500 then
yourmon[id] = yourmon[id] + 500
parse ("setmoney "..id.." "..player(id,"money")-500)
end
elseif (type==68) then
if player(id,"money")>=1000 then
yourmon[id] = yourmon[id] + 1000
parse ("setmoney "..id.." "..player(id,"money")-1000)
end
end

end

addhook ("leave","left")
function left(id)
yourmon[id] = 0
first[id] = nil
end


addhook ("say","sages")
function sages(id,txt)
if txt=="!save" then
yourmon[id] = yourmon[id] + player(id,"money")
parse ("setmoney "..id.." 0")
io.output(io.open("user/"..player(id,"usgn")..".txt","w+"))
io.write(yourmon[id])
io.close()
msg2 (id,""..copyright.."000255000Saved!@C")
end
end

addhook ("minute","min")
function min()
for id=1,32 do
if player(id,"exists") then
yourmon[id] = yourmon[id] + player(id,"money")
parse ("setmoney "..id.." 11000")
io.output(io.open("user/"..player(id,"usgn")..".txt","w+"))
io.write(yourmon[id])
io.close()
end
end
hud(id)
end

addhook("die","classesoptdie")
function classesoptdie()
     return 1
end
how repair this lua???
it say '<eof>' expected near 'end'
and who can give me !rp_admin lua?

old Re: Lua Scripts/Questions/Help

J4x
User Off Offline

Quote
<eof> means end of file... i think this should work
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
yourmon = {}
use = 1
first = {}
copyright=string.char(169)

addhook ("spawn","span")
function span(id)

if yourmon[id]==nil then
yourmon[id] = 0
end

if first[id] == nil then
first[id] = 111111
if (io.open("user/"..player(id,"usgn")..".txt")~=nil) then
msg2 (id,""..copyright.."000255000Loaded!")
for l in io.lines("user/"..player(id,"usgn")..".txt") do
mof = tonumber(l)
if mof ~=nil then
yourmon[id] = mof
end
end


else
msg2 (id,""..copyright.."255000000Sorry, no savefile found!")
end

end
end


addhook ("serveraction","ser")
function ser(id,ac)
if (ac==1 and use==1) then
goldmenu(id)
end
end

function goldmenu(id)
checkk = player(id,"money")+yourmon[id]
menu (id,"drop money,500,1000,5000,10000,50000,100000,200000,500000")
end



addhook ("menu","meno")
function meno(id,menu,sel)
if (menu=="drop money") then
if sel>=1 and sel<=9 then
goldmenu(id)
end
if yourmon[id]~= nil then
checkmonx = player(id,"money")+yourmon[id]
yourmon[id] = yourmon[id] + player(id,"money")
parse ("setmoney "..id.." 0")
else
checkmonx = ""
end


if sel==1 and checkmonx >=500 then
parse ("spawnitem 67 "..(player(id,"tilex")).." "..(player(id,"tiley")))
yourmon[id] = yourmon[id] - 500
end
if sel==2 and checkmonx >=1000 then
parse ("spawnitem 68 "..(player(id,"tilex")).." "..(player(id,"tiley")))
yourmon[id] = yourmon[id] - 1000
end
if sel==3 and checkmonx >=5000 then
yourmon[id] = yourmon[id] - 5000
for i=1,5 do
parse ("spawnitem 68 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end

if sel==4 and checkmonx >=10000 then
yourmon[id] = yourmon[id] - 10000
for i=1,10 do
parse ("spawnitem 68 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
if sel==5 and checkmonx >=50000 then
yourmon[id] = yourmon[id] - 50000
for i=1,50 do
parse ("spawnitem 68 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
if sel==6 and checkmonx >=100000 then
yourmon[id] = yourmon[id] - 100000
parse ("spawnitem 56 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
if sel==7 and checkmonx >=200000 then
yourmon[id] = yourmon[id] - 200000
parse ("spawnitem 56 "..(player(id,"tilex")).." "..(player(id,"tiley")))
parse ("spawnitem 56 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
end
end

if sel==8 and checkmonx >=500000 then
yourmon[id] = yourmon[id] - 500000
for i=1,5 do
parse ("spawnitem 56 "..(player(id,"tilex")).." "..(player(id,"tiley")))
end
end
end





addhook ("join","jo")
function jo(id)
yourmon[id] = 0
end



addhook ("second","sec")
function sec()
for id=1,32 do
if(player(id,"exists")) then

if yourmon[id] ~= nil then
hud(id)
checkk = player(id,"money")+yourmon[id]
if checkk~=nil and checkk<10000 then
yourmon[id] = 0
parse ("setmoney "..id.." "..checkk)
hud(id)
end
end




if (player(id,"money")>10000) then
chec = player(id,"money") - 10000
parse ("setmoney "..id.." "..(player(id,"money")-chec))
yourmon[id] = yourmon[id] + chec
end

if(player(id,"money")<10000) then
chec = 10000 - player(id,"money")
if yourmon[id]~=nil then
if yourmon[id] >=chec then
yourmon[id] = yourmon[id] - chec
parse ("setmoney "..id.." "..(player(id,"money")+chec))
hud(id)
end
end
end



function hud(id)
txt = (""..copyright.."000255000Money(+10000):"..yourmon[id].."$")
x = 15
y = 430
idd = 15
parse('hudtxt2 '..id..' '..idd..' "'..txt..'" '..x..' '..y)
end

addhook ("walkover","walken")
function walken(id,iid,type,ain,a,mode)

if (type==66) then
if player(id,"money")>=100 then
yourmon[id] = yourmon[id] + 100
parse ("setmoney "..id.." "..player(id,"money")-100)
end
elseif (type==67) then
if player(id,"money")>=500 then
yourmon[id] = yourmon[id] + 500
parse ("setmoney "..id.." "..player(id,"money")-500)
end
elseif (type==68) then
if player(id,"money")>=1000 then
yourmon[id] = yourmon[id] + 1000
parse ("setmoney "..id.." "..player(id,"money")-1000)
end
end

end

addhook ("leave","left")
function left(id)
yourmon[id] = 0
first[id] = nil
end


addhook ("say","sages")
function sages(id,txt)
if txt=="!save" then
yourmon[id] = yourmon[id] + player(id,"money")
parse ("setmoney "..id.." 0")
io.output(io.open("user/"..player(id,"usgn")..".txt","w+"))
io.write(yourmon[id])
io.close()
msg2 (id,""..copyright.."000255000Saved!@C")
end
end

addhook ("minute","min")
function min()
for id=1,32 do
if player(id,"exists") then
yourmon[id] = yourmon[id] + player(id,"money")
parse ("setmoney "..id.." 11000")
io.output(io.open("user/"..player(id,"usgn")..".txt","w+"))
io.write(yourmon[id])
io.close()
end
end
hud(id)
end

addhook("die","classesoptdie")
function classesoptdie()
return 1
end

old closed Re: Lua Scripts/Questions/Help

shironeko
User Off Offline

Quote
OMG...First Try can but SECOND Try failed
*Same Error*

Admin/mod comment

Don't quote posts when they're directly above yours. /TheKilledDeath

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
@The_Flame

Your code is really ugly...

This is what I have made of your code
Spoiler >

old Re: Lua Scripts/Questions/Help

RyceR
User Off Offline

Quote
How to make it:
On roundend is music...
When music is not finished and there is new music, this 1 is stoped.
My code:
1
2
3
4
5
6
7
8
9
addhook("endround","win")
function win()
	parse("sv_sound eXpunge_roundsounds/end"..math.random(1,13)..".wav")
end

addhook("join","winn")
function winn(id)
	parse("sv_sound2 "..id.." eXpunge_roundsounds/start.wav")
end
plz help me!
edited 1×, last 23.12.10 12:08:01 pm

old Re: Lua Scripts/Questions/Help

Casper-
User Off Offline

Quote
BureX has written
1
2
3
4
5
6
7
8
9
10
addhook("ai_goto","zmgo")
function zmgo(id,x,y)
[and i should write here other stuff (which i dont know)]
end

or

addhook("ai_goto","zmgo")
function zmgo(id,32,64)
end


Can i make "ai_goto" more of them ? like every random bot goes to random "ai_goto" and starts to attack when destination is reached ?

old Re: Lua Scripts/Questions/Help

DannyDeth
User Off Offline

Quote
Burex stop pushing that fucking question all the time! Seriously

@Rycer:
It's because the math.random function return an integer not a character!

@Yamato4147:
1
2
3
4
5
6
7
8
9
10
addhook("buildattempt","barricade_build")
function barricade_build(id,type)
	if (type=="barricade") then
		if (player(id,"team")==2) then
			return 0
		else
			return 1
		end
	end
end
I think that will work fine

old Re: Lua Scripts/Questions/Help

Yasday
User Off Offline

Quote
@DannyDeth
1
2
3
4
5
6
7
8
addhook("buildattempt","barricade_build")
function barricade_build(id,type)
	if type == 1 then
		if not player(id,"team") == 2 then
			return 1
		end
	end
end

type is a number value

old Re: Lua Scripts/Questions/Help

Rainoth
Moderator Off Offline

Quote
Hello could anyone explain me about timers and make an example. I think timer will call function after some time. But what are numbers 9000 100 5000 beforei it ? Please give example. I have an idea of something like speedpotion. When you buy it you get speed 50 and after some time (timer here) your speed becomes 0 again... Thank you for your help

old Re: Lua Scripts/Questions/Help

Yasday
User Off Offline

Quote
1
timer(1000,"msg","HEY!") --msg with hey after 1 sec

timer(time in millisecs,function,params)

edit:

1
2
3
4
5
6
function speeddown(id)
	id = tonumber(id)
	parse([[speedmod ]]..id..[[ 0]])
end

timer(25000,"speeddown",id) --after 25 secs call speeddown
edited 1×, last 23.12.10 01:04:54 pm

old Re: Lua Scripts/Questions/Help

RyceR
User Off Offline

Quote
RyceR has written
How to make it:
On roundend is music...
When music is not finished and there is new music, this 1 is stoped.
My code:
1
2
3
4
5
6
7
8
9
addhook("endround","win")
function win()
	parse("sv_sound eXpunge_roundsounds/end"..math.random(1,13)..".wav")
end

addhook("join","winn")
function winn(id)
	parse("sv_sound2 "..id.." eXpunge_roundsounds/start.wav")
end

plz help me!

old Re: Lua Scripts/Questions/Help

DannyDeth
User Off Offline

Quote
Oh yeah I forgot *FACEPALM*
The names only work in mp_building_***
lolz...
So let me change that quickly:
1
2
3
4
5
6
7
8
9
10
addhook("buildattempt","barricade_build")
function barricade_build(id,type)
     if (type==1) then
          if (player(id,"team")==2) then
               return 0
          else
               return 1
          end
     end
end

@Batlaizys:
SO you want to make a speedpotion that lasts a certain time? It's not to hard, here is a simple demonstration:
1
2
3
4
5
6
7
8
9
10
function speed-potion(id)
	end-time = os.clock() + 5 -- The speed potion will last 5 seconds...
	parse("speedmod "..id.." 50") -- Make him fast...
	while True:
	if (os.clock==end-time) then
		parse("speedmod "..id.." 0")
	else
		-- Wait and do nothing...
	end
end
It's un tested, if there are any errors say so and i will correct them ASAP

EDIT: @Rycer:
Explain properly and I might be able to understand you, I cannot understand what you are trying to say
To the start Previous 1 2331 332 333338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview