Forum

> > CS2D > Scripts > Armor regen script is not adding armor
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Armor regen script is not adding armor

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Armor regen script is not adding armor

SpartanWar118
User Off Offline

Zitieren
I've got a bit of a problem that won't leave me be
Basically what i'm trying to do here is make it to where the player with an id of 1 (Usually me when i start up the local server) gains 4 points of Kevlar armor per second up until the armor count reaches 100, then it stops
But it doesn't even start to begin with, it remains at zero
I checked the console, but nothing was wrong, i tried a bit of manual debugging but it seems to be successfully adding armor, but i'm not getting it
I checked my id in the game, it's always been 1
But yet it doesn't work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
------------
-- CONFIG --
------------
	
	AP = 4 -- how many Armor Points will be added per second

------------

if second==nil then second={} end
second={}

addhook("second", "every_second")
function every_second()
	PlayerID = 1 -- Player's ingame id
	PlayerArmor = player(1, "armor") -- Player's current armor
	AddArmor = player(1, "armor")+AP -- Simple AP calculator
	   if PlayerArmor ~= 100 then -- Stops charging at 100
	   parse ("setarmor "..PlayerID.." AddArmor") -- Finishes math
	   end
end

Thanks for any help i can get
(By the way, it's a modified "Gradual Healing" code i saw on this site once, not that i couldn't eventually learn to make it by myself)

alt Re: Armor regen script is not adding armor

Cure Pikachu
User Off Offline

Zitieren
I am typing this from a phone, so I will apologise in advance if it comes out wrong.
First, replace
parse ("setarmor "..PlayerID.." AddArmor")
with
parse("setarmor "..PlayerID.." "..AddArmor)
. This one is just what I call a syntax error.
Next,
if PlayerArmor ~= 100 then
should be
if PlayerArmor  < 100 then
. Wrong operator basically.
In addition, to ensure that the armour value actually stops at 100 (it can reach up to 206), replace
AddArmor = player(1, "armor")+AP
with
AddArmor = math.min(player(1,"armor")+AP,100)
.
1× editiert, zuletzt 20.11.17 23:58:34

alt Re: Armor regen script is not adding armor

SpartanWar118
User Off Offline

Zitieren
Oh my god thank you very much!
It took me forever to figure out what was wrong
Either it did what i mentioned earlier, or it would go past 200
(And eventually make the armor disappear entirely, not even leaving a "0", just a shield icon)
I guess we can close this thing now

alt Re: Armor regen script is not adding armor

Cure Pikachu
User Off Offline

Zitieren
user SpartanWar118 hat geschrieben
(By the way, it's a modified "Gradual Healing" code i saw on this site once...)

That might be the code that I shared.

It also might be worth doing a
player(1,"exists")
and
player(1,"health") > 0
query so it doesn't spam error messages into the console in the following cases:
• You are running a dedicated server and the player with ID 1 doesn't exist
• Player with ID 1 is dead

alt Re: Armor regen script is not adding armor

Rainoth
Moderator Off Offline

Zitieren
You might also want to remove line 9 and 10 because you're not using them anywhere.

They are used in the examples to contain various variables and functions inside these tables. You chose to name your function "every_second" thus it has nothing to do with the "second" table. Might as well remove it then
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht