aliens

Author Topic: [Answered] Script hooks  (Read 4005 times)

Offline mhdm

  • Squaddie
  • *
  • Posts: 4
    • View Profile
[Answered] Script hooks
« on: December 17, 2019, 01:25:34 am »
I want to add the description of the script hooks to the ruleset reference. Searching in the forums I found the ones for hitUnit and damageUnit but I was unable to find others if any of you know what they do and when they trigger I'll add them to the reference.

Still missing

Unit scripts
recolorUnitSprite
selectUnitSprite
selectMoveSoundUnit
reactionUnitAction
reactionUnitReaction
createUnit
newTurnUnit
returnFromMissionUnit
awardExperience
visibilityUnit

Item scripts
recolorItemSprite
selectItemSprite
reactionWeaponAction
createItem
newTurnItem
« Last Edit: February 12, 2023, 03:24:22 pm by Meridian »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3349
    • View Profile
Re: Script hooks
« Reply #1 on: December 17, 2019, 08:47:26 pm »
Unit scripts
recolorUnitSprite - run for each pixel of unit graphic (you can change color in any way you want)
selectUnitSprite - run for each part of unit graphic (you can replace what graphic is used for legs)
selectMoveSoundUnit - run for unit each step
reactionUnitAction - run for unit that did action that other unit react
reactionUnitReaction - run for unit that see action done by other unit
createUnit - run when new unit is created
newTurnUnit - run for each unit and "turn" (this men for human, alien and civilian turn)
returnFromMissionUnit - run for each unit ad when battle mission ends
awardExperience - run when unit can grain some exp from action
visibilityUnit - run when unit try see other unit

Item scripts
recolorItemSprite - run for each pixel of unit graphic
selectItemSprite - run to change floor graphic, hand graphic or battlescape graphic of item
reactionWeaponAction - run for weapon that did shoot and now some one else try react to it
createItem - run when item is creted
newTurnItem - run for each unit and "turn" (this men for human, alien and civilian turn)

Offline mhdm

  • Squaddie
  • *
  • Posts: 4
    • View Profile
Re: Script hooks
« Reply #2 on: December 18, 2019, 10:03:24 pm »
Wow thanks I'll add them to the reference. Btw there is no flag/hook that happens when a character turns to look around is there?. Can a flag related to the right mouse button be used?. I want to create a mod to allow some armors to look around without spending TU's figured I could use the recovery script every time they looked around to give them the TU's back but im guessing its not that easy.
« Last Edit: December 18, 2019, 10:16:41 pm by mhdm »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3349
    • View Profile
Re: Script hooks
« Reply #3 on: December 18, 2019, 10:31:06 pm »
all available hooks are listed in log when game is run in debug/verabatimlogging mode.

For changing cost using scripts, there is no hook for that and it will be none. If something like this could be possible then AI would be lot more complex to correctly handle behaviours like that. simply some thing is better leave hardcoded because other wise planning next action will be nightmare if in last moment script change cost of action.

Offline mhdm

  • Squaddie
  • *
  • Posts: 4
    • View Profile
Re: Script hooks
« Reply #4 on: December 20, 2019, 09:19:03 am »
I see thank you very much for your answers. I already added the information to the reference page.

Offline TBeholder

  • Sergeant
  • **
  • Posts: 41
    • View Profile
Re: [y-script] Script hooks
« Reply #5 on: December 30, 2022, 07:27:18 pm »
This helps, though needs some update.
However, one important detail the verbose log cannot give is when these scripts run.
It looks like when an unit provokes reaction, first the engine determines that reaction should happen, then scripts run in the order reactionWeaponAction (if the action was with a weapon), then reactionUnitAction, then reactionUnitReaction.
But when does selectItemSprite run? Apparently not just once when the item spawns, since it can be used to react on ammunition changes. Every time anything is done with an item? Every frame the item is on screen?..
It’s obviously important for FooBonusStats, too, and not obvious either.
And so on.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3349
    • View Profile
Re: [y-script] Script hooks
« Reply #6 on: December 30, 2022, 07:32:27 pm »
`selectItemSprite` is run every time when item is show, this mean it could be 60 times per second for every item visible on screen.
`*BonusStats` when game try "read" this stat, like when you attack someone using PSI then psi stats of attacker and victim need be calculated and scripts hooks for this stats are run.