Forum

> > CS2D > Scripts > Health Script
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Health Script

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Health Script

DX
User Off Offline

Zitieren
how so that I receive more than 250 damage I will not die
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
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end

HP = initArray(32)
AP = initArray(32)

addhook("spawn","spawn")
function spawn(id)
	HP[id]=1000
	AP[id]=1000
end

addhook("always","always")
function always()
	for id = 1, 32 do
		if HP[id]>0 then
			parse("setmaxhealth "..id.." 250")
			parse('hudtxt2 '..id..' 1 "©000500000Health: '..HP[id]..'" 10 440')
		elseif HP[id]<1 then
			parse("sethealth "..id.." 1")
			parse('hudtxt2 '..id..' 1 "©000500000Health: 0" 10 440')
		end

		if AP[id]>0 then
			parse("setarmor "..id.." 200 ")
			parse('hudtxt2 '..id..' 2 "©000500000Armor: '..AP[id]..'" 10 460')
		elseif AP[id]<1 then
			parse("setarmor "..id.." 0 ")
			parse('hudtxt2 '..id..' 2 "©000500000Armor: 0" 10 460')
		end
	end
end

addhook("hit","hit")
function hit(id,source,wpn,hpdmg,apdmg)
	if HP[id]>0 then
		HP[id]=HP[id]-hpdmg
	end

	if AP[id]>0 then
		AP[id]=AP[id]-apdmg
	end
end

alt Re: Health Script

Bowlinghead
User Off Offline

Zitieren
1. Think of when your health changes. It only accurs on the "hit" event (or the die, leave event) therefore you dont have to check it "always"!


2. Use return 1 to neglect ALL damage received at the end and then use
1
parse("sethealth "..id.." "..HP[id])
when HP[id] < 250.

3. table optimization or something like that. When there are 3 players on the servers, you store 29x "0".


Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function yourHit(id,source,wpn,hpdmg,apdmg)
     
    HP[id] = HP[id] - hpdmg;
   if (HP[id] <= 0) then 
	parse("killplayer "..id)
   end


    if (HP[id] < 250) then
	parse("sethealth "..id.." "..tostring(HP[id]))
   else 
	parse("sethealth "..id.." 250");
   end

   return 1;
   -- note that everything below "return" WILL NOT BE EXECUTED!
end

alt Re: Health Script

Cure Pikachu
User Off Offline

Zitieren
Wait, so if incoming (raw) damage is more than 250 it is negated? Or a health script that extends your max HP past 250 like the kind user Mami Tomoe shared?
1× editiert, zuletzt 14.01.21 11:21:49
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht