OpenXcom Forum

Modding => Help => Topic started by: Nirran on November 16, 2023, 06:36:22 am

Title: Prevent Chryssalid Insta Kill
Post by: Nirran on November 16, 2023, 06:36:22 am
my script triggers on the hit but soldier dies anyway,looked at script ,donno what to look for

any way to prevent the transformation with scripts?4
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nord on November 16, 2023, 11:18:08 am
you need scripthook "damageSpecialUnit"
in which you should modify variable "transform_chance".
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 16, 2023, 11:02:42 pm
you need scripthook "damageSpecialUnit"
in which you should modify variable "transform_chance".


Thnx Dude

question: this obviously isnt the entirte hook list,mind dirrecting me to the complete list?

Code: [Select]
    Unit scripts
        recolorUnitSprite: Runs for every pixel of a units graphic. Change to any color.
        selectUnitSprite: Runs for every part of a units graphic. E.g. Change the graphic used for legs.
        selectMoveSoundUnit: Runs for each unit step.
        reactionUnitAction: Runs when an unit performs an action that triggers reaction fire.
        reactionUnitReaction: Runs when a unit sees another unit perform an action that triggers reaction fire.
        hitUnit: When a unit is hit it allows adjusting damage and the part of the body it affects. Runs before damageUnit
        damageUnit: Used to alter the final change to stats of a unit when its hit by a weapon. If unit receives a hit with 0 power this script doesnt run.
        healUnit: Used to alter effect of medikit on unit. Can alter exp from usage of it.
        createUnit: Runs when new unit is created
        newTurnUnit: Runs for every unit every turn (this includes alien, civilian and xcom turns)
        returnFromMissionUnit: Runs for every unit at the end of a mission.
        awardExperience: Runs whenever a unit performs an action that can earn it experience.
        visibilityUnit: Runs to check if two units of opposing factions can see each other.
    Item scripts
        recolorItemSprite: Runs for every pixel of sprite. Change color.
        selectItemSprite: Run to change the graphic of an item when its on the floor or in the hands of a soldier
        reactionWeaponAction: Runs for the weapon that triggered reaction shots by firing.
        createItem: Runs when a new item is created.
        newTurnItem: Runs for each item each turn. (this includes alien, civilian and xcom turns)
    Stat bonus scripts
        For armors: psiDefence, meleeDodge, recovery (time, energy, morale, health, stun, mana)
        For items: damageBonus, meleeBonus, accuracyMultiplier, meleeMultiplier, throwMultiplier, closeQuartersMultiplier
        For units: applySoldierBonuses: Runs once for each bonus of each soldier on mission start.

seems oxce has alot of variations of get/set

edit: what is the correct synthax to get/set transform_chance?

edit2: typo
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nord on November 17, 2023, 08:27:06 am
To create full list of script commands, you need to switch "verboseLogging" in options.cfg to "true", then launch oxce, then quit and open file "openxcom.log". It will contain not only log, but script help. Save it somewhere, and remember to update when upgrade to newer OXCE version.

Quote
edit: what is the correct synthax to get/set transform_chance?
Just as any variable,
Code: [Select]
set temp transform_chance;
...magic...
set transform_chance temp;

Like 0 is no transform at all, 100 - transform by any circumstances.
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 17, 2023, 08:47:04 am
To create full list of script commands, you need to switch "verboseLogging" in options.cfg to "true", then launch oxce, then quit and open file "openxcom.log". It will contain not only log, but script help. Save it somewhere, and remember to update when upgrade to newer OXCE version.
Just as any variable,
Code: [Select]
set temp transform_chance;
...magic...
set transform_chance temp;

Like 0 is no transform at all, 100 - transform by any circumstances.

I Tried both of those,they both break the script

thnx tho for trying
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nord on November 18, 2023, 09:44:38 am
Youmust
I Tried both of those,they both break the script
Show it here.
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 18, 2023, 10:31:05 am
Youmust Show it here.

my script i tried these :

