Author Topic: [Suggestion] add ptre BattleUnit for target_unit & observer_unit  (Read 671 times)

Offline Osobist

  • Sergeant
  • **
  • Posts: 34
    • View Profile
Hello. I have a feature request - implementation of ptre BattleUnit for target_unit & observer_unit, which allow modder to change unit's stats depending of whether it sees enemy or spotted by it.

Background: I'm working under SCP Foundation theme mod and I think it's possible to implement the most iconic and in fact very first SCP ever written https://scp-wiki.wikidot.com/scp-173. The script for it could look like this:


Code: [Select]
armors:
  - type: SECTOID_ARMOR0
    tags:
      IS_SCP173: 1

extended:
  tags:
    RuleArmor:
      IS_SCP173: int

  scripts:
    visibilityUnit:
      - offset: 4
        code: |
          var ptr RuleArmor armorRuleset;
          var int scp173;
          var int observerFaction;
          var int targetTU;
          var int targetTUmax;
          var int observerMorale;
          var int observerBravery;
          var int cowardness 110;

          target_unit.getRuleArmor armorRuleset;
          armorRuleset.getTag scp173 Tag.IS_SCP173;

          if eq scp173 1;
            target_unit.Stats.getTimeUnits targetTUmax;
            target_unit.setTimeUnits targetTUmax;
            observer_unit.getFaction observerFaction;
            debug_log "SCP is" target_unit "Observer is" observer_unit;

            if neq observerFaction 1;
              target_unit.setTimeUnits 0;
              observer_unit.Stats.getBravery observerBravery;
              observer_unit.getMorale observerMorale;
              sub cowardness observerBravery;
              sub observerMorale cowardness;
              observer_unit.setMorale observerMorale;
            end;

          end;

          return current_visibility visibility_mode;

This could be useful in general when modder needs to, e.g., disrupt enemy's accuracy by wearing a chameleon armor of some sort.
« Last Edit: March 22, 2023, 04:35:15 pm by Osobist »

Offline Yankes

  • Commander
  • *****
  • Posts: 3206
    • View Profile
Re: [Suggestion] add ptre BattleUnit for target_unit & observer_unit
« Reply #1 on: March 22, 2023, 10:08:26 pm »
This will not work, as moment when game check for visibility can and will be changed based how game engine will be improved. Most of hooks like this are read-only to prevent instabilities. Not mention that writable unit in this place could easy break every thing like you kill unit when this hook is called.


There is function `tryConcealUnit` that check if unit is not seen by any enemy, its original use was to make unit disappear from memory of enemy if currently is not seen by any body.

You can use this function on "newTurn" to see if is visible or not, with this you can freely update units stats to fit your desires.