How do you check for total active totems?

Started by Endif, August 11, 2019, 07:07:17 PM

Previous topic - Next topic

Endif

I'd like to check how many totems are active while maintaining the totem's original purpose (generate aether).

There should be a CONST_ENERGYLEVEL because CONST_AMMO isn't working for the totems, assuming because it's green packets, not red.

Any guidance would be helpful,
Thanks!

Builder17

Quote from: Endif on August 11, 2019, 07:07:17 PM
I'd like to check how many totems are active while maintaining the totem's original purpose (generate aether).

There should be a CONST_ENERGYLEVEL because CONST_AMMO isn't working for the totems, assuming because it's green packets, not red.

According to this, CONST_AMMO works, but only for CRPL created totems http://knucklecracker.com/wiki/doku.php?id=crpl:crpltutorial:code_examples#connect_totems_to_win

Modified version to suit your purpose better:
# Original author: J
# This script has to be called totem.crpl
# ------------------------------------------
once
"TOTEM" CurrentCoords CreateUnit ->totemUID
"totem" ->unitName
4 delay self 0 Destroy
endonce


# Author: J
# ------------------------------------------
$totemsrequired:1
$scriptname:"totem.crpl"

once
ClearTraceLog ShowTraceLog
2 delay
"unitName" "totem" GetCoresWithVar dup ->totemcount 0 do # Finds all crpl created totems
<-scriptname "totemUID" getScriptVar
"totem" I concat ->!
loop
endonce

0 ->activecount
<-totemcount 0 do
"totem" I concat <-! dup ->unitUID CONST_AMMO GetUnitAttribute
0 gt if
<-activecount 1 add ->activecount
"Totems currently active: " <-activecount Trace2
endif
loop

# If all totems are active, blow up all enemy units (insta-win)
<-activecount <-totemsrequired gte if
#Replace these with your functionality
#0 0 99999 GetEnemyUnitsInRange 0 do
# dup Self neq if
# 2 Destroy
# else
# pop
# endif
# loop
# Self 2 Destroy
endif

GoodMorning

It works on any Totems, the CRPL part in that script is to acquire the UID of the Totems properly.
A narrative is a lightly-marked path to another reality.

Endif

Sorry, I meant to update this post the other night, but I figured out a way that works.


once
106 242 GetUnitAt ->totem1
210 5   GetUnitAt ->totem2
63 38   GetUnitAt ->totem3
199 104 GetUnitAt ->totem4
endonce

5 1 do
"totem" I concat <-! CONST_AMMO GetUnitAttribute
5 gt <-activeTotems add ->activeTotems
loop

Endif

Quote from: GoodMorning on August 12, 2019, 11:38:56 PM
It works on any Totems, the CRPL part in that script is to acquire the UID of the Totems properly.

I've heard about some issues with grabbing UID on the discord chat. What's that all about exactly? I mean, I understand that GetUnitAt can retrieve multiple units and that could be an issue, but what's the problem with using it on an application specific situation in which there will only be one unit at that location?

The only issue I can surmise is in the case of a Canon flying overtop of it. Would that trigger the GetUID?

GoodMorning

It could. The usual reason for caution is that people try to get the UID of a PZ or similar unit, and end up with the wrong one. Sometimes they end up destroying the core which runs the script.

For this application, you should be fine. In fact, you could even hard-code the UIDs directly (not a suggestion, merely an observation).
A narrative is a lightly-marked path to another reality.

Endif

Quote from: GoodMorning on August 13, 2019, 08:53:09 PM
In fact, you could even hard-code the UIDs directly (not a suggestion, merely an observation).
Reh-heh-heaally?

I wasn't too sure how the UID's work. I figured they were a random number derived from something and assigned at the beginning of the game. How do I know what will affect how the UID is derived? Are they the same if I move them?

GoodMorning

The UID is assigned when the unit is created, and kept until it is destroyed. For example, a Mortar will have the same UID when you move it, save/load, and change the settings.

A PZ is not the same unit as the Emitter that left it, and a Guppy base is not the same unit as the aircraft. Thus, they will have different UIDs.

UIDs are unique, so they won't be reused. However, it's generally best to treat them as "magic" unless you have a very specific reason not to.

For this, I would try to use GetAllUnitsInRange and then find the Totem. There are some circumstances where a hardcoded UID is good, but not many of them. (And it's risky even then. What if you accidentally miss when using "delete" in the editor, forget to change the script, and you only find the problem after playing through to what should be the end?)
A narrative is a lightly-marked path to another reality.