Changing a weapon's sprites based on the ammunition loaded:
extended:
tags: # Remember to add these tags to the same file as items ruleset
RuleItem:
ALLOW_AMMO_TO_RESPRITE: int
NEW_BIGOB_FOR_WEAPON: int
NEW_FLOOROB_FOR_WEAPON: int
NEW_HANDOB_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;
ammoRuleset.getTag sprite_index Tag.NEW_BIGOB_FOR_WEAPON;
ammoRuleset.getTag modOffset Tag.CURRENT_MOD_OFFSET;
rules.getSpriteOffsetBigobs sprite_index modOffset;
return sprite_index;
end;
end;
end;
return sprite_index;
# Select weapon floorSprite based on ammo item
- offset: 2
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_floor;
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_FLOOROB_FOR_WEAPON;
if neq newSprite 0;
ammoRuleset.getTag sprite_index Tag.NEW_FLOOROB_FOR_WEAPON;
ammoRuleset.getTag modOffset Tag.CURRENT_MOD_OFFSET;
rules.getSpriteOffsetFloorob sprite_index modOffset;
return sprite_index;
end;
end;
end;
return sprite_index;
# Select weapon handSprite based on ammo item
- offset: 3
code: |
var ptr BattleItem ammoItem;
var ptr RuleItem weaponRuleset;
var ptr RuleItem ammoRuleset;
var int doResprite;
var int newSprite;
var int modOffset;
if or eq blit_part blit_item_lefthand eq blit_part blit_item_righthand;
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_HANDOB_FOR_WEAPON;
if neq newSprite 0;
add newSprite sprite_offset;
set sprite_index newSprite;
ammoRuleset.getTag modOffset Tag.CURRENT_MOD_OFFSET;
rules.getSpriteOffsetBigobs sprite_index modOffset;
return sprite_index;
end;
end;
end;
return sprite_index;
Set the tag ALLOW_AMMO_TO_RESPRITE: 1 on the weapon you wish to change sprites, then on the ammunition you wish to do the change for, set NEW_BIGOB_FOR_WEAPON, NEW_FLOOROB_FOR_WEAPON, and NEW_HANDOB_FOR_WEAPON tags to the sprites you want, and add CURRENT_MOD_OFFSET: current to the tags as well.
Note: with the way tags are handled, this will not change sprites if you choose a sprite index of 0. Also, since Handobs are lacking a proper function for getting the mod offset (coming in OXCE 3.7), this may not work if you have mods with different index offsets for handobs and bigobs - you can check your verbose log to see if the offsets are the same or not.
Also, this may not be useful if you want to have multiple weapons changing sprites but all share the same types of ammunition - I'll probably work fixing that at some point.