Forum
Scripts
Lua Scripts/Questions/Helpthanks for the help! (did u insert the delay so the firballs disappear or not?)
as well, on a script i wrote, there is a bug saying :expecting 'eof' near end
i know what this error message is, but i dont know how to fix it... here is 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
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
--------------------------------------------------
-- UT+Quake Sounds Script by Unreal Software --
-- 22.02.2009 - www.UnrealSoftware.de --
-- Adds UT and Quake Sounds to your Server --
--------------------------------------------------
if sample==nil then sample={} end
sample.ut={}
-----------------------
-- INITIAL SETUP --
-----------------------
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
sample.ut.level=initArray(32)
sample.ut.fblood=0
-----------------------
-- PREPARE TO FIGHT! --
-----------------------
-- addhook("startround","sample.ut.startround")
-- function sample.ut.startround()
-- 	parse("sv_sound \"fun/prepare.wav\"")
-- 	sample.ut.fblood=0
-- end
-----------------------
-- KILL SOUNDS --
-----------------------
	level=sample.ut.level[killer]
	level=level+1
	sample.ut.level[killer]=level
	sample.ut.timer[killer]=os.clock()
	-- FIRST BLOOD?
	if (sample.ut.fblood==0) then
		sample.ut.fblood=1
		parse("sv_sound \"fun/firstblood.mp3\"");
	end
		if (level==1) then
			-- Single Kill! Nothing Special!
		elseif (level==3) then
			parse("sv_sound \"fun/multikill.mp3\"")
		elseif (level==5) then
			parse("sv_sound \"fun/killingspree.mp3\"")
		elseif (level==7) then
			parse("sv_sound \"fun/rampage.mp3\"")
		elseif (level==10) then
			parse("sv_sound \"fun/unstoppable.mp3\"")
		else
			parse("sv_sound \"fun/godlike.mp3\"")
		end
	end
end
im stumped...
edit: for some reason some lua scripts arent being executed when i launch cs2d even though i triple checked the path in the server.lua, any answers or previous threads (soz im too lazy to look around :P)
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
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
-- Flashlight by wUps
--
-- bind "f" "say admin"
--
function initArray(m)
	local array = {}
	for i = 1, m
	do array[i]=0
	end
		return array
end
light=initArray(32)
light01=initArray(32)
addhook("say","lightz3")
function lightz3(p3,t)
	if (t == "!cigarette") then	
		if (light01[p3] == 1) then
		 local team = player(id,"team")
elseif (team==2) then
			light01[p3]=0
			freeimage(light[p3])
		else
			light01[p3]=1
			light[p3]=image("gfx/--- soja ---/bike.bmp",1,1,200+p3)
			imageblend(light[p3],0)
			imagecolor(light[p3],255,255,255)
			imagealpha(light[p3],0.5)
		end
		return 1
	end
end
Anti has written
Lua holds absolute references to all variables that are passed, so by calling:
1
2
3
2
3
a = initArray(32, "o")
a[0] = "b"
--a === {"b"}*32
Lua will assign every element within the table to "b", however that's not even your problem (although you should look into this as it will cause unexpected behavior within your script)
Skip down all the way to see the final solution
It is logically flawed to place the entire sequence in a "startround" hook as this will cause unexpected behaviors in a non-normal match. Instead, replace the entire speed_mvs block with:
1
2
3
4
5
2
3
4
5
addhook("spawn","speed_spawn")
function speed_spawn(id)
	speed_mvs[id]=0
	speed22_mvs(id)
end
And while I hate to go around and spam this all over the place, if you really want more personalized help with Lua, go to http://cs2d.org/
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
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
-- Flashlight by wUps
--
-- bind "f" "say admin"
--
function initArray(m)
	local array = {}
	for i = 1, m
	do array[i]=0
	end
		return array
end
light=initArray(32)
light01=initArray(32)
addhook("say","lightz3")
function lightz3(p3,t)
	if (t == "!cigarette") then	
		if (light01[p3] == 1) then
		 local team = player(id,"team")
elseif (team==2) then
			light01[p3]=0
			freeimage(light[p3])
		else
			light01[p3]=1
			light[p3]=image("gfx/--- soja ---/bike.bmp",1,1,200+p3)
			imageblend(light[p3],0)
			imagecolor(light[p3],255,255,255)
			imagealpha(light[p3],0.5)
		end
		return 1
	end
end
N-B-K has written
There are too much information in the forum about that ;), or in the download section, just search and you'll see
gabpro has written
After answering it can anyone answer the following question?
I'd like to know how to save a variable in a document(.txt) and load it later,for example save the mod's money...
PS:LOL,I'm using tradutor too
I'd like to know how to save a variable in a document(.txt) and load it later,for example save the mod's money...
PS:LOL,I'm using tradutor too

There are too much information in the forum about that ;), or in the download section, just search and you'll see