Code: [Select]
          #get transform_chance temp;
          #set transform_chance temp;
          #set temp transform_chance;  
          #debug_log "transform " temp;

it is a script to cheat death,originaly copied from Meridian lucky script i found on this forum,this doesnt fire if i uncoment those(one at a time of course)

Code: [Select]
          unit.getHealth Health;                 # get current health
          sub Health to_health;                  # sub projected hp loss from current hp
          debug_log "Unconscious Code Health:" Health;     
         
          unit.getStun stunLevel;                # set var to unit stun level
          add stunLevel to_stun;                 # add projected stun level to current stun level
          debug_log "Unconscious Code Stun:" stunLevel;       
         
          #get transform_chance temp;
          #set transform_chance temp;
          #set temp transform_chance;  
          #debug_log "transform " temp;         
          if ge stunLevel Health;
             #battle_game.flashLongMessage "STR_TRANSFORM_STRING";
             battle_game.flashLongMessage "STR_UNCONSCIOUS_STRING";
             #set transform_chance temp;
             #debug_log "transform " temp";         
             unit.getHealthMax temp;
             unit.setHealth temp;
             mul temp 4;
             unit.setStun temp;
             set to_health 0;
             set to_stun 0;
             set to_wound -50;
             unit.disableIndicators;
             unit.setTag Tag.LRF_IS_DEAD 1;
             return;
          end;
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nord on November 19, 2023, 09:17:20 am
first string is wrong, and you forget about @magic@ in a middle.
If you want make chances equal to 0:
Code: [Select]
set transform_chance 0;If you want set chances 15% less:
Code: [Select]
set temp transform_chance;
muldiv temp 85 100;
set transform_chance temp;
And dont forget to define variable in a beginning of script:
Code: [Select]
    damageSpecialUnit:
      - offset: 11    # any number for counting
        code: |
          var int temp;
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 19, 2023, 11:00:20 am
first string is wrong, and you forget about @magic@ in a middle.
If you want make chances equal to 0:
Code: [Select]
set transform_chance 0;If you want set chances 15% less:
Code: [Select]
set temp transform_chance;
muldiv temp 85 100;
set transform_chance temp;
And dont forget to define variable in a beginning of script:
Code: [Select]
    damageSpecialUnit:
      - offset: 11    # any number for counting
        code: |
          var int temp;

ok thnx for reply,i tried a few variasions of this

Code: [Select]
  scripts:
    damageSpecialUnit:
      - offset: 99
        code: |
          var int temp 0;
          var int transform 0; 
           
          set temp transform_chance;
          ...magic...
          set transform_chance temp;
          debug_log "transform " temp;  
          battle_game.flashLongMessage "STR_TRANSFORM_STRING";

they break the code,and the string dosnt fire
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nord on November 19, 2023, 03:26:22 pm
:) "...magic..." is not an operator, it is a joke.
Dont write it.
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 19, 2023, 10:51:39 pm
:) "...magic..." is not an operator, it is a joke.
Dont write it.

haha wasnt sure,tried this and debug line doesnt fire

Code: [Select]
extended:
  tags:                                                               
    BattleUnit:                           
      LRF_IS_DEAD: int                       
                   
  scripts:
    damageSpecialUnit:
      - offset: 99
        code: |
          var int temp 0;
          var int transform 0; 
           
          set temp transform_chance;
          #...magic...
          set transform_chance temp;
          debug_log "transform " temp;  
          battle_game.flashLongMessage "STR_TRANSFORM_STRING";
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 22, 2023, 04:10:41 am
anybody know why that code fails?
Title: Re: Prevent Chryssalid Insta Kill
Post by: Yankes on November 22, 2023, 11:15:26 am
You should know it, you have all available tools to debug this, look in logs and see what was there.
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nord on November 22, 2023, 12:06:39 pm
you forget
Code: [Select]
return; in the end.
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 23, 2023, 01:53:35 am
You should know it, you have all available tools to debug this, look in logs and see what was there.

its is bit problematic,as the debug doesnt spam anything i try,nothign fires

