Forum

> > CS2D > Scripts > Armor regen script is not adding armor
Forums overviewCS2D overview Scripts overviewLog in to reply

English Armor regen script is not adding armor

4 replies
To the start Previous 1 Next To the start

old Armor regen script is not adding armor

SpartanWar118
User Off Offline

Quote
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)

old Re: Armor regen script is not adding armor

Cure Pikachu
User Off Offline

Quote
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)
.
edited 1×, last 20.11.17 11:58:34 pm

old Re: Armor regen script is not adding armor

SpartanWar118
User Off Offline

Quote
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

old Re: Armor regen script is not adding armor

Cure Pikachu
User Off Offline

Quote
user SpartanWar118 has written
(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

old Re: Armor regen script is not adding armor

Rainoth
Moderator Off Offline

Quote
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
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview