Author Topic: [Solved] Shields. Scripts reference.  (Read 4411 times)

Offline tkzv

  • Commander
  • *****
  • Posts: 583
    • View Profile
[Solved] Shields. Scripts reference.
« on: October 19, 2017, 07:00:21 pm »
Is there any page with reference manual for scripts in OXCE+ ? I'm trying to write a mod that would give a shield that would add armour points to front+side or back. I tried to figure how it was done in Piratez and got lost. So far I only managed to cut out everything, leaving only a single shield. I did not include the scripts from Piratez, thus the Ufopaedia description is incorrect.

What do I need to alter the operative's armour depending on the shield placement (left arm, right arm, back or none)?

Note to self: https://www.ufopaedia.org/index.php/Ruleset_Reference_OpenXcom_Extended_Plus_(OpenXcom) doesnt't have it.

P.S. If I build the OXCE+ source with "make doxygen", will it give anything useful?
« Last Edit: February 12, 2023, 02:22:53 pm by Meridian »

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Shields. Scripts reference.
« Reply #1 on: October 19, 2017, 09:05:48 pm »
You need to write the script code in order to do this.  The Yankes_Scripts.rul file from Piratez contains all the script code for the mod, but just for the features that are used in the mod.  If you want to do something like changing armor values based on the placement of an item, then you'll need your own code to do that, since it's not an already-written script.  The documentation for scripts is pretty sparse, just the output from the log file with debug mode and verbose logging on and the examples posted on the forums, plus the Piratez script file.

Offline tkzv

  • Commander
  • *****
  • Posts: 583
    • View Profile
Re: Shields. Scripts reference.
« Reply #2 on: October 19, 2017, 11:13:22 pm »
You need to write the script code in order to do this. The Yankes_Scripts.rul file from Piratez contains all the script code for the mod, but just for the features that are used in the mod.  If you want to do something like changing armor values based on the placement of an item, then you'll need your own code to do that, since it's not an already-written script.
Yes, I figured that. That's why I asked :)

The documentation for scripts is pretty sparse, just the output from the log file with debug mode and verbose logging on and the examples posted on the forums, plus the Piratez script file.
Thanks! But Yankes_Scripts.rul is where I got lost.

What language is this?

What does "muldiv shieldArmor 100 shieldResistCoeff;" mean?
shieldArmor = shieldArmor * 100 / shieldResistCoeff ?
Or shieldResistCoeff = shieldResistCoeff * 100 / shieldArmor  ?

What about "or eq damaging_type 0 eq damaging_type 9 eq damaging_type 10 eq damaging_type 11;"?
Does or combine all 4 "damaging_type == X" or only the last 2?
How can it tell if it's binary or quaternary?

What in the script sets the action that triggers the script? Or how is it triggered?

How can a script check if the item is equipped or the item's position in the inventory?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Shields. Scripts reference.
« Reply #3 on: October 20, 2017, 01:10:03 am »
The language is Yankes' own, the description of all the functions is in that log output I linked to you.

Yes, I figured that. That's why I asked :)
What does "muldiv shieldArmor 100 shieldResistCoeff;" mean?
shieldArmor = shieldArmor * 100 / shieldResistCoeff ?
Or shieldResistCoeff = shieldResistCoeff * 100 / shieldArmor  ?

It means shieldArmor = shieldArmor * 100 / shieldResistCoeff, all mathematical operations put the output in the first variable.

Quote
What about "or eq damaging_type 0 eq damaging_type 9 eq damaging_type 10 eq damaging_type 11;"?
Does or combine all 4 "damaging_type == X" or only the last 2?
How can it tell if it's binary or quaternary?

Boolean operators apply to the whole line, so the next few lines run if the damage type is any of 0, 9, 10, or 11.

Quote
What in the script sets the action that triggers the script? Or how is it triggered?

The name of the script sets that, the one you're looking at is "onHit", so it runs whenever a unit is hit.

Quote
How can a script check if the item is equipped or the item's position in the inventory?

Position in inventory isn't an available variable (see the log output file), but you can check for whether an item is in one hand or another, or whether the item has an owner (is in some unit's inventory).  You also can't search for items in a unit's inventory, only check the hands, or run a script every turn for each item.

Offline tkzv

  • Commander
  • *****
  • Posts: 583
    • View Profile
Re: Shields. Scripts reference.
« Reply #4 on: October 20, 2017, 01:51:49 am »
The name of the script sets that, the one you're looking at is "onHit", so it runs whenever a unit is hit.
This name isn't anywhere in the files you gave. Or anywhere in the OXCE+ source. The closest words are "getExplosionHitSound", "explosionHitSound" and "_explosionHitSound". Are you sure?

Besides, I'd prefer to change the values when an operative takes the shield in his hand or puts it in inventory. Takes the shield, armour increases for front and shield hand. Put it in another hand — armour is reset, then increased for front and the other side. Puts it in inventory — armour increases for rear. Has no shield — standard armour.

Position in inventory isn't an available variable (see the log output file),
Well, it can only fit the backpack, anyway.

but you can check for whether an item is in one hand or another, or whether the item has an owner (is in some unit's inventory).  You also can't search for items in a unit's inventory, only check the hands, or run a script every turn for each item.
Do you mean every player's and every enemy's turn for ITEM_STUN_PER_TURN, ITEM_ENERGY_PER_TURN, ITEM_MORALE_PER_TURN?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Shields. Scripts reference.
« Reply #5 on: October 20, 2017, 02:12:46 am »
Sorry, the name is 'hitUnit'.

There aren't any script hooks for moving items in inventory, so that's a no-go. My workaround is to check left or right hands when a unit is hit, then subtract the shields armor tag value from the power of the hit.

The other workaround is to use 'newTurnItem' scripts, which run once for every item at the beginning of both your and the alien's turns. See the item resistance tags and code; each turn, the item runs some code and if the right conditions are met, a tag is set on the unit with the item. Then, when that unit is hit, I have the script look for that tag to reduce the damage taken. It's clunky, but it gets the job done.

Edit: The ALL_CAPS variables are tags that are read in by the newTurnItem script to do exactly what they're named to do.
« Last Edit: October 20, 2017, 02:21:03 am by ohartenstein23 »