CRPL "Damage"

Started by LappySheep, August 13, 2017, 03:14:00 PM

Previous topic - Next topic

LappySheep

Is there a reason the following code does not work?:

$COLLISION_RADIUS:16
$DAMAGE_AMT:0.1

once
Self CONST_MAXHEALTH 2000000 SetUnitAttribute
endonce

GetUnitsInRange(CurrentCoords <-COLLISION_RADIUS) ->unitUID
Damage(<-unitUID <-DAMAGE_AMT)
3 Delay


The idea is:
Within a radius of 8 (I assume range = diameter), structures by the player will slowly take damage by 10% health per 3 frames (1 second per structure destroyed).

When I ran the script, it damages nothing.

Without the one-time-run segment, the core destroyed itself.

When collision radius was 1, the units destroyed were anywhere on the map.

Long story short, I wanted to make a unit that would be indestructible and would have a small area where allied units would get destroyed, and optionally if it can work, it would spawn creeper on the area of destroyed units.

GoodMorning

The first step in debugging something like this is the trace commands. Not all units have the same health, either - a CN is much tougher than a Beam.

I suggest first checking what the GetUnitsInRange call returns. Be aware that it can collect PZs. TraceStack will be your friend.

There is an existing flaw:
GetUnitsInRange ->UID
GUIR pushes a lot of UIDs to the stack, followed by the number of units found. You are taking the count as your target, and leaving the actual UIDs.
A narrative is a lightly-marked path to another reality.

LappySheep

Is there a way I can skip parts of the stack?

GoodMorning

Nothing better than "swap". You can, however, do something along the lines of this...


$Range:10
$DamageAmt:0.04
CurrentCoords <-Range GetUnitsInRange 0 do #Use the count as a loop-limit
    ->UID
    <-UID <-DamageAmt Damage
loop
A narrative is a lightly-marked path to another reality.

LappySheep

So if I'm right, that code...

--> Changes the range to 10 as a variable. (Is this radius or diameter?)
--> Damage amount is 0.04 as a variable. (Is there a way I can find the HP for every unit? In a previous question I asked in the forums I was told you could modify HP of custom units (and I'm assuming this includes hardcoded units too?), does this mean the unit will take 0.04 damage or 4% of their hp as damage?

--> Makes units in the range take damage

For the comment of #Use the count as a loop-limit

Does this mean I can limit it? And if it's "0", does that make it infinite?

GoodMorning

Here's the more in-depth explanation:


$Range:10.0
$DamageAmt:0.04
CurrentCoords <-Range GetUnitsInRange 0 do
    ->UID
    <-UID <-DamageAmt Damage
loop


$Var is an input variable, with a default value. This allows you to set this from within the map editor.

GetUnitsInRange (and all related functions) take range as a radius.

GetUnitsInRange, if it picks up four units, will have this effect on the stack:
[ X Y Radius - UID0 UID1 UID2 UID3 4]
So, four UIDs followed by the count are pushed to the stack.

"do" takes two arguments: [End Start - ]
Entering the do-loop, I is set to "Start" (I've only ever supplied ints for this). Every time the code gets to "loop", I goes up by one; if I is now still less than "End" then the code goes back to the "do", otherwise continuing to the code after "loop".

Combining this, we get:

X Y Radius #GetUnitsInRange
UID0 UID1 UID2 UID3 4
UID0 UID1 UID2 UID3 4 0 #do
UID0 UID1 UID2 UID3
#I=0; ->UID, do damage
UID0 UID1 UID2
#I=1; ->UID, do damage
UID0 UID1
#I=2; ->UID, do damage
UID0
#I=3; ->UID, do damage
#Stack is empty again
#I=4; loop finished


The wiki has information on units. Only CRPL Cores can have their max health or heal rate changed. All units can have their current health set. You can damage something for a proportion of it's maximum health by checking it (<-UID CONST_MAXHEALTH GetUnitAttribute) and dealing damage (or just direct health-setting) accordingly. Health is an absolute, so dealing 0.04 damage to something with 400 health will end with a unit at 399.96 health (give or take rounding).
A narrative is a lightly-marked path to another reality.

LappySheep

Ah, I get it now. Thank you :)