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 2206 207 208338 339 Next To the start

old Re: Lua Scripts/Questions/Help

palomino
User Off Offline

Quote
Thank you Dark Byte:D
EDIT: He shows that I tried to call line 8 a nil value:
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
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
achvmfunc.lvl=initArray(32)
achvmfunc.timer=initArray(32)

addhook("kill","achvmfunc")
function achvmfunc(killer,victim,weapon)
	if (os.clock()-achvmfunc.timer[killer])>3 then
		achvmfunc.lvl[killer]=0
	end
	level=achvmfunc.lvl[killer]
	level=level+1
	achvmfunc.lvl[killer]=level
	killtimer[killer]=os.clock()

	if (weapon==1) and (level==5) then
		msg(player(killer,"name").." made 5 kills with a USP! ")
		parse("equip "..id.." 57")
	end
	if (weapon==2) and (level==5) then
		msg(player(player,"name").." made 5 kills with a Glock! ")
		parse("equip "..id.." 57")
	end
	if (weapon==32) and (level==10) then
		msg(player(killer,"name").." became a Marksman! ")
		parse("equip "..id.." 58")
	end
	if (weapon==30) and (level==10) then
		msg(player(killer,"name").." became a Marksman! ")
		parse("equip "..id.." 58")
	end
	if (weapon==35) and (level==5) then
		msg(player(killer,"name").." is a Sniper! ")
	end
	if (weapon==69) and (level==5) then
		msg(player(player,"name").." is a Psycho! Hunt him down! ")
	end
end
What to do now?

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
@Sunny Autumn:
1
2
achvmfunc.lvl=initArray(32)
achvmfunc.timer=initArray(32)

to

1
2
3
achvmfunc = {} -- you must create the array before indexing
achvmfunc.lvl=initArray(32)
achvmfunc.timer=initArray(32)

Edit:
What is the difference between pairs(t) and ipairs(t)? I was doing a test and they both seem to return the same value.
edited 1×, last 04.06.10 02:37:25 am

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
pairs will get all the keys, including strings.
ipairs will get all the numerical indexes starting from zero
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
a ={
	1,
	5,
	lol=3
}

for k,v in pairs(a) do
	print(k)
end
--Output:
--1,2,lol

a = {1,2,3,nil,4,5}
for i,v in ipairs(a) do
	print(i)
end
--Output: 1,2,3 (notice that the func stopped when found nil)

Edit: Autumn's script still won't work, he is using the same name for a table and a function (achvmfunc)

old Re: Lua Scripts/Questions/Help

ZzZz
User Off Offline

Quote
Plz help me I want this script to use only 1 serveraction key for the bank:
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
addhook("join","bank_join")
addhook("menu","bank_menu")
addhook("serveraction","bank_serveraction")

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

bank_money_player = array(32)
bank_table = {100,200,500,1000,2000,5000,10000,16000}

function bank_join(p)
     bank_money_player[p] = 0
end

function bank_serveraction(p)
     menu(p,"Bank Menu (Your Cash: "..bank_money_player[p].."),Add Cash To Bank,Take Cash From Bank")
end

function bank_cash_add(p)
     menu(p,"Add Cash To Bank? (Bank: "..bank_money_player[p].."),$100,$200,$500,$1000,$2000,$5000,$10000,$16000")
end

function bank_cash_take(p)
     menu(p,"Take Cash From Bank? (Bank: "..bank_money_player[p].."),$100,$200,$500,$1000,$2000,$5000,$10000,$16000")
end

function bank_menu(p,t,s)
     if ("Bank Menu" == string.sub(t, 1, 9)) then
          if (s == 1) then
               bank_cash_add(p)
          elseif (s == 2) then
               bank_cash_take(p)
          end
     end

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
Just replace
1
2
3
function bank_serveraction(p)
menu(p,"Bank Menu (Your Cash: "..bank_money_player[p].."),Add Cash To Bank,Take Cash From Bank")
end
by
1
2
3
4
5
function bank_serveraction(p, action)
	if (action == 1) then
		menu(p,"Bank Menu (Your Cash: "..bank_money_player[p].."),Add Cash To Bank,Take Cash From Bank")
	end