I search and find,but it dont work =x
Have a error,but i dont understand how to save or load files with lua...
Can anyone help me how to save the variable X(leave) and load it after(join) in a .txt document or something?
Soja1997 has written
Find and replace
1
light[p3]=image("gfx/--- soja ---/bike.bmp",1,1,200+p3)
1
light[p3]=image("gfx/--- soja ---/bike.bmp",1,1,100+p3)
Also, please don't bump your questions, do it again and you will be banned.
1
imagealpha(light[p3],0.5)
Works Menu
Worker - 1000$/Minute
Miner - 2000$/Minute
Barman - 3000$/Minute
Soldier - 4000$/Minute
Doctor - 5000$/Minute
Dealer - 6000/Minute
Banker - 7000$/Minute
If admin say : give_work ID Worker
Miner,Barman,Solider,DOctor,Dealer,Banker etc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
addhook("minute","RPminute")
function RPminute()
local p = function(id)
if player(id,"exists") then return true end
return nil
end
local give = function(id,ammount)
msg2(id,"©150100255 Pay Day!@C")
msg2(id,"©150100255 Wyplata!@C")
addmoney(id, 5000)
end
for id=1,32 do
if p(id) then
give(id,5000)
end
end
end
edited 3×, last 01.05.10 04:36:00 pm
I started learning Lua scripting recently.
How to improve my parse script?
Download
Thanks.
Although, It's not the best way to use metatables in BMax Lua.
Sometimes, by using hooks in tables that are in already tables - map changing deals game crash.
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
local TempParse = parse
function parse(Cmd, ...)
	local p = [[ ]]
	p = p..table.concat( {...}, [[ ]] )
	TempParse(Cmd .. p)
end
--
parse("sv_msg2",1,321)
Blazzingxx has written
Please write me code, where my script generate game crash Everything worked fine until I added the remove + fade functions. Before the sprites lay on the ground so it worked. But now they only appear sometimes or not at all. I can't find any problems with it so I thought you guys could help me out here.
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
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
local day = 0
----------------------------------------------
-- HIT Sprite --
----------------------------------------------
addhook("hit","cs_hit")
function cs_hit(id,source,weapon,hpdmg,apdmg)
	if(source > 0) then
		if(player(id,"team") == 1 and player(source,"team") == 2) then
			x1 = player(id,"x")
			y1 = player(id,"y")
			x2 = player(source,"x")
			y2 = player(source,"y")
			--ANGLE
			angle = 90 + math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
			distance = 0
			time = 0
			weapimg = ""
			if(weapon == 1 or weapon == 2 or weapon == 3 or weapon == 4 or weapon == 5 or weapon == 6 or weapon == 20 or weapon == 21 or weapon == 22 or weapon == 23 or weapon == 24 or weapon == 39 or weapon == 40) then
				weapimg = "Small.bmp"
				distance = 2
				time = 7000
			end
			if(weapon == 10 or weapon == 11) then
				weapimg = "Huge.bmp"
				distance = 5
				time = 20000
			end
			if(weapon == 30 or weapon == 31 or weapon == 32 or weapon == 33 or weapon == 34 or weapon == 38) then
				weapimg = "Medium.bmp"
				distance = 5
				time = 10000
			end
			if(weapon == 35 or weapon == 36 or weapon == 37) then
				weapimg = "Big.bmp"
				distance = 5
				time = 15000
			end
			if(weapon == 50) then
				weapimg = "Tiny.bmp"
				distance = 5
				time = 7000
			end
			x1 = x1 + (math.cos(angle*(math.pi/180)) * distance)
			y1 = y1 + (math.sin(angle*(math.pi/180)) * distance)
			if(time > 0) then
				img=image("gfx/HolloweyesSprites/"..weapimg,x1,y1,0)
				imagepos(img,x1,y1,angle)
				timer(time,"fade1",day.."-"..img)
			end
		end
	end
end
----------------------------------------------
-- REMOVE TIMERS --
----------------------------------------------
addhook("endround","cs_endround")
function cs_endround(mode)
	day = day + 1
end
----------------------------------------------
-- FADE FUNCTIONS + REMOVE --
----------------------------------------------
function fade1(p)
	pos = string.find(p,"-")
	if(tonumber(string.sub(p,0,pos-1)) == day)then
		imagealpha( tonumber(string.sub(p,pos+1)) ,0.5)
	end
	timer(300,"removeIMG",p)
end
function removeIMG(p)
	pos = string.find(p,"-")
	if(tonumber(string.sub(p,0,pos-1)) == day)then
		freeimage( tonumber(string.sub(p,pos+1)) )
	end
end
Thanks
Timer works in miliseconds. 1 milisec = 1/1000 seconds.
So instead of 300 you should write 3000 for 3 seconds, 30000 for 30 seconds and so on. Note that the timer system is quite buggy.
@SDKey:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PARSE={cmd = nil}
function PARSE.__index(t,k)
	PARSE.cmd = k
	return t
end
function PARSE.__call(t, ...)
	if PARSE.cmd then --PARSE.cmd("par")
		PARSE.cmd = PARSE.cmd.." "..table.concat(arg," ")
		parse(PARSE.cmd)
		PARSE.cmd = nil
	else --PARSE("cmd","par")
		parse(table.concat(arg," "))
	end
end
setmetatable(PARSE,PARSE)
Also, I used one table for calling and storing the metamethods.
Is there any way to make a delay in the code then?
I need Works Menu Script
Flacko has written
@SDKey:
Flacko, thanks,
1. One table - good idea!
2. In my script: If I use dofile("sys\lua\parse") I won't cause a variable conflict, because my temp variables are local.
And I have not PARSE.cmd as table element
3. Your script has little bug: 1
2
3
2
3
PARSE.equip(1,3)	-- return "equip 1 3"
PARSE("equip", 1, 3)	-- return "cmd equip 1 3"
PARSE("equip 1 3")	-- return "cmd equip 1 3
4. Can I rewrite standart "parse" function?Please answer to me...
Lua Scripts/Questions/Help


Offline