you forget
Code: [Select]
return; in the end.

tried that,no dice,thnx for trying
Title: Re: Prevent Chryssalid Insta Kill
Post by: Meridian on November 23, 2023, 08:19:57 am
Sorry, but I tried your script and the logs clearly indicate what's wrong.

Code: [Select]
[23-11-2023_07-09-43] [ERROR] Invalid variable name 'transform'
[23-11-2023_07-09-43] [ERROR] Error in matching arguments for operator 'var'
[23-11-2023_07-09-43] [ERROR] Error in parsing script 'damageSpecialUnit' for 'Global Event Script': invalid operation in line: 'var int transform 0;'

It says exactly, which line is wrong ('var int transform 0;').
And it says exactly what's wrong (invalid variable name).

And Nord's answer is also correct.
Once you fix the issue with the variable name, the logs will complain about the missing return too.

Here's a fixed script:

Code: [Select]
extended:
  tags:                                                               
    BattleUnit:                           
      LRF_IS_DEAD: int                       
                   
  scripts:
    damageSpecialUnit:
      - offset: 99
        code: |
          var int temp 0;
          var int transformx 0; 
           
          set temp transform_chance;
          #...magic...
          set transform_chance temp;
          debug_log "transform " temp;  
          battle_game.flashLongMessage "STR_TRANSFORM_STRING";
          return;
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 23, 2023, 09:55:29 am
Sorry, but I tried your script and the logs clearly indicate what's wrong.

Code: [Select]
[23-11-2023_07-09-43] [ERROR] Invalid variable name 'transform'
[23-11-2023_07-09-43] [ERROR] Error in matching arguments for operator 'var'
[23-11-2023_07-09-43] [ERROR] Error in parsing script 'damageSpecialUnit' for 'Global Event Script': invalid operation in line: 'var int transform 0;'

It says exactly, which line is wrong ('var int transform 0;').
And it says exactly what's wrong (invalid variable name).

And Nord's answer is also correct.
Once you fix the issue with the variable name, the logs will complain about the missing return too.

Here's a fixed script:

Code: [Select]
extended:
  tags:                                                               
    BattleUnit:                           
      LRF_IS_DEAD: int                       
                   
  scripts:
    damageSpecialUnit:
      - offset: 99
        code: |
          var int temp 0;
          var int transformx 0; 
           
          set temp transform_chance;
          #...magic...
          set transform_chance temp;
          debug_log "transform " temp;  
          battle_game.flashLongMessage "STR_TRANSFORM_STRING";
          return;

my bad god i was looking for errors at end of the log,thinking that the script would error after the attack and it would be at bottom of the file

thanks once again Meridian
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 23, 2023, 08:48:34 pm
is  transform_chance always 100 if it isnt modded?
Title: Re: Prevent Chryssalid Insta Kill
Post by: Meridian on November 23, 2023, 08:55:25 pm
no, the default value is this:

Code: [Select]
const RuleItem *specialDamageTransform = attack.damage_item ? attack.damage_item->getRules() : nullptr;
int specialDamageTransformChance = 0;

if (specialDamageTransform
&& !specialDamageTransform->getZombieUnit(this).empty()
&& getArmor()->getZombiImmune() == false)
{
specialDamageTransformChance = getOriginalFaction() != FACTION_HOSTILE ? specialDamageTransform->getZombieUnitChance() : 0;
}
Title: Re: Prevent Chryssalid Insta Kill
Post by: Nirran on November 23, 2023, 10:39:15 pm
no, the default value is this:

Code: [Select]
const RuleItem *specialDamageTransform = attack.damage_item ? attack.damage_item->getRules() : nullptr;
int specialDamageTransformChance = 0;

if (specialDamageTransform
&& !specialDamageTransform->getZombieUnit(this).empty()
&& getArmor()->getZombiImmune() == false)
{
specialDamageTransformChance = getOriginalFaction() != FACTION_HOSTILE ? specialDamageTransform->getZombieUnitChance() : 0;
}

thanks again dude