Author Topic: [Suggestion/Y-Scripts]setDeathFrames  (Read 2219 times)

Offline Buscher

  • Colonel
  • ****
  • Posts: 168
    • View Profile
[Suggestion/Y-Scripts]setDeathFrames
« on: February 17, 2023, 11:36:38 am »
For Gibs of Gory it would be helpful if scripting allowed to set the number of DeathFrames. I would like to keep the default 3 for the standard death while being able to extend the more messy ones to 8. For the standard death creating the missing 5 frames or extending the 3 to 8 is a bit prohibitive for mods which have a lot of spritesheets already. 3 DeathFrames for the messy ones works okay but it could look a lot better with 8.

Currently getDeathFrames is attached to RuleArmor which makes sense and of course limits a setDeathFrames as this information can be read-only. Would it be viable to add an override with BattleUnit.setDeathFrames?

Thanks for possible considerations.

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3346
    • View Profile
Re: [Suggestion/Y-Scripts]setDeathFrames
« Reply #1 on: February 17, 2023, 12:19:26 pm »
I do not know it should be on `BattleUnit`, as you set it once, but then unit again "die" how many frames then should be used?

I will think how best expose this to scripts, for now I consider altering this during dying animation directly.

Offline The Martian

  • Commander
  • *****
  • Posts: 754
  • "It implores you to listen to its arguments..."
    • View Profile
Re: [Suggestion/Y-Scripts]setDeathFrames
« Reply #2 on: February 18, 2023, 01:21:25 am »
I would like to keep the default 3 for the standard death while being able to extend the more messy ones to 8.

Although it will work a little different I think you can currently script the end goal you want.

Use an altered version of this script Yankes uploaded that changes which frames on a sprite sheet are loaded for the death animation:
https://openxcom.org/forum/index.php/topic,10392.msg144792.html#msg144792

Code: [Select]
extended:
  scripts:
    selectUnitSprite:
      - offset: -2
        code: |
          var int drawingRoutine;
          var int deathFrames;
         
          if or
            eq blit_part blit_torso
            eq blit_part blit_legs
          ;
            var ptr RuleArmor armor;
            unit.getRuleArmor armor;
            armor.getDrawingRoutine drawingRoutine;
            armor.getDeathFrames deathFrames;
            if and
              eq drawingRoutine 0
              gt sprite_index 264  #bigger than first death frame
              gt deathFrames 3
            ;
              sub deathFrames 3;
              add sprite_index deathFrames;
            end;
          end;
          return sprite_index;
Global script, check for `drawingRoutine: 0`  and for e.g. `deathFrames: 5`.

Script shift all frames after death frame by additional death frames.


I think the trick would be to place a check for the type of situation/damage you want right before the frame offset so that a different frame set is used depending on what the unit was hit with.

Pseudocode Example:
Code: [Select]
if situation 1 # (Unit was hit for over 50 of its current health and died)
  sprite_index 264
end

if situation 2 #  (Unit was hit be a fire attack and died)
  sprite_index 274
end

if situation 3 #  (Unit was hit be a stunning attack and collapsed)
  sprite_index 284
end

You would need several sets of the death animation frames each offset by X amount ahead of the last for the script to work. Although it won't let you increase or decrease the number of death frames you can just insert your expected FloorOb for any addtional frames on the sprite sheet for deaths with a lower frame count. (The delay should be very brief)

Here is an example unit sprite sheet of what I mean, the death frames are not currently aligned to the correct index I'm just trying to show what I mean visually:
Spoiler:
« Last Edit: February 18, 2023, 01:41:25 am by The Martian »

Offline Buscher

  • Colonel
  • ****
  • Posts: 168
    • View Profile
Re: [Suggestion/Y-Scripts]setDeathFrames
« Reply #3 on: February 18, 2023, 09:52:30 am »
My suggestion is about to dynamically select the number of deathFrames (for example 3 vs 8 ). In other words the length of animation. Not the beginning index. The latter is already done in Gibs of Gory.

Offline The Martian

  • Commander
  • *****
  • Posts: 754
  • "It implores you to listen to its arguments..."
    • View Profile
Re: [Suggestion/Y-Scripts]setDeathFrames
« Reply #4 on: February 18, 2023, 10:47:25 am »
My mistake, sorry about that.

Offline Buscher

  • Colonel
  • ****
  • Posts: 168
    • View Profile
Re: [Suggestion/Y-Scripts]setDeathFrames
« Reply #5 on: February 18, 2023, 02:18:33 pm »
Don't worry about it.
It's great that you linked to Yankes's script which I didn't find at first either and that you pretty much documented the entire idea as well. Thank you.