end

old Re: Lua Scripts/Questions/Help

ZzZz
User Off Offline

Quote
thx
Can anyone give me a script so that when someone kills a player, the killer gains money and the victim loses money?
edited 2×, last 06.06.10 09:23:54 am

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
@ZzZz:
1
2
3
4
5
6
7
8
9
addhook("kill", "_kill")

mon_add = 100
mon_sub = 100

function _kill (k, v)
	parse("setmoney "..k.." "..(player(k, "money")+mon_add))
parse("setmoney "..v.." "..(player(v, "money")-mon_sub))
end

old Re: Lua Scripts/Questions/Help

Refresh
User Off Offline

Quote
hi guys. I want to create a little complicated script. I have a menu to create some objects, and I want to move the things you can build with wrench to this menu, and I want to make it too they costs money. I am very n00b starter scripter :l
thanks for reading

old Re: Lua Scripts/Questions/Help

palomino
User Off Offline

Quote
Dark Byte has written
@ZzZz:
1
2
3
4
5
6
7
8
9
addhook("kill", "_kill")

mon_add = 100
mon_sub = 100

function _kill (k, v)
	parse("setmoney "..k.." "..(player(k, "money")+mon_add))
parse("setmoney "..v.." "..(player(v, "money")-mon_sub))
end

I think you meant this:
1
2
3
4
function _kill (k, v)
	parse("setmoney "..k.." "..(player(k, "money")+mon_add))
	parse("setmoney "..v.." "..(player(v, "money")-mon_sub))
end

old Re: Lua Scripts/Questions/Help

Vectarrio
User Off Offline

Quote
Sunny Autumn has written
Dark Byte has written
@ZzZz:
1
2
3
4
5
6
7
8
9
addhook("kill", "_kill")

mon_add = 100
mon_sub = 100

function _kill (k, v)
	parse("setmoney "..k.." "..(player(k, "money")+mon_add))
parse("setmoney "..v.." "..(player(v, "money")-mon_sub))
end

I think you meant this:
1
2
3
4
function _kill (k, v)
	parse("setmoney "..k.." "..(player(k, "money")+mon_add))
	parse("setmoney "..v.." "..(player(v, "money")-mon_sub))
end

no, he made this mon_add=100 and mon_sub=100, so you can easily change amount of money

old Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

Quote
But that is not the mistake.
1
2
3
4
5
6
7
8
9
addhook("kill", "_kill")

mon_add = 100
mon_sub = 100

function _kill (k, v,weapon,x,y)
     parse("setmoney "..k.." "..(player(k, "money")+mon_add))
     parse("setmoney "..v.." "..(player(v, "money")-mon_sub))
end

old Simple Ball Physics

SQ
Moderator Off Offline

Quote
That's the script I've done some time ago. "Simple ball physics"...
You should test this script with empty map (dm_laser size)

IMG:https://img517.imageshack.us/img517/2858/dsay.th.png


√ Ball has effect from weapon bullets.
√ You can disable, enable kick mode by pressing [E]

Don't forget to set image path.
IMG:https://img72.imageshack.us/img72/1050/ballo.png


This line/function to set area size.
1
SetArea(2,2,18,18)

== Full Script
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
function InTable(n,v)
	local Table = {}
	for i = 0, n, 1 do Table[i] = v end
	return(Table)
end

ImagePath = "gfx/lua/ball.png"	-- Image = 32*32 (Circle)

WeaponsPush = true

Ball = { X , Y, XS, YS, IMG = {}, Cur }
Pl = { Kick = InTable(32,0) }

addhook("startround","FootBallStart")
addhook("always","FootBallUpdate")
addhook("use","FootBallKick")
addhook("attack","FootBallPush")

function FootBallStart() LoadBall(9,9) end

function SetArea(X,Y,W,H) Area = { X = X * 32 + 16, Y = Y * 32 + 16, W = W * 32 + 16, H = H * 32 + 16 } end

