Forum

> > CS2D > Scripts > Health Replenish in my script doesn't work.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Health Replenish in my script doesn't work.

5 replies
To the start Previous 1 Next To the start

old Health Replenish in my script doesn't work.

Rainoth
Moderator Off Offline

Quote
Hello everybody. I was experimenting with SpawnProjectile command and wanted to make self HP regen (and I did find scripts here in forum that do that) but I wanted mine to work together with USGN. Basically what this has to do is :
• If player has USGN 15476 (me) then when he uses left atack he spawns items or other projectiles. THIS part is working.
• If player has USGN 15476 (also me) he gets healed back to 100 health every second) When I start server the hooks are added no errors occur and the projectile part works. Then via console I slap myself few times however I DO NOT heal back to 100 HP back. Could any of you tell me what I did/wrote wrong ? Knowing me.. I added a lot of unneeded stuff that might be pointless but I just try to make everything work. I would be VERY thankful if you could point out (at least) my mistake or fix the code. Thank you in advance.

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
function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end

bombs = initArray(32)
health = initArray(32)

addhook("attack2","bomb")
function bomb(id)
if (bombs[id]==1) then
if player(id,"usgn") == 15476 then
	for i=0,315,45 do
		parse("spawnprojectile "..id.." 45 "..player(id,"x").." "..player(id,"y").." 1000 "..i)
end
end
end
end

addhook("spawn","starting")
function starting(id)
bombs[id] = 1
health[id] = 1
end

addhook("second","rehealth")
function rehealth()
if (health[id]==1) then
if player(id,"usgn") == 15476 then
parse("sethealth "..id.." 100")
end
end
end

old Re: Health Replenish in my script doesn't work.

iii
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
addhook("second","rehealth")

function rehealth()
for i=1,32 do
	if (health[i]==1) then
		if player(i,"usgn") == 15476 then
			parse("sethealth "..i.." 100")
		end
	end
end

this is the function

old Re: Health Replenish in my script doesn't work.

Cure Pikachu
User Off Offline

Quote
@user iii: Missing end.
Fixed + Better:
1
2
3
4
5
6
7
8
9
10
addhook("second","rehealth")
function rehealth()
	for _, id in ipairs(player(0,"table")) do
		if (health[id]==1) then
			if player(id,"usgn") == 15476 then
				parse("sethealth "..id.." 100")
			end
		end
	end
end
edited 1×, last 08.09.14 09:21:35 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview