CW3:Abraxis detecting destruction of player units?

Started by pawel345, May 14, 2014, 03:52:47 PM

Previous topic - Next topic

pawel345

If possible I would like to see how it's done, I see ho to make the pop-up but how do you detect if a player unit has been destroyed?

knucracker

Which mission are you talking about in CW3:A?
In general if you have the unitID for a unit, you can call GetUnitAttribute(<-unitID CONST_ISDESTROYED) to tell.

If you have a crpltower you can put
:Destroyed
in your script.  That gets called when the crpltower is destroyed.

pawel345

In all the missions, at lest the starting ones, you view a message-box whenever any of the units is destroyed by the creeper, but not if the player triggered the destruction. I would like to see the script used as, for some time I had an idea for a map that requires to know if the creeper destroyed a player unit.

Karsten75

Virgil, I think he's talking about the new notifications tabs.

pawel345

Yes, but I know there is a function to create one, but how do you know when to make it?

Karsten75


knucracker

In your own core, add a :destroyed function.  That gets called whenever your core is destroyed.

pawel345

Hmm, what I meant I would like to detect if a player unit, let's say a nullifier gets destroyed by creeper. My idea was that to set a limit on the unit's let's say 10 of them, and then if a player "looses" a unit lower the limit by 1. So an unit once lost is lost, but you can still destroy your own units, to build them elsewhere. But I don't know how to detect such an event, and seeing that it works in the maps there, I wonder how is it done?

knucracker

I'm still not totally following... which map do you see this on?  That will probably help clear it up for me.

pawel345

Ehh I guess nevermind.

The thing I'm asking about is how to detect the destruction of a player build unit like a collector or a PC, that got destroyed by Creeper.
Because just checking the CONST_ISDESTROYED will not give me the information if it was destroyed by the player or by the enemy.

In the online version you put a message whenever such an event occurs. I was asking what kind of script is used to detect such an event.

knucracker

Yeah, those game event tags are built into game.  Every internal unit has a handler for destruction and that internal handler pops up that game event tag.  There is currently no global event that is broadcast to CRPL scripts every time a unit gets destroyed which in turn indicates the reason for the destruction.  Adding something like that would require a little bit of thinking.  Something like a game event log that crpl scripts could peek at.  Sounds like a good idea, but is more work than I can devote right now.

stewbasic

There is a quirk I discovered while making this map http://knucklecracker.com/forums/index.php?topic=16178.0 which could help, though you run the risk of the quirk being changed by a future game update.

In the frame the unit is destroyed (ie the first frame where GetUnitAttribute(<-unit CONST_ISDESTROYED) is true), calling GetUnitType will return nothing if destroyed by creeper, but will return the expected thing if destroyed by the player (same for other GetUnitAttribute calls). This includes paused frames too so you need to use OperateWhilePaused. eg:


once
  @GetTheUnitICareAbout ->unit
  @Awake
endonce

if(<-unit)
  if(GetUnitAttribute(<-unit CONST_ISDESTROYED))
    if(GetUnitType(<-unit) "" eq)
      # Unit destroyed by creeper
    else
      # Unit destroyed by player
    endif
  endif
  0 ->unit
endif

:Awake
  OperateWhilePaused(TRUE)


Of course, it might be easier to just destroy the unit yourself when its HP drops below some threshold. Also in the scenario you've described, can't a player get around the mechanic by carefully destroying any unit that is close to dying?

pawel345

Yes but it would work for nullifiers, preventing the player to randomly place them wherever. Also a lost collector or reactor would be lost :P

Annonymus

You can still do this by attaching a CRPL core to every player unit copying its health and making it vulnerable to creeper, now if the core gets destroyed by the creeper (at the same time as the unit given that they have the same health) decrease the limit by 1, while if the core exists but can not detect it's associated unit anymore the player must have destroyed it therefore you can destroy the core without doing anything else.

However this idea seems pretty useless to me since with a bit of micromanagement it would always be possible to destroy the unit just a moment before it gets destroyed by the creeper, without losing a single unit in the entire map.
If a topic started by me is in the wrong place feel free to move it at anytime.