Author Topic: [Example] Handcuffs script  (Read 17072 times)

Offline Kozinsky

  • Colonel
  • ****
  • Posts: 128
  • Sorry for my bEd English
    • View Profile
Re: [Script] Handcuffs
« Reply #15 on: May 04, 2020, 08:51:14 am »
Quick question, where do you find this relationship in the save? Basically, what I'm asking is, will the handcuffs work if you handcuff something, save the game, and load it? I can't find it on the unit id in the save.

For a unit, two lines "IS_HANDCUFFED" and "VIRTUAL_STUN_LEVEL" will appear in the "tags" section. If this did not happen, then the handcuffs could not be put on.
Are there any records in the file "openxcom.log"?

Offline vadracas

  • Colonel
  • ****
  • Posts: 285
  • Just another player/modder combo.
    • View Profile
Re: [Script] Handcuffs
« Reply #16 on: May 04, 2020, 12:12:05 pm »
I received no data in the log, and it did consume my handcuffs, which gave me the impression that what I had used the cuffs on must have been cuffed. However, I was suspicious when I saw nothing in the log, and more so when there wasn't a handcuffed tag on the unit In question(a zombie boomer since I had limited electrical and couldn't afford to let him stand again).

Offline Kozinsky

  • Colonel
  • ****
  • Posts: 128
  • Sorry for my bEd English
    • View Profile
Re: [Script] Handcuffs
« Reply #17 on: May 04, 2020, 12:28:15 pm »
I received no data in the log, and it did consume my handcuffs, which gave me the impression that what I had used the cuffs on must have been cuffed. However, I was suspicious when I saw nothing in the log, and more so when there wasn't a handcuffed tag on the unit In question(a zombie boomer since I had limited electrical and couldn't afford to let him stand again).

This is very strange. It looks like your version of OXCE doesn't support scripts - in this case the handcuffs behave like a normal stimulant. Maybe you made a syntax mistake when using my script in your mod? And when you run OXCE, script was ignored, while loading, with the corresponding message in "openxcom.log".

Offline vadracas

  • Colonel
  • ****
  • Posts: 285
  • Just another player/modder combo.
    • View Profile
Re: [Script] Handcuffs
« Reply #18 on: May 04, 2020, 02:43:13 pm »
This is very strange. It looks like your version of OXCE doesn't support scripts - in this case the handcuffs behave like a normal stimulant. Maybe you made a syntax mistake when using my script in your mod? And when you run OXCE, script was ignored, while loading, with the corresponding message in "openxcom.log".


Well, I am using OXCE 6.4.6(compiled on my mac) and the mod with the handcuffs is Solarius's xcomfiles downloaded the latest release from github. When I checked his script, it doesn't have entries to the log, so no surprise there, but I do see that it is supposed to give the unit a tag.

Offline Kozinsky

  • Colonel
  • ****
  • Posts: 128
  • Sorry for my bEd English
    • View Profile
Re: [Script] Handcuffs
« Reply #19 on: May 04, 2020, 03:23:41 pm »

Well, I am using OXCE 6.4.6(compiled on my mac) and the mod with the handcuffs is Solarius's xcomfiles downloaded the latest release from github. When I checked his script, it doesn't have entries to the log, so no surprise there, but I do see that it is supposed to give the unit a tag.
Tested the latest version of XCF from GitHub - everything works well for civilians. Maybe you have some kind of specific creature you're handcuffing?

Offline vadracas

  • Colonel
  • ****
  • Posts: 285
  • Just another player/modder combo.
    • View Profile
Re: [Script] Handcuffs
« Reply #20 on: May 04, 2020, 03:35:38 pm »
Zombie Boomer

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11722
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [Script] Handcuffs
« Reply #21 on: May 05, 2020, 10:40:04 am »
Yeah, I removed the log outputs on Kozinsky's advice. I understand its purpose was beta-testing.

Zombie Boomers are probably way too strong to care much about puny handcuffs...

Offline vadracas

  • Colonel
  • ****
  • Posts: 285
  • Just another player/modder combo.
    • View Profile
Re: [Script] Handcuffs
« Reply #22 on: May 05, 2020, 12:44:33 pm »
Yeah, I removed the log outputs on Kozinsky's advice. I understand its purpose was beta-testing.

Zombie Boomers are probably way too strong to care much about puny handcuffs...


That's perfectly reasonable, however, I was under the impression the handcuffs wouldn't be consumed if it failed based on this thread?

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11722
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [Script] Handcuffs
« Reply #23 on: May 05, 2020, 12:57:52 pm »

That's perfectly reasonable, however, I was under the impression the handcuffs wouldn't be consumed if it failed based on this thread?

Both this mod and XCF very clearly state that the handcuffs will be consumed even when unsuccessful.

Offline vadracas

  • Colonel
  • ****
  • Posts: 285
  • Just another player/modder combo.
    • View Profile
Re: [Script] Handcuffs
« Reply #24 on: May 05, 2020, 03:11:05 pm »
Because you spend last charge, if you block it, game would not remove your item.
Probably most correct way to do it is set `medikit_action_type` to zero if you are prevented doing any thing.

What does this mean then?

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Script] Handcuffs
« Reply #25 on: May 05, 2020, 06:57:15 pm »
Item is removed because all charges are set to zero,
and they are set because default medkit logic was run after script,
and it was run because script allowed it.

To fix it you need set in script property I show to block default medkit behavior.

This is clear?


Offline vadracas

  • Colonel
  • ****
  • Posts: 285
  • Just another player/modder combo.
    • View Profile
Re: [Script] Handcuffs
« Reply #26 on: May 05, 2020, 07:14:37 pm »
Yes, thank you.

Offline Kozinsky

  • Colonel
  • ****
  • Posts: 128
  • Sorry for my bEd English
    • View Profile
Re: [Script] Handcuffs
« Reply #27 on: May 05, 2020, 09:17:28 pm »
Because you spend last charge, if you block it, game would not remove your item.
Probably most correct way to do it is set `medikit_action_type` to zero if you are prevented doing any thing.
Could you give me an example?

What I need:
I check some condition through "if ... else ... end".
If the condition is "true", the medikit should disappear and the soldier should spend TU and energy to use the medikit (according to the "costUse" block of the item).
If the condition is "false", nothing should happen, the soldier should not waste TU and energy on using the medikit.

What I've done:
If the condition is "true" the medikit is used according to the rules of the game - it disappears, and the soldier spends TU and energy.
If the condition is "false", I restore the charge to the medikit and return the spent TU and energy to the soldier:
Code: [Select]
    healUnit:
      - offset: 1
        code: |
          var int CurrEnergy 0;
          var int CurrTU 0;
...
          if ...
...
          else ...
            actor.getEnergy CurrEnergy;
            actor.getTimeUnits CurrTU;
            add CurrEnergy 10;
            add CurrTU 40;           
            item.setStimulantQuantity 1;
            actor.setEnergy CurrEnergy;
            actor.setTimeUnits CurrTU;
          end;

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Script] Handcuffs
« Reply #28 on: May 05, 2020, 10:46:53 pm »
Instead of
Code: [Select]
item.setStimulantQuantity 1;
you should use

Code: [Select]
set medikit_action_type 0;

This will prevent code that is run after script that change number of `setStimulantQuantity`.

Offline Kozinsky

  • Colonel
  • ****
  • Posts: 128
  • Sorry for my bEd English
    • View Profile
Re: [Script] Handcuffs
« Reply #29 on: May 06, 2020, 09:23:46 am »
Code: [Select]
set medikit_action_type 0;

It doesn't work. The medikit disappears, and the soldier loses TU and energy.

Code: [Select]
items:
  - type: STR_HANDCUFFS
    medikitType: 2
    medikitTargetSelf: false
    medikitTargetImmune: true
    medikitTargetMatrix: 21
    medikitActionName: STR_HANDCUFFS_ACTION
    stimulant: 1
    stunRecovery: 0
    isConsumable: true
    costUse:
      time: 40
      energy: 10

extended:
  scripts:
    healUnit:
      - offset: 1
        code: |
          var int CurrEnergy 0;
          var int CurrTU 0;
...
          if ...
...
          else ...
            #actor.getEnergy CurrEnergy;
            #actor.getTimeUnits CurrTU;
            #add CurrEnergy 10;
            #add CurrTU 40;           
            #item.setStimulantQuantity 1;
            #actor.setEnergy CurrEnergy;
            #actor.setTimeUnits CurrTU;
            set medikit_action_type 0;
          end;
« Last Edit: May 06, 2020, 12:04:57 pm by Kozinsky »