Author Topic: [suggestion] Script Hook when moving item in paperdoll screen  (Read 1590 times)

Offline MaxMahem

  • Captain
  • ***
  • Posts: 60
    • View Profile
So a limitation apparently in the current library of scripts in use is that passive items (like shields or gas masks) are always "active." Regardless of where they are equipped. To enforce these items behaving logically, items are restricted in what equipment slots they can be placed in. So a gas mask can only be placed in the head slot, and a shield only in the hand slot. This is fine but eliminates the possibility of carrying a shield or a gas mask in one's inventory and equipping them when the situation calls for it. And also for picking up such "passive" items and carrying them off as loot without equipping them.

So I'm going through and enhancing some of the existing scripts with a modification that causes them only to execute when an item is in the proper location. Since the proper data is exposed in the newTurnItem hook, this can all be done with existing scripting tools which is great.

And for most items, the resulting functionality is fairly self-evident. It seems self-explanatory that a shield or a gas mask would only have an effect when worn in the proper location. But for various other items (for example, jewelry that provides a passive buff), it might not be.

For these situations, it would be beneficial to have a scripting hook that gets called after an item is moved to a new location on the paper doll, which can return a message that gets flashed to the user. Via this means feedback on the items state could be provided.

Additionally, this hook could be used to activate items that otherwise, I believe, would not have a chance to get activated (or deactivated) again until the next turn. Meaningful for reaction fire, for example. Currently, it is probably possible to drop a shield but retain its protection until the end of the turn in many mods. (Implementing this would probably mean a lot of code repetition, but I don't see a way around that with the current set of tools available).

It would be great if this would be exposed in all places the paper doll is exposed, the basescape equip screen, the pre-mission equip screen, and obviously, the in-mission equip screen. But probably not if it conflicts with the ability to "activate" equipment as described above.

I'm willing to take a stab at this if it does not seem unwanted, though I admit it would be a stretch given my current knowledge of the code base. But you know, that's how one grows (though I am more than willing to step aside if someone else wants to do it).

Offline MaxMahem

  • Captain
  • ***
  • Posts: 60
    • View Profile
Re: [suggestion] Script Hook when moving item in paperdoll screen
« Reply #1 on: March 12, 2023, 08:13:20 am »
It occurs to me that another way to provide feedback would be to change the item sprite to give a visual indicator of its state. Similar to the way grenades can be handled. Preferably this would be an additional sprite that could get layered on top. I know some modifications are possible with Y-scripts, but I didn't see any obvious way to change the bigItem value or something similar from within itemTurnRule and similar hooks, though I easily could have missed them.

Edit: Figured out a way to do this (recolorItemSprite I think) though a way to layer another sprite would still be nice.
« Last Edit: March 12, 2023, 09:10:05 am by MaxMahem »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [suggestion] Script Hook when moving item in paperdoll screen
« Reply #2 on: March 12, 2023, 11:05:34 am »
I bit reserved to add script that is called when you move item, it can have multiple unintended consequences that will be very hard to handle by engine (like killing unit when you give it a item).
My goal with scripts is that you can't crash game or make it inoperable and this hook is tricky to make it right as not only inventory but other game event would need to call it (unit creation, unit death/stun, reload item, etc).

Usually in case like this I use "read-only" scripts that do not change game state but in this case it will be pointless as you will not have any side effects.

Offline MaxMahem

  • Captain
  • ***
  • Posts: 60
    • View Profile
Re: [suggestion] Script Hook when moving item in paperdoll screen
« Reply #3 on: March 12, 2023, 11:13:00 am »
Usually in case like this I use "read-only" scripts that do not change game state but in this case it will be pointless as you will not have any side effects.

Maybe I am misunderstanding you, but to my understanding this would be fine for the primary use case, as I have no need to change the game's state in any way, only to display a transient message to the user (which could be seen as a state change I guess, but a very minor one).