OpenXcom Forum
Modding => OXCE Support => OpenXcom Extended => OXCE Support Y-scripts => Topic started by: Nord on August 09, 2021, 09:18:28 am
-
Continuing this discussion:
https://openxcom.org/forum/index.php/topic,9992.0.html (https://openxcom.org/forum/index.php/topic,9992.0.html)
I managed to create an item, which represents shield power. It is built-in in armor, and updates each turn.
But now i want to update it each time the unit is hit. And i can not gain access to this item from "hitUnit:" script hook.
Is this even possible?
-
`getSpecialItem` and `getSpecialItem.size` is used to access unit buildin weapons.
You need iterate for each weapon to find one you want.
-
So, if a unit have more than one builtInWeapons, how must i search through them?
Include internal cycle in hitUnit?
Can you provide some kind of example?
Pleeeease.
Thanks.
-
You can consider this example if you like
newTurnUnit:
- offset: 20
code: |
...
var int temp;
var int numInventoryItems;
var ptr RuleItem rItem;
var ptre BattleItem tempItem;
var ptre BattleItem itemDummy;
var ptre BattleItem itemWeapon;
...
unit.getSpecialItem itemWeapon 0; # might need a sanity check with getSpecialItem.size
itemWeapon.getRuleItem rItem;
rItem.getTag temp Tag.ITEM_IS_VOX_WEAPON;
if neq temp 1;
return;
end;
unit.getInventoryItem.size numInventoryItems;
loop var i numInventoryItems;
unit.getInventoryItem tempItem i;
tempItem.getRuleItem rItem;
rItem.getTag temp Tag.ITEM_IS_VOX_DUMMY;
if and eq temp 1 eq itemDummy null;
unit.getInventoryItem itemDummy i;
end;
end;
...
return;
-
You can consider this example if you like
newTurnUnit:
- offset: 20
code: |
...
var int temp;
var int numInventoryItems;
var ptr RuleItem rItem;
var ptre BattleItem tempItem;
var ptre BattleItem itemDummy;
var ptre BattleItem itemWeapon;
...
unit.getSpecialItem itemWeapon 0; # might need a sanity check with getSpecialItem.size
itemWeapon.getRuleItem rItem;
rItem.getTag temp Tag.ITEM_IS_VOX_WEAPON;
if neq temp 1;
return;
end;
unit.getInventoryItem.size numInventoryItems;
loop var i numInventoryItems;
unit.getInventoryItem tempItem i;
tempItem.getRuleItem rItem;
rItem.getTag temp Tag.ITEM_IS_VOX_DUMMY;
if and eq temp 1 eq itemDummy null;
unit.getInventoryItem itemDummy i;
end;
end;
...
return;
"newTurnUnit" is not what i seek. I want to look into "hitUnit" hook.
-
You were asking how to access a specialWeapon and it makes (nearly) zero difference in syntax if it is a newTurnUnit hook or a hitUnit hook. It should work the same.
'attacker' as well as 'unit' are accessible and editable (ptre BattleUnit) for both script hooks. This means that your specialWeapon is also editable (ptre BattleItem). You don't even have to change anything in the example to access it with the variable 'itemWeapon' from the example.
-
Ok, i think i got it.
If in "unit.getSpecialItem itemWeapon 0;" 0 - is the special weapon's index number.
I should try. Thank you.
Upd. 2: It works!
Thank you very much!