function LoadBall(X,Y)
	Ball.X, Ball.Y = X * 32 + 16, Y * 32 + 16
	Ball.XS, Ball.YS = 0, 0
	for k, v in pairs(Ball.IMG) do freeimage(v) end
	Ball.IMG = {}
	local ID = image(ImagePath,Ball.X,Ball.Y,1)
	table.insert(Ball.IMG,ID)
	Ball.Cur = ID
end

function FootBallUpdate()
	local X, Y
	for k, v in pairs(player(0,"table")) do
		X, Y = player(v,"x"), player(v,"y")
		if (Dist(X,Y,Ball.X,Ball.Y) < 32) then
			local RAD = math.atan2(Y - Ball.Y,X - Ball.X)
			local Power = 2
			if (Pl.Kick[v] > 0) then
				Power, Pl.Kick[v] = 12, 0
				msg2(v,"KICK!@C")
				msg2(v,"Kick: OFF")
			end
			Ball.XS = Ball.XS - math.cos(RAD) * Power
			Ball.YS = Ball.YS - math.sin(RAD) * Power
			Ball.X = X - math.cos(RAD) * 33
			Ball.Y = Y - math.sin(RAD) * 33
		 end
	end
	-- This should be improved by tile collisions
	if (Ball.X > Area.W or Ball.X < Area.X) then Ball.XS = -Ball.XS end
	if (Ball.Y > Area.H or Ball.Y < Area.Y) then Ball.YS = -Ball.YS end
	if (Ball.X > Area.W) then Ball.X = Area.W end
	if (Ball.Y > Area.H) then Ball.Y = Area.H end
	if (Ball.X < Area.X) then Ball.X = Area.X end
	if (Ball.Y < Area.Y) then Ball.Y = Area.Y end	
	if (Ball.XS > 12) then Ball.XS = 12 elseif (Ball.XS < -12) then Ball.XS = -12 end
	if (Ball.YS > 12) then Ball.YS = 12 elseif (Ball.YS < -12) then Ball.YS = -12 end 
	Ball.X, Ball.Y = Ball.X + Ball.XS, Ball.Y + Ball.YS
	imagepos(Ball.Cur,Ball.X,Ball.Y,0)
	Ball.XS, Ball.YS = Ball.XS / 1.05, Ball.YS / 1.05
end

function Dist(X1,Y1,X2,Y2)
	return( ((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2) ^ .5 )
end

function FootBallKick(ID)
	local Switch = {"Off","On"}
	if (Pl.Kick[ID] > 0) then Pl.Kick[ID] = 0 else Pl.Kick[ID] = 1 end
	msg2(ID,"Kick: "..Switch[Pl.Kick[ID] + 1])
end

function FootBallPush(ID)
	local WPN = player(ID,"weapontype")
	if (WPN > 0 and WPN < 10 or WPN > 19 and WPN < 41) and WeaponsPush then
		local X = player(ID,"x")
		local Y = player(ID,"y")
		local ROT = player(ID,"rot") - 90
		local FLY = true
		while FLY do
			X, Y = X + math.cos(math.rad(ROT)) * 5, Y + math.sin(math.rad(ROT)) * 5
			if Dist(X,Y,Ball.X,Ball.Y) < 16 then
				local DMG = itemtype(WPN,"dmg") / 4
				Ball.XS, Ball.YS = Ball.XS + math.cos(math.rad(ROT)) * DMG, Ball.YS + math.sin(math.rad(ROT)) * DMG
				break
			else
				if tile(math.ceil(X/32) - 1,math.ceil(Y/32) - 1,"wall") then FLY = false end
			end
		end

	end
end

FootBallStart()
SetArea(2,2,18,18)

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
Nice!! I love you
but the ball when you kick it, its go thru the wall. Is there possible to make it wall like map size?

old Re: Lua Scripts/Questions/Help

EngiN33R
Moderator Off Offline

Quote
Hi people! I may ask a stupid question, but how do I make a custom killed-by in the top right corner? E.g. I'm not killed by Claw, I'm killed by Infection (XCafe.net servers)
To the start Previous 1 2206 207 208338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview