Author Topic: [Example] Buffing Script  (Read 15417 times)

Offline Finnik

  • Commander
  • *****
  • Posts: 508
  • Finnik#0257
    • View Profile
[Example] Buffing Script
« on: November 23, 2018, 01:00:49 pm »
I decided to try to learn how to write Yankes scripts, at least at basic level, so here is my trial release (many thanks to ohartenstein23 for his invaluable help in understanding). This script allows you to set the weapon property (tag) to change the characteristics of the target, which hit the weapon. Stats will be changed to the end of the battle. For example, you can make a blinding gun, lowering Firing, or stim enjector, increasing TUs and, say, Bravery =)

all you need is to define tags in your item, like that:
Code: [Select]
items:
  - type: STR_BUFFER
    #categories: [STR_EQUIPMENT]
    size: 0.2
    costBuy: 10
    costSell: 8925
    weight: 9
    bigSprite: 8585
    floorSprite: 8586
    bulletSprite: 31
    fireSound: 15
    power: 5 #there must be a hit event to act the script
    damageType: 3
    damageAlter:
      ToHealth: 0.0   
    clipSize: -1
    accuracyAimed: 110
    tuAimed: 15
    battleType: 1
    twoHanded: false
    invWidth: 1
    invHeight: 2
    recoveryPoints: 2
    armor: 10
    attraction: 4
    listOrder: 39101
    tags: #here buff values can be set
      FTAG_BUFF_VALUE_TIMEUNITS: 20 #remember add renewable resources to damage alter if positive. this will only affect maximum value, not current
      FTAG_BUFF_VALUE_STAMINA: 20
      FTAG_BUFF_VALUE_HEALTH: 0
      FTAG_BUFF_VALUE_BRAVERY: -20 #negative means debuff
      FTAG_BUFF_VALUE_REACTIONS: 20
      FTAG_BUFF_VALUE_FIRING: 20
      FTAG_BUFF_VALUE_THROWING: 20
      FTAG_BUFF_VALUE_MELEE: 20
      FTAG_BUFF_VALUE_STRENGTH: 20
      FTAG_BUFF_VALUE_PSISTRENGTH: 20
      FTAG_BUFF_VALUE_PSISKILL: 20


I will be glad to know what do you think about it. Also any advice is very welcome  :D
« Last Edit: February 12, 2023, 02:26:04 pm by Meridian »

Offline Nord

  • Commander
  • *****
  • Posts: 1748
  • The Gate is open.
    • View Profile
Re: Buffing Script
« Reply #1 on: November 23, 2018, 02:06:08 pm »
It is fantastic!
But how about stat overflow?

Offline Finnik

  • Commander
  • *****
  • Posts: 508
  • Finnik#0257
    • View Profile
Re: Buffing Script
« Reply #2 on: November 23, 2018, 02:14:53 pm »
I have not faced any problems with it yet. I tried on testing with TUs to be set above 200, everything was fine. also, stats cant be lower 1, so if calculations leads to it, 1 is set instead. But more expirience opinion required for full overview

Offline Nord

  • Commander
  • *****
  • Posts: 1748
  • The Gate is open.
    • View Profile
Re: Buffing Script
« Reply #3 on: November 23, 2018, 02:58:12 pm »
As i remember, in vanilla was a bug, when unit stats increases over 256, they become 1.

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11736
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Buffing Script
« Reply #4 on: November 23, 2018, 03:14:47 pm »
As i remember, in vanilla was a bug, when unit stats increases over 256, they become 1.

This is in no way related to OXC code, which allows stats of pretty much any value (up to millions).

Offline Nord

  • Commander
  • *****
  • Posts: 1748
  • The Gate is open.
    • View Profile
Re: Buffing Script
« Reply #5 on: November 23, 2018, 03:45:42 pm »
Then we have pretty good stimpacks and magic spells now. :)

Offline efrenespartano

  • Commander
  • *****
  • Posts: 765
  • I know a lot about the law and other lawyerings.
    • View Profile
Re: Buffing Script
« Reply #6 on: November 23, 2018, 05:09:28 pm »
I decided to try to learn how to write Yankes scripts, at least at basic level, so here is my trial release (many thanks to ohartenstein23 for his invaluable help in understanding). This script allows you to set the weapon property (tag) to change the characteristics of the target, which hit the weapon. Stats will be changed to the end of the battle. For example, you can make a blinding gun, lowering Firing, or stim enjector, increasing TUs and, say, Bravery =)

all you need is to define tags in your item, like that:

I will be glad to know what do you think about it. Also any advice is very welcome  :D

Wonderful, Finnik! This is what I looked for! I have planned to make a Combat Whistle, and a Combat Bagpipes so you could encourage your troops to not die and this could be very useful to get the desired effect.

Thank you for making this.



Enviado desde mi iPhone utilizando Tapatalk

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3355
    • View Profile
Re: Buffing Script
« Reply #7 on: November 23, 2018, 09:55:46 pm »
This is in no way related to OXC code, which allows stats of pretty much any value (up to millions).
But not scripts :> I made deliberate decision to cap stats, upper limit is 1000 (I expects that mods use 100-200 value range, and I multiply it by 5).
Another thing is that is I reduce size of variable that store stats from `int32` to `int16`, this mean right now value is 32*1024. I did that because even you have more that 4GiB free memory, processor memory cache have only couple of MiB and if something not fit it then code is 1000 time slower.

And another thing is low limit, any stat can't have value less than 1, if you did that lot of game logic could go haywire.

Offline Finnik

  • Commander
  • *****
  • Posts: 508
  • Finnik#0257
    • View Profile
Re: Buffing Script
« Reply #8 on: November 25, 2018, 06:11:36 pm »
also ive made script for temporal buff/debuff (it will be off in a set ammount of turns)  :D  so i can design any buff effect if needed. some example:

i wonder, if i can set any visual effect to a unit with my debuff tag? without making something really huge for recolorUnitSprite
« Last Edit: November 25, 2018, 06:47:03 pm by Finnik »

Offline efrenespartano

  • Commander
  • *****
  • Posts: 765
  • I know a lot about the law and other lawyerings.
    • View Profile
Re: Buffing Script
« Reply #9 on: November 25, 2018, 07:20:46 pm »
also ive made script for temporal buff/debuff (it will be off in a set ammount of turns)  :D  so i can design any buff effect if needed. some example:

Thank you! I was about to suggest you something like this, actually.

Do you updated the download link?


Enviado desde mi iPhone utilizando Tapatalk

Offline Finnik

  • Commander
  • *****
  • Posts: 508
  • Finnik#0257
    • View Profile
Re: Buffing Script
« Reply #10 on: November 25, 2018, 08:23:37 pm »
not yet, as it will be different script. the one above is specially designed to work with any stat, and now im working on specific daze buff. fading mecanic is much more complicated, so i will be desigh buffs/debuffs separetly if desired, and buff mecanic will be hardcoded. so for now Daze debuff work lowering reactions, but now im setting it to lowering TU by half of original, Reactions buy -30, Firing and trowing -25 and Melee by -15. this is subject of balance talking, but im not feeling ill let modders to change values via tag sets with numbers.

but the code for effect, that was in video is attached here (note, that mod itself is not standalone, its submod for XCF, but i can use script from it in way you like)
« Last Edit: November 25, 2018, 08:29:36 pm by Finnik »

Offline efrenespartano

  • Commander
  • *****
  • Posts: 765
  • I know a lot about the law and other lawyerings.
    • View Profile
Buffing Script
« Reply #11 on: November 25, 2018, 09:45:49 pm »
In my particular opinion, it would be good if you gave modders flexibility to adapt this new temporary script, even if it did not have the different animation.

In case you decide that this temporary buff will be fixed, I present what I have in mind with your script:

Medikit: heals wounds and contains analgesics and stimulants (the same as the vanilla medikit)

Campaign surgery kit: the same as the Medikit, but much better. (Extra +5 Health, +2 Stamina)

Trench Whistle: encourages the troops, raises the reactions and courage. (+7 TU, +10 Bravery, +5 reactions)

Combat Bagpipe: increases bravery, slightly strength, melee damage and stamina (+3 TU, +15 Bravery, +3 Strength, +4 Melee, +4 Stamina)

Bandages: for bleeding and recover a little health. (Stops bleeding, +3 health)

Combat drugs: it increases the precision, the reactions, the force, but reduces the health. (+5 Firing, +10 Reactions, +7 Strength, -8 Health)

Flamethrower: well... is a flamethrower, but reduces enemy reactions and bravery to emule the fear of being roared alive (-10 Reactions, -5 Bravery)

Most of them for three turns, except the medikits and surgery lit, these are more like vanilla medikit.

As you can see, I have many plans for your script, Finnik. :)


Enviado desde mi iPhone utilizando Tapatalk
« Last Edit: November 25, 2018, 09:55:41 pm by efrenespartano »

Offline Finnik

  • Commander
  • *****
  • Posts: 508
  • Finnik#0257
    • View Profile
Re: Buffing Script
« Reply #12 on: November 26, 2018, 12:28:53 am »
In my particular opinion, it would be good if you gave modders flexibility to adapt this new temporary script, even if it did not have the different animation.

In case you decide that this temporary buff will be fixed, I present what I have in mind with your script:

Medikit: heals wounds and contains analgesics and stimulants (the same as the vanilla medikit)

Campaign surgery kit: the same as the Medikit, but much better. (Extra +5 Health, +2 Stamina)

we cant set Yankes script for medcit use.

Trench Whistle: encourages the troops, raises the reactions and courage. (+7 TU, +10 Bravery, +5 reactions)

Combat Bagpipe: increases bravery, slightly strength, melee damage and stamina (+3 TU, +15 Bravery, +3 Strength, +4 Melee, +4 Stamina)
can be done with first script

Bandages: for bleeding and recover a little health. (Stops bleeding, +3 health)

can be done without scripting with OXCE

Flamethrower: well... is a flamethrower, but reduces enemy reactions and bravery to emule the fear of being roared alive (-10 Reactions, -5 Bravery)
there are mecanics for it already

Most of them for three turns, except the medikits and surgery lit, these are more like vanilla medikit.

can be done without scripting with OXCE

you know, tracking debuff end restore stut to its original value is pretty comlycated thing, so if you can satisfy with permanent buff from first script - just mod and item like i describe above
if you want to make trackable debuff - ill better teach you how to script it =) i dont think trackable debuff made verstile with tags will be unreosanable comlicated both to wright and use for modders

--- posts merged ---

what do you think, guys? this script makes daze on a target, hitted with proper item and fade out in set ammount of turns
Code: [Select]
extended:
  tags:
    RuleItem:
      FTAG_DAZE_VALUE: int
      FTAG_DAZE_TIME: int
    BattleUnit:
      FTAG_ISDAZED: int #not shure about it
      FTAG_DAZE_ENDTURN: int
      FTAG_DAZE_ORIGINAL_TIMEUNITS: int
      FTAG_DAZE_ORIGINAL_REACTIONS: int
      FTAG_DAZE_ORIGINAL_FIRING: int
      FTAG_DAZE_ORIGINAL_THROWING: int
      FTAG_DAZE_ORIGINAL_MELEE: int
  scripts:
    hitUnit:
      - offset: 1
        code: |
          var ptr RuleItem itemRuleset;
          var int dazeTag;
          var int dazeValue;
          var int statValue;
          var int debuffValue;
          var int dazeTime;
          var int endTurn;
   
          unit.getTag dazeTag Tag.FTAG_ISDAZED;
          if eq dazeTag 69; # Make sure unit already have daze debuff
            return power part side;
          end;

          set dazeTag 69; #set dazed tag
          unit.setTag Tag.FTAG_ISDAZED dazeTag;

          damaging_item.getRuleItem itemRuleset; #get debuff stats from item
          itemRuleset.getTag dazeValue Tag.FTAG_DAZE_VALUE;
          itemRuleset.getTag dazeTime Tag.FTAG_DAZE_TIME;

          if neq dazeValue 0;
            unit.Stats.getTimeUnits statValue; #remember original TimeUnits stat
            unit.setTag Tag.FTAG_DAZE_ORIGINAL_TIMEUNITS statValue;
         
            div statValue 2; #calculate TimeUnits debuff, deviding it by 2
            unit.Stats.setTimeUnits statValue; #apply debuff
            clear statValue;

            unit.Stats.getReactions statValue; #remember original Reactions stat
            unit.setTag Tag.FTAG_DAZE_ORIGINAL_REACTIONS statValue;
            battle_game.randomRange debuffValue 25 35; #calculate random, 25-35 for Reactions
            mul debuffValue dazeValue; #calculate debuff
            sub statValue debuffValue;
            unit.Stats.setReactions statValue; #apply Reactions  debuff
            clear statValue;
            clear debuffValue;

            unit.Stats.getFiring statValue; #remember original Firing stat
            unit.setTag Tag.FTAG_DAZE_ORIGINAL_FIRING statValue;
            battle_game.randomRange debuffValue 20 30; #calculate random, 20-30 for Firing
            mul debuffValue dazeValue; #calculate debuff
            sub statValue debuffValue;
            unit.Stats.setFiring statValue; #apply debuff
            clear statValue;
            clear debuffValue;

            unit.Stats.getThrowing statValue; #remember original Throwing stat
            unit.setTag Tag.FTAG_DAZE_ORIGINAL_THROWING statValue;
            battle_game.randomRange debuffValue 20 30; #calculate random, 20-30 for Throwing
            mul debuffValue dazeValue; #calculate debuff
            sub statValue debuffValue;
            unit.Stats.setThrowing statValue; #apply debuff
            clear statValue;
            clear debuffValue;

            unit.Stats.getMelee statValue; #remember original Melee stat
            unit.setTag Tag.FTAG_DAZE_ORIGINAL_MELEE statValue;
            battle_game.randomRange debuffValue 10 20; #calculate random, 10-20 for Melee
            mul debuffValue dazeValue; #calculate debuff
            sub statValue debuffValue;
            unit.Stats.setMelee statValue; #apply debuff
            clear statValue;
            clear debuffValue;

            battle_game.getTurn endTurn;
            add endTurn dazeTime; #define end turn for debuff
            unit.setTag Tag.FTAG_DAZE_ENDTURN endTurn;
          end;

          return power part side;

    newTurnUnit:
      - offset: 2
        code: |
          var int currTurn;
          var int endTurn;
          var int dazeTag;
          var int originalTimeUnits;
          var int originalReactions;
          var int originalFiring;
          var int originalThrowing;
          var int originalMelee;

          # Make sure this doesn't run an extra time when civilians have a turn
          if eq side 2;
            return;
          end;

          unit.getTag dazeTag Tag.FTAG_ISDAZED;
          unit.getTag endTurn Tag.FTAG_DAZE_ENDTURN;
          unit.getTag originalTimeUnits Tag.FTAG_DAZE_ORIGINAL_TIMEUNITS;
          unit.getTag originalReactions Tag.FTAG_DAZE_ORIGINAL_REACTIONS;
          unit.getTag originalFiring Tag.FTAG_DAZE_ORIGINAL_FIRING;
          unit.getTag originalThrowing Tag.FTAG_DAZE_ORIGINAL_THROWING;
          unit.getTag originalMelee Tag.FTAG_DAZE_ORIGINAL_MELEE;

          battle_game.getTurn currTurn;

          if eq dazeTag 69;
            if eq currTurn endTurn;
              unit.Stats.setTimeUnits originalTimeUnits; #revent debuff
              unit.Stats.setReactions originalReactions;
              unit.Stats.setFiring originalFiring;
              unit.Stats.setThrowing originalThrowing;
              unit.Stats.setMelee originalMelee;
              unit.setTag Tag.FTAG_ISDAZED 0; #cancel tag
            end;
          end;

          return;

im hardcoded parameters of daze debuff, it halfs TUs, decrease reactions by 25-35, firing and throwing by 20-30, and melee by 10-20. numbers are subject of balance talking.

you still can adjust values. place this in your item.rul

Code: [Select]
    tags:
      FTAG_DAZE_VALUE: 1 #this is multiplyer to numbers above. if lower than 1, debuff will be weaker, if higher - stronger
      FTAG_DAZE_TIME: 2 #number of turns before fading

here is example mod. note, its is submod for XCF, which, btw, i strongly recommend to check out https://openxcom.mod.io/the-x-com-files
« Last Edit: November 26, 2018, 10:12:35 am by Solarius Scorch »

Offline efrenespartano

  • Commander
  • *****
  • Posts: 765
  • I know a lot about the law and other lawyerings.
    • View Profile
Re: Buffing Script
« Reply #13 on: November 26, 2018, 07:35:36 am »

you know, tracking debuff end restore stut to its original value is pretty comlycated thing, so if you can satisfy with permanent buff from first script - just mod and item like i describe above
if you want to make trackable debuff - ill better teach you how to script it =) i dont think trackable debuff made verstile with tags will be unreosanable comlicated both to wright and use for modders

As you indicate, seems that medical stuff could use codes mostly based on OXCE existent stuff, I'll give them a check:)

If you think my ideas could be done using the first script, it's OK, then. I'll use it. :) Thank you for making this! I'll keep an eye on your project. 

Offline Finnik

  • Commander
  • *****
  • Posts: 508
  • Finnik#0257
    • View Profile
Re: Buffing Script
« Reply #14 on: November 26, 2018, 10:54:42 am »
TY! problem is im using hitUnit hook in Yankes script to set up debuff(buff) effect from item, so you actually need to hit with that item. it can be done with firing, melee, grenede or thing like my flashbang above, but you need a hit. as far as i know, medkit is not a hit event.