Author Topic: [Solved] Replacing weapon sprite depending of ammo.  (Read 4228 times)

Offline Nord

  • Commander
  • *****
  • Posts: 1747
  • The Gate is open.
    • View Profile
[Solved] Replacing weapon sprite depending of ammo.
« on: September 23, 2021, 12:08:26 pm »
I think i saw somewhere a mod, that changes sprites for loaded and empty guns in battlescape. But now i can not find nor it, nor these possibilities in ruleset or scripts.
Am i hallucinating?
« Last Edit: February 12, 2023, 03:16:03 pm by Meridian »

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9099
    • View Profile
Re: Replacing weapon sprite depending of ammo.
« Reply #1 on: September 23, 2021, 12:21:54 pm »
I think it was done in 40k, but maybe they have switched to something else... I found only recolor in v30.
Maybe try some earlier 40k version?

Forum search yielded this post from Yankes: https://openxcom.org/forum/index.php/topic,4880.msg70935.html#msg70935

or here from Ohartenstein: https://openxcom.org/forum/index.php/topic,5245.msg78316.html#msg78316

Offline Nord

  • Commander
  • *****
  • Posts: 1747
  • The Gate is open.
    • View Profile
Re: Replacing weapon sprite depending of ammo.
« Reply #2 on: September 23, 2021, 12:48:59 pm »
That's it, thank you.
Oh it is good to know that i am still sane.  :)

Ok. As i asked in a dead topic,
Quote
Excuse me, but i can not understand what
Code: [Select]

rules.getSpriteOffsetBigobs sprite_index temp;

doing.
Can you explain please?

(I thinked it is like "auto-adding mod offset when more than one mod is used" but looks like it is not working like that.)
I have done working script. But it stops working when i change mod load order. So i need to catch mod sprite offset.
Described command always gives me "1" in return. I think i do something wrong.
Here is a quote from my version of script:
Code: [Select]
extended:
    RuleItem:
#change sprite from ammo
      ALLOW_AMMO_TO_RESPRITE: int
      NEW_BIGOB_FOR_WEAPON: int
      CURRENT_MOD_OFFSET: RuleList
  scripts: 
    selectItemSprite:
# Select weapon bigSprite based on ammo item
      - offset: 1
        code: |
          var ptr BattleItem ammoItem;
          var ptr RuleItem weaponRuleset;
          var ptr RuleItem ammoRuleset;
          var int doResprite;
          var int newSprite;
          var int modOffset;

          if eq blit_part blit_item_big;
            item.getRuleItem weaponRuleset;
            weaponRuleset.getTag doResprite Tag.ALLOW_AMMO_TO_RESPRITE;

            if eq doResprite 1;
              item.getAmmoItem ammoItem;
              ammoItem.getRuleItem ammoRuleset;
              ammoRuleset.getTag newSprite Tag.NEW_BIGOB_FOR_WEAPON;

              if neq newSprite 0;
                set sprite_index newSprite;
                ammoRuleset.getTag modOffset Tag.CURRENT_MOD_OFFSET;
                rules.getSpriteOffsetBigobs sprite_index modOffset;
              end;

            end;

          end;

          return sprite_index;

items:
  - type: STR_DART_GUN
    tags:
      ALLOW_AMMO_TO_RESPRITE: 1
  - type: STR_DART_CLIP
    tags:
      NEW_BIGOB_FOR_WEAPON: 1154
      CURRENT_MOD_OFFSET: current
Help me please.
« Last Edit: September 23, 2021, 04:34:02 pm by Nord »

Offline Filip H

  • Squaddie
  • *
  • Posts: 6
    • View Profile
Re: Replacing weapon sprite depending of ammo.
« Reply #3 on: September 23, 2021, 01:50:40 pm »
Counter-Terrorist Operations, UNEXCOM: bureau 11 and OpenScarfCom also have scripts that do this

Offline Nord

  • Commander
  • *****
  • Posts: 1747
  • The Gate is open.
    • View Profile
Re: Replacing weapon sprite depending of ammo.
« Reply #4 on: September 23, 2021, 09:29:07 pm »
Counter-Terrorist Operations, UNEXCOM: bureau 11 and OpenScarfCom also have scripts that do this
I have researched them. All of them using little cheat: instead of giving plane new sprite number, they organize bigob sprites in a fixed order, and then just increase sprite index by a fixed number.
It is a way, though. And if i will not understand how to get mod sprite offset, then i can go that way and rearrange my sprites.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Replacing weapon sprite depending of ammo.
« Reply #5 on: October 01, 2021, 01:52:33 am »
Did you finally make it work? then I look on your script it look like it should work correctly. At least looking on overall structure, probably best way to handle case like this is to check what exactly this script do using `debug_log item "some message" 132;` where you can dump most data to logs and see what steps script do.

Offline efrenespartano

  • Commander
  • *****
  • Posts: 765
  • I know a lot about the law and other lawyerings.
    • View Profile
Re: Replacing weapon sprite depending of ammo.
« Reply #6 on: October 01, 2021, 08:02:51 am »
I have researched them. All of them using little cheat: instead of giving plane new sprite number, they organize bigob sprites in a fixed order, and then just increase sprite index by a fixed number.
It is a way, though. And if i will not understand how to get mod sprite offset, then i can go that way and rearrange my sprites.

It may look boring and/or overwhelming to do the changes on the indexes, specially if you had an extensive amount of sprites. But tbh, the change isn't as bad as it sounds. Actually, it's easier to organize the sprite indexes when the number is the same for all three of them.

Offline Nord

  • Commander
  • *****
  • Posts: 1747
  • The Gate is open.
    • View Profile
Re: Replacing weapon sprite depending of ammo.
« Reply #7 on: October 01, 2021, 09:24:04 am »
Did you finally make it work?
Yes, by rearranging "extraSprites" and changing "set sprite_index..." to "add sprite_index..."
Still dont understand how to get mod offset though.
You can look at working script in my "TWoTS" mod, with gas cannon for example.

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1512
    • View Profile
Re: Replacing weapon sprite depending of ammo.
« Reply #8 on: April 06, 2022, 06:30:17 am »
You can look at working script in my "TWoTS" mod, with gas cannon for example.
Thanks so much for getting this working! I'm borrowing the script from your mod as long as nobody minds!