Forum

> > CS2D > Scripts > Will my script work ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Will my script work ?

8 replies
To the start Previous 1 Next To the start

old Will my script work ?

Rainoth
Moderator 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
killpt = 0
addhook("second","revivehud")
function revivehud()
	for __,id in pairs(player(0,"table")) do
		if player(id,"exists") then
			parse('hudtxt2 '..id..' 3 "©255000000Kill Streak: '..killpt..'" 123 123')
		end
	end
end

addhook("die","givinglife")
function givinglife(victim,killer,weapon,x,y)
ix = player(id,"tilex")
iy = player(id,"tiley")
	if killpt[id] == 3 then
		parse("spawnplayer "..victim.." "..ix.." "..iy..")
		parse("equip "..victim.." 32")
		parse("equip "..victim.." 3")
		parse("setarmor "..victim.." 200")
killpt[id] = killpt[id] - 3
	end
end



addhook("kill", "akill")
function akill(id, victim, weapon, x, y)
killpt = killpt + 1
end

I wrote this all from a scratch without looking at any examples so I think stuff might be wrong... This will be run in Jail server so no respawn until new round. The idea is :
• Hud that shows Kill Points
• When player kills someone, he gets one kill point.
• If the player dies and he has at least 3 kill points, he will respawn at his exact location, get weapons and armor and his killpoints will be reduced by 3

Hope you can tell me what can be wrong here...

EDIT : It doesn't work after I just tested it It gives me kill points when I die too...

old Re: Will my script work ?

Cure Pikachu
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
-- killpt needs to be a table
killpt = {}
for i = 1, 32 do
	killpt[i] = 0
end

addhook("second","revivehud")
function revivehud()
	for __, id in pairs(player(0,"table")) do
		-- the player(id,"exists") check can be skipped due to the use of player(0,"table")
		parse('hudtxt2 '..id..' 3 "©255000000Kill Streak: '..killpt[id]..'" 123 123')
	end
end

addhook("die","givinglife")
function givinglife(victim,killer,weapon,x,y)
	-- Wrong check, == is too restrictive
	if killpt[victim] >= 3 then
		-- spawnplayer's x and y parameters are in pixels
		-- besides you can't retrieve coordinates from a dead player
		-- and since the die hook has x and y parameters in pixels, I'll use those
		parse("spawnplayer "..victim.." "..x.." "..y) -- FIXED
		-- PMs seems to be taking forever to send :o
		timer(750,"parse","equip "..victim.." 32")
		timer(750,"parse","equip "..victim.." 3")
		timer(750,"parse","equip "..victim.." 50")
		timer(750,"parse","setweapon "..victim.." 32")
		timer(750,"parse","setarmor "..victim.." 200")
		killpt[victim] = killpt[victim] - 3
	end
end

addhook("kill","akill")
function akill(id) -- parameters that are not needed for a certain function can be omitted
	killpt[id] = killpt[id] + 1
end

-- for a per-player table, this is required at least
addhook("join","resetkills")
function resetkills(id)
	killpt[id] = 0
end
Other than that, I think you got the hang of it.
edited 3×, last 01.03.13 07:41:35 pm

old Re: Will my script work ?

KagamineLen
User Off Offline

Quote
1
LUA ERROR: sys/lua/test.lua:16: unfinished string near '")'

Line 16
1
parse("spawnplayer "..victim.." "..ix.." "..iy..")

do this
1
parse("spawnplayer "..victim.." "..ix.." "..iy.."")

old Re: Will my script work ?

Rainoth
Moderator Off Offline

Quote
I'm sorry but I don't know how to make tables yet. Is it possible to do it other way ? (I'm going to copy yours for now ..)

old Re: Will my script work ?

Rainoth
Moderator Off Offline

Quote
More >


This script is working to the point of spawning player. The player spawns but gets no equipment. Is there any way I could make this work ?

old Re: Will my script work ?

Gajos
BANNED Off Offline

Quote
sorry, but I made it on my android and I didn't tested it.
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
addhook("second","updatehud")
function updatehud()
	for _, id in pairs(player(0,"table")) do
		if player(id,"exists") then
			parse('hudtxt2 '..id..' 3 "©255000000Kill Streak: '..killpt[id]..'" 123 123')
		end
	end
end

pt = {}
addhook("die","pt.die")
function pt.die(id,killer,weapon,x,y)
	if killpt[id] >= 3 then
		parse("spawnplayer "..id.." "..x.." "..y.." ")
		if killpt[id] >= 3 then
			killpt[id] = killpt[id] - 3
		else
			killpt[id] = 0
		end
	end
end

addhook("spawn","pt.spawn")
function pt.spawn(id)
		parse("equip "..id.." 32")
		parse("equip "..id.." 3")
		parse("setarmor "..id.." 200")
end

addhook("kill","pt.kill")
function pt.kill(id)
	killpt[id] = killpt[id] + 1
end

addhook("join","pt.join")
function pt.join(id)
	killpt[id] = 0
end

old Re: Will my script work ?

KagamineLen
User Off Offline

Quote
this code is tested and working

More >
edited 2×, last 02.03.13 12:05:54 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview