aliens

Author Topic: [SOLVED][Support requested] Y-scripts and recoloring function  (Read 126 times)

Offline Aldorn

  • Commander
  • *****
  • Posts: 774
    • View Profile
Hello,

First, great job here and there, I am always surprised everytime I am back here ;D

So, after converting to V8.1, I spent several hours the past two days to download mods, download scripts, read topics, and try on my own in order to test the recolor function and see if it could be of any use for me

Let's say, mainly, I could recolor alien leaders and commanders

So I made several tests, globally it works, but I still have an issue and need help :-[


Let's see how it is by default (no script): Cf. Img000

Then with modding (script below) but doing nothing (i.e., recolor but with same color): Cf. Img001

I guessed it may be due to shade, but the result is the same with or without the 3 lines about shade (#Try shade)

Does any one understand why, aliens are lighter in Img001 compared to Img000? Globally, in Img001, mutons are more or less the same color as the one in the bottom left corner (center of access lift) on Img000


(Then next step will be to work with reinforcement and timers ::))


Thanks

Code: [Select]
  - type: MUTON_ARMOR0
    scripts:
      recolorUnitSprite: |
        var int CurrentColor;
        var int CurrentShade; #Try shade
        get_shade CurrentShade new_pixel; #Try shade
        get_color CurrentColor new_pixel;
        if eq CurrentColor COLOR_X1_GREEN0;
          set_color new_pixel COLOR_X1_GREEN0;
        end;
        set_shade new_pixel CurrentShade; #Try shade
        return new_pixel;
« Last Edit: March 27, 2025, 01:18:17 am by Aldorn »

Offline Yankes

  • Commander
  • Global Moderator
  • Commander
  • *****
  • Posts: 3462
  • Posts: 421
    • View Profile
Re: [Support requested] Y-scripts and recoloring function
« Reply #1 on: March 26, 2025, 09:09:03 pm »
Thing that you are missing is environment shading, you should consult first what default script is and then update it to fit your case.

Code: [Select]
unit.getRecolor new_pixel; add_burn_shade new_pixel burn shade; return new_pixel;
This is is default script and would be good if your code preserve it.
 
`unit.getRecolor` first is important as this is part of default functionality of recoloring hair/skin. If you remove it
then if was default Xcom solder armor then it will loose correct hair colors.
As bonus same functionality could even work for you case as you can define in ruleset what rank will have specific colors override.

`add_burn_shade` this function handle two functionalities: apply environment shade and another is fading out unit sprite when unit get overkill.


Offline Aldorn

  • Commander
  • *****
  • Posts: 774
    • View Profile
nd
« Reply #2 on: March 27, 2025, 01:07:16 am »
OMG I read the same answer you made there, but did not understand I had to include it just before my "return new_pixel;", sorry :-[
https://openxcom.org/forum/index.php?topic=10918.msg151126#msg151126

And I read and tried so many things that at the end I was a little bit disappointed

Thank you very much  :)


Let me share the final result in case anyone else might be interested in the future

Example of script that recolor mutons (those wearing armor0 only) from green to silver, without loosing shade, and recoloring only green part (i.e., not their head for example)
Code: [Select]
armors:
  - type: MUTON_ARMOR0
    scripts:
      recolorUnitSprite: |
        var int CurrentColor;
        get_color CurrentColor new_pixel; #Get current color
        if eq CurrentColor COLOR_X1_GREEN1; #Be sure to recolor only the green part
          set_color new_pixel COLOR_X1_SILVER #Change it to silver
        end;
        unit.getRecolor new_pixel;
        add_burn_shade new_pixel burn shade; #Do not forget to apply the shade
        return new_pixel;

As a reminder, the color constants
Code: [Select]
# COLOR_X1_YELLOW 1
# COLOR_X1_RED 2
# COLOR_X1_GREEN0 3
# COLOR_X1_GREEN1 4
# COLOR_X1_GRAY 5
# COLOR_X1_BROWN0 6
# COLOR_X1_BLUE0 7
# COLOR_X1_BLUE1 8
# COLOR_X1_BROWN1 9
# COLOR_X1_BROWN2 10
# COLOR_X1_PURPLE0 11
# COLOR_X1_PURPLE1 12
# COLOR_X1_BLUE2 13
# COLOR_X1_SILVER 14
# COLOR_X1_SPECIAL 15

Cf. Img003: all mutons are now of silver colour, except those wearing MUTON_ARMOR1 or MUTON_ARMOR2

Let me close this topic
« Last Edit: March 29, 2025, 03:43:32 pm by Aldorn »