Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: pawel345 on May 14, 2014, 03:52:47 PM

Title: CW3:Abraxis detecting destruction of player units?
Post by: pawel345 on May 14, 2014, 03:52:47 PM
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?
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: knucracker on May 14, 2014, 05:15:01 PM
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.
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: pawel345 on May 15, 2014, 05:35:19 AM
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.
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: Karsten75 on May 15, 2014, 08:05:42 AM
Virgil, I think he's talking about the new notifications tabs.
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: pawel345 on May 15, 2014, 08:17:32 AM
Yes, but I know there is a function to create one, but how do you know when to make it?
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: Karsten75 on May 15, 2014, 08:25:11 AM
For player units it's built in.
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: knucracker on May 15, 2014, 08:42:02 AM
In your own core, add a :destroyed function.  That gets called whenever your core is destroyed.
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: pawel345 on May 15, 2014, 09:20:32 AM
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?
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: knucracker on May 15, 2014, 09:27:11 AM
I'm still not totally following... which map do you see this on?  That will probably help clear it up for me.
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: pawel345 on May 15, 2014, 09:53:31 AM
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.
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: knucracker on May 15, 2014, 10:09:38 AM
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.
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: stewbasic on May 15, 2014, 10:29:04 AM
There is a quirk I discovered while making this map http://knucklecracker.com/forums/index.php?topic=16178.0 (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?
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: pawel345 on May 15, 2014, 10:35:29 AM
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
Title: Re: CW3:Abraxis detecting destruction of player units?
Post by: Annonymus on May 15, 2014, 06:31:28 PM
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.