aliens

Author Topic: [Examples] 8mono's Y-script repository  (Read 3252 times)

Offline AlicePaws

  • Colonel
  • ****
  • Posts: 146
    • View Profile
[Examples] 8mono's Y-script repository
« on: July 05, 2021, 03:06:47 pm »
I'll be isolating the scripts I'm using in the mods I've made. Feel free to use or edit them as you wish, you don't need any permissions but a credit or mention is nice!, any feedback is appreciated as well

Support Deployables
https://openxcom.mod.io/support-deployables
Superheavy Arsenal
https://openxcom.mod.io/superheavy-arsenal
X-Com Files Additions (XCF Submod)
https://openxcom.org/forum/index.php/topic,9722.0.html

Flare Gun
Code: [Select]
extended:
  tags:
    RuleArmor:
#flare
      ITAG_ILLUMINATION_LIVING: int
      ITAG_ILLUMINATION_DURATION: int #unable to currently determine duration without setting this here as well
  scripts:
    createUnit:
      - offset: 0.5
        code: |
          var int flareLivingTag;
          var int illuminationDuration;
          var ptr RuleArmor armorUnit;
          var int currTurn;
          var int currSide;
          var ptr RuleItem ruleItem;
          var ptre BattleItem smokeItem;
          var ptre BattleItem flareItem;
         
          unit.getRuleArmor armorUnit;
          armorUnit.getTag flareLivingTag Tag.ITAG_ILLUMINATION_LIVING;
          armorUnit.getTag illuminationDuration Tag.ITAG_ILLUMINATION_DURATION;
         
          if and eq flareLivingTag 1 eq currSide 0;
            unit.getInventoryItem smokeItem 3;
            unit.getInventoryItem flareItem 2;
            debug_log illuminationDuration;
            mul illuminationDuration 2; #compensating
            debug_log flareItem;
            debug_log smokeItem;
            flareItem.setFuseEnabled 1;
            flareItem.setFuseTimer illuminationDuration;
            smokeItem.setFuseEnabled 1;
            smokeItem.setFuseTimer 0;
            debug_log "This armor has a flare value CREATEUNIT EDITION ";
            unit.addStun 25;
            unit.disableIndicators;
          end;
          return;

    newTurnUnit:
      - offset: 1.5
        code: |
          var int flareLivingTag;
          var ptr RuleArmor armorUnit;
          var int currTurn;
          var int currSide;
          var int stunApplied;

          unit.getRuleArmor armorUnit;
          armorUnit.getTag flareLivingTag Tag.ITAG_ILLUMINATION_LIVING;
         
          if eq flareLivingTag 1;
            battle_game.getTurn currTurn;
            battle_game.getTurnSide currSide;
            debug_log currTurn;
            debug_log currSide;
            debug_log "Above was currTurn and currSide";

            debug_log "This armor has a flare value NEWTURNUNIT EDITION";
            if neq currSide 0;
              unit.setHealth -1;
            end;
          end;
          return;
items:
#flare test
  - type: STR_LIVING_FLARE_R
    size: 0.1
    power: 16
    battleType: 10
    armor: 30
    fuseType: -3
    fuseTriggerEvents:
      defaultBehavior: true
      throwTrigger: false
    recover: false
    invWidth: 1
    invHeight: 1
    fixedWeapon: true
    hiddenOnMinimap: true
    defaultInventorySlot: STR_RIGHT_HAND
  - type: STR_LIVING_FLARE_L
    size: 0.1
    power: 16
    battleType: 10
    armor: 30
    fuseType: -3
    fuseTriggerEvents:
      defaultBehavior: true
      throwTrigger: false
    recover: false
    invWidth: 1
    invHeight: 1
    fixedWeapon: true
    hiddenOnMinimap: true
    defaultInventorySlot: STR_LEFT_HAND
  - type: STR_LIVING_FLARE_I
    size: 0.1
    power: 16
    battleType: 10
    armor: 100
    fuseType: -1
    fuseTriggerEvents:
      defaultBehavior: true
      throwTrigger: false
    recover: false
    invWidth: 1
    invHeight: 1
    hiddenOnMinimap: true
  - type: STR_LIVING_FLARE_SMOKE_I
    size: 0.1
    power: 60
    battleType: 4
    armor: 30
    damageType: 9
    blastRadius: 1
    fuseType: 0
    damageAlter:
      ToItem: 0
    fuseTriggerEvents:
      defaultBehavior: true
      throwTrigger: false
    recover: false
    invWidth: 1
    invHeight: 1
    hiddenOnMinimap: true
    isExplodingInHands: true
  - type: STR_LIVING_FLARE
    name: STR_FLARE
    size: 0.1
    battleType: 11
    armor: 30
    recover: false
    hiddenOnMinimap: true
    invWidth: 1
    invHeight: 1
#FLARES
  - type: STR_FLARE_GUN
    size: 0.1
    costBuy: 500
    costSell: 200
    weight: 5
    bigSprite: 0
    floorSprite: 0
    handSprite: 8
    bulletSprite: 6
    fireSound: 11
    compatibleAmmo:
      - STR_ILLUMINATOR_CLIP
    accuracyCloseQuarters: 133
    accuracyAimed: 45
    tuAimed: 28
    tuLoad: 10
    battleType: 1
    arcingShot: true
    invWidth: 1
    invHeight: 2
    armor: 25
    aimRange: 9 #12
    dropoff: 3
  - type: STR_ILLUMINATOR_CLIP
    size: 0.1
    costBuy: 50
    costSell: 20
    weight: 8
    bigSprite: 2
    floorSprite: 2
    hitSound: 19
    hitAnimation: 36
    power: 20
    spawnUnit: STR_FLARE_TEST
    spawnUnitFaction: 2
    damageType: 9
    blastRadius: 0
    clipSize: 1
    battleType: 2
    invWidth: 1
    invHeight: 1
    armor: 25
armors:
#FLARE
  - type: STR_FLARE_ARMOR
    spriteSheet: FLOATER.PCK #make sure this is invisible or appropiate!
    spriteInv: MAN_1 #make sure this is invisible or appropiate!
    corpseBattle:
      - STR_LIVING_FLARE
    visibilityAtDark: -500
    visibilityAtDay: -500
    camouflageAtDay: 1000
    camouflageAtDark: 1000
    psiCamouflage: 1000
    personalLight: 4 # 100 I know it doesnt go up that much
    drawingRoutine: 1
    movementType: 1
    fearImmune: true
    zombiImmune: true
    builtInWeapons:
      - STR_LIVING_FLARE_L
      - STR_LIVING_FLARE_R
      - STR_LIVING_FLARE_I
      - STR_LIVING_FLARE_SMOKE_I
    frontArmor: 0
    sideArmor: 0
    rearArmor: 0
    underArmor: 0
    overKill: 1500
    loftempsSet: [ 3 ]
    tags:
      ITAG_ILLUMINATION_LIVING: 1
      ITAG_ILLUMINATION_DURATION: 8 #lets pretend this value is obtained from the ammo, don't know how to do it yet, would need a "unitHasShot event" or something
alienRaces:
  - id: STR_FLARE
    members:
      - STR_FLARE_TEST
units:
  - type: STR_FLARE_TEST
    race: STR_FLARE
    stats:
      tu: 0
      stamina: 10
      health: 0
      bravery: 200
      reactions: 0
      firing: 0
      throwing: 0
      strength: 0
      psiStrength: 200
      psiSkill: 0
      melee: 0
      mana: 10
    armor: STR_FLARE_ARMOR
    standHeight: 22
    kneelHeight: 14
    floatHeight: 2
    value: 1


The idea for the flare gun is to spawn a unit (I use "invisible" spritesheets for the floater as well as "invisible" sprites for the items in my mods) at the point of impact and have it be equipped with flares and an optional smoke effect, upon death it will drop the primed flare in its inventory, the primed flare lasts for a few turns before disapearing.
Things I'd like to improve are:
- Immediate flare deployment (not having to wait until the flare updates by doing an action)
- Knowing the best faction to spawn (Civilians for example if they die you lose points, Enemies would mean they get vision, Xcom means you can control them and they would substract points for dying as well as it just feels weird... + getting  extra vision which is unfair)
- Readability

Things that are out of the scope of my skills and the scripting language at the moment:
- Have the flares actually start at the highest point of the sky (same X,Z coordinates, just the max Y for that map) and descend 1 tile per turn until they reach the ground  (more of a visual novelty if anything, but it would make them also behave differently from regular throwable electro-flares)
« Last Edit: February 12, 2023, 03:00:28 pm by Meridian »

Offline AlicePaws

  • Colonel
  • ****
  • Posts: 146
    • View Profile
Re: [y-script] 8mono's script repository
« Reply #1 on: July 05, 2021, 06:55:04 pm »
Impact Vest
Code: [Select]
#--------------------------------------------------------------------------------------------
# Scripting stuff
#--------------------------------------------------------------------------------------------
extended:
  tags:
#--------------------------------------------------------------------------------------------
# RuleItem tags
#--------------------------------------------------------------------------------------------
    RuleItem:
#defense
      ITEM_IMPACT_VEST: int
      ITEM_RESIST_SLOT_INDEX: int
#--------------------------------------------------------------------------------------------
# RuleUnit tags
#--------------------------------------------------------------------------------------------
    BattleUnit:
#resistances
      UNIT_RESIST_ITEM_SLOT_1: int
#--------------------------------------------------------------------------------------------
# Scripts
#--------------------------------------------------------------------------------------------
  scripts:
    newTurnUnit:
      - offset: 1
        code: |
          # Clear all unit resist types and minimums so resistance items can set again
          unit.setTag Tag.UNIT_RESIST_ITEM_SLOT_1 0;
          return;
    newTurnItem:
      - offset: 3
        code: |
          var ptre BattleUnit itemOwner;
          var ptr RuleItem itemRuleset;
          var int itemResistSlotIndex;
          var int temp;

          item.getOwner itemOwner;

          # If no owner, skip script
          if eq itemOwner null;
            return;
          end;

          # Check the item's slot index; if it's already set on this unit, don't count this item
          item.getRuleItem itemRuleset;
          itemRuleset.getTag itemResistSlotIndex Tag.ITEM_RESIST_SLOT_INDEX;

          if eq itemResistSlotIndex 1;
            itemOwner.getTag temp Tag.UNIT_RESIST_ITEM_SLOT_1;

            if eq temp 1;
              return;
            else;
              itemOwner.setTag Tag.UNIT_RESIST_ITEM_SLOT_1 1;
            end;
          end;

          return;
    hitUnit:
      - offset: 3
        code: |
          var ptre BattleItem vestItem;
          var ptr RuleItem damagingRuleset;
          var ptr RuleItem vestRuleset;
          var ptr Tile attackerTile;
          var ptr Tile unitTile;
          var int attackerX;
          var int attackerY;
          var int attackerZ;
          var int unitX;
          var int unitY;
          var int unitZ;
          var int distanceTile;
          var int vestArmor;

          unit.getTag vestArmor Tag.UNIT_RESIST_ITEM_SLOT_1;

          if eq vestArmor 0;
            debug_log "Vest not found! aborting";
            return power part side;
          end;
          debug_log "damaging_type equals:";
          debug_log damaging_type;
          if or eq damaging_type 0 eq damaging_type 6 eq damaging_type 8 eq damaging_type 9;
            debug_log "Damage was Special,Stun,Acid or Smoke aborting...";
            battle_game.flashMessage "Damage bypasses vest!";
            return power part side;
          end;

          #This should only run IF the maximum distance is NOT exceeded (4 tiles right now)
          attacker.getPosition.getX attackerX;
          attacker.getPosition.getY attackerY;
          attacker.getPosition.getZ attackerZ;
          battle_game.getTile attackerTile attackerX attackerY attackerZ;
          unit.getPosition.getX unitX;
          unit.getPosition.getY unitY;
          unit.getPosition.getZ unitZ;
          battle_game.getTile unitTile unitX unitY unitZ;
          attackerTile.getDistanceTile distanceTile unitTile;
          debug_log distanceTile;
          debug_log "Above were distanceTile and distanceVoxel";
         
          if gt distanceTile 4;
            debug_log "Distance was greater than 4!";
            debug_log distanceTile;
            return power part side;
          end;
         
          if or eq side SIDE_LEFT eq side SIDE_RIGHT; #33%
            set vestArmor 3;
            battle_game.flashMessage "Damage reduced by: 33%";
          else eq side SIDE_UNDER; #20%
            set vestArmor 5;
            battle_game.flashMessage "Damage reduced by: 20%";
          else eq side SIDE_REAR; #25%
            battle_game.flashMessage "Damage reduced by: 25%";
            set vestArmor 4;
          else eq side SIDE_FRONT; #50%
            battle_game.flashMessage "Damage reduced by: 50%";
            set vestArmor 2;
          end;

          debug_log "first is original power, after is power after reductions";
          debug_log power;
          #We're only removing that percentage, not making the damage that percentage
          div power vestArmor;
          sub vestArmor 1;
          mul power vestArmor;

          debug_log power;
          return power part side;
#--------------------------------------------------------------------------------------------
# Items
#--------------------------------------------------------------------------------------------
items:
#impact vest
  - type: STR_IMPACT_VEST
    size: 0.2
    costBuy: 100000
    costSell: 25000
    weight: 2
    bigSprite: 32 #check this
    floorSprite: 32 #check this
    battleType: 10
    invWidth: 2
    invHeight: 2
    supportedInventorySections:
      - STR_BACK_PACK
    tags:
      ITEM_IMPACT_VEST: 1
      ITEM_RESIST_SLOT_INDEX: 1

This item is basically only able to be equipped in your backpack and when present will reduce damage under the condition the distance between your attacker is no more than 4, frontal attacks receive the full bonus while other sides have a lesser effect (50% for front, 33% for sides, 25% for back or something like that) Additionally any damage that isn't physical (Plasma, Laser, Smoke) is ignored, this takes inspiration from the Damage reduction items found in the X-Com Files, and actually uses some of the code to achieve the "assigning" part since otherwise you'd need to keep checking the unit's inventory

Offline AlicePaws

  • Colonel
  • ****
  • Posts: 146
    • View Profile
Re: [y-script] 8mono's script repository
« Reply #2 on: July 05, 2021, 08:16:42 pm »
UAV and Holotargetter
Code: [Select]
#--------------------------------------------------------------------------------------------
# Items
#--------------------------------------------------------------------------------------------
items:
#UAV Consoles
  - type: STR_SPAWN_UAV
    size: 0.2
    costBuy: 25000
    costSell: 10000
    weight: 8
    accuracyAimed: 100
    accuracyCloseQuarters: 100
    accuracyMultiplier:
      firing: 0.0
      throwing: 1.0
    tuAimed: 28
    aimRange: 9 #12
    arcingShot: true
    bigSprite: 20
    floorSprite: 20
    bulletSprite: 0
    fireSound: 0
    power: 0
    damageAlter:
      SmokeThreshold: 0
    spawnUnit: STR_UAV_TEST
    spawnUnitFaction: 0 #2 for neutral
    damageType: 0
    blastRadius: 0
    clipSize: 1
    battleType: 1
    costAimed:
      time: 30
      energy: 6
    confAimed:
      name: STR_USE_UAV_SPAWNER
    flatRate: true
    maxRange: 20
    experienceTrainingMode: 7
    invWidth: 2
    invHeight: 1
    armor: 25
    dropoff: 3
  - type: STR_SPAWN_ALLOY_UAV
    size: 0.2
    costBuy: 25000
    costSell: 10000
    weight: 8
    accuracyAimed: 100
    accuracyCloseQuarters: 100
    accuracyMultiplier:
      firing: 0.0
      throwing: 1.0
    tuAimed: 28
    aimRange: 9 #12
    arcingShot: true
    bigSprite: 20
    floorSprite: 20
    bulletSprite: 0
    fireSound: 0
    power: 0
    damageAlter:
      SmokeThreshold: 0
    spawnUnit: STR_ALLOY_UAV_TEST
    spawnUnitFaction: 0 #2 for neutral
    damageType: 0
    blastRadius: 0
    clipSize: 1
    battleType: 1
    costAimed:
      time: 30
      energy: 6
    confAimed:
      name: STR_USE_UAV_SPAWNER
    flatRate: true
    maxRange: 20
    experienceTrainingMode: 7
    invWidth: 2
    invHeight: 1
    armor: 25
    dropoff: 3
#Laser Designators/Holotargetter
  - type: STR_UAV_LASER_TARGETTER
    size: 0.1
    weight: 0
    bigSprite: 30
    bulletSprite: 5
    floorSprite: 30
    handSprite: 0
    explosionSpeed: -5
    fireSound: 0
    accuracyAimed: 120
    tuAimed: 28
    aimRange: 20 #12
    dropoff: 3
    power: 1
    damageType: 4
    clipSize: 10
    battleType: 1
    invWidth: 2
    invHeight: 1
    armor: 25
    fixedWeapon: true
    defaultInventorySlot: STR_RIGHT_HAND
    tags:
      ITEM_UAV_LASER_TARGETTER: 1
      UAV_ITEM: 1
  - type: STR_ALLOY_UAV_LASER_TARGETTER
    size: 0.1
    weight: 0
    bigSprite: 30
    bulletSprite: 5
    floorSprite: 0
    handSprite: 0
    hitAnimation: 192
    explosionSpeed: -5
    fireSound: 0
    accuracyAimed: 125
    tuAimed: 28
    aimRange: 22 #12
    dropoff: 3
    power: 1
    damageType: 4
    clipSize: 12
    battleType: 1
    invWidth: 2
    invHeight: 1
    armor: 25
    fixedWeapon: true
    defaultInventorySlot: STR_RIGHT_HAND
    tags:
      ITEM_UAV_LASER_TARGETTER: 1
      UAV_ITEM: 1
#Self-destruct
  - type: STR_UAV_DETONATE
    size: 0.1
    weight: 0
    bigSprite: 27
    handSprite: 0
    fireSound: 0
    dropoff: 3
    power: 50
    fuseType: -0
    isExplodingInHands: true
    damageType: 3
    blastRadius: 5
    clipSize: 1
    battleType: 4
    invWidth: 2
    invHeight: 1
    armor: 25
    costPrime:
      time: 40
    costUnprime:
      time: 40
    primeActionName: STR_SELF_DESTRUCT
    primeActionMessage: STR_SELF_DESTRUCT_MESSAGE
    unprimeActionName: STR_SELF_DESTRUCT_UNPRIME
    unprimeActionMessage: STR_SELF_DESTRUCT_UNPRIME_MESSAGE
    fixedWeapon: true
    defaultInventorySlot: STR_LEFT_HAND
  - type: STR_ALLOY_UAV_DETONATE
    size: 0.1
    weight: 0
    bigSprite: 27
    handSprite: 0
    fireSound: 0
    dropoff: 3
    power: 75
    fuseType: -1
    isExplodingInHands: true
    damageType: 3
    blastRadius: 5
    clipSize: 1
    battleType: 4
    invWidth: 2
    invHeight: 1
    armor: 25
    costPrime:
      time: 40
    costUnprime:
      time: 40
    primeActionName: STR_SELF_DESTRUCT
    primeActionMessage: STR_SELF_DESTRUCT_MESSAGE
    unprimeActionName: STR_SELF_DESTRUCT_UNPRIME
    unprimeActionMessage: STR_SELF_DESTRUCT_UNPRIME_MESSAGE
    fixedWeapon: true
    defaultInventorySlot: STR_LEFT_HAND
#Corpses
  - type: STR_UAV_CORPSE
    name: STR_UAV_CORPSE
    size: 0.1
    weight: 7
    bigSprite: 2
    floorSprite: 2
    handSprite: 0
    battleType: 11
    armor: 30
    recover: true
    hiddenOnMinimap: false
    invWidth: 2
    invHeight: 1
  - type: STR_ALLOY_UAV_CORPSE
    name: STR_ALLOY_UAV_CORPSE
    size: 0.1
    weight: 9
    bigSprite: 2
    floorSprite: 2
    handSprite: 0
    battleType: 11
    armor: 30
    recover: true
    hiddenOnMinimap: false
    invWidth: 2
    invHeight: 1
#--------------------------------------------------------------------------------------------
# Scripting stuff
#--------------------------------------------------------------------------------------------
extended:
  tags: # Remember to add tag definitions to same file as item/armor rulesets!
#--------------------------------------------------------------------------------------------
# RuleItem tags
#--------------------------------------------------------------------------------------------
    RuleItem:
#uav
      ITEM_UAV_LASER_TARGETTER: int
      UAV_ITEM: int
#--------------------------------------------------------------------------------------------
# RuleUnit tags
#--------------------------------------------------------------------------------------------
    BattleUnit:
#holotargeter
      UNIT_HOLOTARGETTED: int
      UNIT_HOLOTARGET_ENDTURN: int
      UNIT_IS_UAV: int
#--------------------------------------------------------------------------------------------
# Scripts
#--------------------------------------------------------------------------------------------
  scripts:
    createUnit:
      - offset: 1
        code: |
          var int unitIsUAV;
          var ptre BattleItem itemCheck;
          var int temp;
 
          # Make sure this doesn't run an extra time when civilians or aliens have a turn
          if or eq side 0 eq side 1;
            return power part side;
          end;
         
          unit.getRightHandWeapon itemCheck;
          itemCheck.getTag unitIsUAV Tag.UAV_ITEM;
          unit.setTag Tag.UNIT_IS_UAV unitIsUAV;
          debug_log "we checked if item belongs to a UAV and tag it as such below is unitIsUAV tag check: ";
          unit.getTag temp Tag.UNIT_IS_UAV;
          debug_log temp;
         
          return;
    hitUnit:
      - offset: 3
        code: |
          var ptr RuleItem damagingRuleset;
          var ptr RuleItem UAVRuleset;
          var ptr Tile attackerTile;
          var ptr Tile unitTile;
          var int attackerX;
          var int attackerY;
          var int attackerZ;
          var int unitX;
          var int unitY;
          var int unitZ;
          var int distanceTile;
          var int UAVLaser;
          var int holoTargetted;
          var int currTurn;
          var int endTurn;
          var int temp;
          var int tuCost;
          var int refundedTU;
          var int refundChance;
          var int unitIsUAV;
          set UAVLaser 0;
         
          # Make sure this doesn't run an extra time when civilians or aliens have a turn
          if or eq side 0 eq side 1;
            return power part side;
          end;
         
          weapon_item.getRuleItem UAVRuleset;
          UAVRuleset.getTag UAVLaser Tag.ITEM_UAV_LASER_TARGETTER;
          unit.getTag holoTargetted Tag.UNIT_HOLOTARGETTED;
          attacker.getTag unitIsUAV Tag.UNIT_IS_UAV;
          debug_log "Below are UAVLaser, weapon_item, holoTargetted and if unit is UAV";
          debug_log UAVLaser;
          debug_log weapon_item;
          debug_log holoTargetted;
          debug_log unitIsUAV;
         
          if and eq holoTargetted 0 eq UAVLaser 1;
            unit.setTag Tag.UNIT_HOLOTARGETTED 1;
            unit.getTag temp Tag.UNIT_HOLOTARGETTED;
            debug_log temp;
            debug_log "above was debug temp for holotarget";
            set endTurn currTurn;
            add endTurn 5;
            unit.setTag Tag.UNIT_HOLOTARGET_ENDTURN endTurn;           
            debug_log "target holotargetted";
          else and eq holoTargetted 1 eq UAVLaser 1;
            set endTurn currTurn;
            add endTurn 3;
            unit.setTag Tag.UNIT_HOLOTARGET_ENDTURN endTurn;
            attacker.getPosition.getX attackerX;
            attacker.getPosition.getY attackerY;
            attacker.getPosition.getZ attackerZ;
            battle_game.getTile attackerTile attackerX attackerY attackerZ;
            unit.getPosition.getX unitX;
            unit.getPosition.getY unitY;
            unit.getPosition.getZ unitZ;
            battle_game.getTile unitTile unitX unitY unitZ;
            attackerTile.getDistanceTile distanceTile unitTile;
            battle_game.flashMessage "Laser time extended, unit is: {0} tiles away!" distanceTile;
            debug_log "target holotarget timer extended";
          end;
          if eq UAVLaser 1;
            attacker.getPosition.getX attackerX;
            attacker.getPosition.getY attackerY;
            attacker.getPosition.getZ attackerZ;
            battle_game.getTile attackerTile attackerX attackerY attackerZ;
            unit.getPosition.getX unitX;
            unit.getPosition.getY unitY;
            unit.getPosition.getZ unitZ;
            battle_game.getTile unitTile unitX unitY unitZ;
            attackerTile.getDistanceTile distanceTile unitTile;
            debug_log distanceTile;
            debug_log "above was distanceTile";
            #eventually when I find out how visibility works, if you can see it it broadcats its distance every turn while lasered
            battle_game.flashMessage "Target lasered: {0} tiles away!" distanceTile;       
            unit.setTag Tag.UNIT_HOLOTARGETTED 1;     
          end;
          unit.getTag holoTargetted Tag.UNIT_HOLOTARGETTED;
         
          # This part is for non UAVs only (your soldiers)
          if or eq UAVLaser 1 eq unitIsUAV 1;
            debug_log "unit was UAV so we're returning!";
            return power part side;
          end;
         
          debug_log holoTargetted;
          debug_log "seeing if holoTargetted equals 1 for the unitHolotarget tag";
          if eq holoTargetted 0;
            debug_log "target doesnt have holo, aborting";
            return power part side;
          else and eq holoTargetted 1 eq battle_action BA_AIMEDSHOT;
            debug_log "target did have holo AND im using AIMED shot";
            attacker.getPosition.getX attackerX;
            attacker.getPosition.getY attackerY;
            attacker.getPosition.getZ attackerZ;
            battle_game.getTile attackerTile attackerX attackerY attackerZ;
            unit.getPosition.getX unitX;
            unit.getPosition.getY unitY;
            unit.getPosition.getZ unitZ;
            battle_game.getTile unitTile unitX unitY unitZ;
            attackerTile.getDistanceTile distanceTile unitTile;
            debug_log distanceTile;
            #eventually when I find out how visibility works, if you can see it it broadcats its distance every turn while lasered
            battle_game.flashMessage "Target has holoTarget and is: {0} tiles away!" distanceTile;
            debug_log power;
            mul power 120;
            div power 100;
            debug_log power;
            debug_log "Above was power before the *120 / 100 division thing";
          else and eq holoTargetted 1 eq battle_action BA_SNAPSHOT;
            debug_log "target did have holo and im using SNAPSHOT";
            weapon_item.getActionCost.getTimeUnits tuCost attacker BA_SNAPSHOT;
            battle_game.randomRange refundChance 1 100; #calculate random chance for refund apply
            debug_log refundChance;
            debug_log "above was refundChance";
            if gt refundChance 49;
              debug_log "refund granted!";
              debug_log tuCost;
              attacker.getTimeUnits refundedTU;
              debug_log refundedTU;
              add refundedTU tuCost;
              debug_log refundedTU;
              attacker.setTimeUnits refundedTU;
              attacker.getPosition.getX attackerX;
              attacker.getPosition.getY attackerY;
              attacker.getPosition.getZ attackerZ;
              battle_game.getTile attackerTile attackerX attackerY attackerZ;
              unit.getPosition.getX unitX;
              unit.getPosition.getY unitY;
              unit.getPosition.getZ unitZ;
              battle_game.getTile unitTile unitX unitY unitZ;
              attackerTile.getDistanceTile distanceTile unitTile;
              debug_log distanceTile;
              battle_game.flashMessage "{0} TU's Refunded! target is: {1} tiles away!" tuCost distanceTile;
            end;
          end;   

          return power part side;
    newTurnUnit:
      - offset: 4
        code: |
          var int holoTag;
          var int endTurn;
          var int warnTurn;
          var int currTurn;
          var int currSide;

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

          unit.getTag holoTag Tag.UNIT_HOLOTARGETTED;
          unit.getTag endTurn Tag.UNIT_HOLOTARGET_ENDTURN;
          if eq holoTag 1;
            battle_game.getTurn currTurn;
            battle_game.getTurnSide currSide;
            set warnTurn endTurn;
            sub warnTurn 1;
            debug_log currTurn;
            debug_log currSide;
            debug_log "Unit has a Holo tag";
            debug_log "Above was currTurn and currSide";
            if eq warnTurn currTurn;
              debug_log "Holo-Target is about to wear off out...";
              battle_game.flashMessage "Holo-Target is about to wear off!";
            end;
            if lt currTurn endTurn;
           
            else eq currTurn endTurn;
              battle_game.flashMessage "Holo-Target has worn off!";
              unit.setTag Tag.UNIT_HOLOTARGETTED 0;
              debug_log "removed holotarget!";
              return;
            end;
           
          end;
          return;
alienRaces:
  - id: STR_UAV
    members:
      - STR_UAV_TEST
units:
  - type: STR_UAV_TEST
    race: STR_UAV
    stats:
      tu: 60
      stamina: 30
      health: 30
      bravery: 110
      reactions: 80
      firing: 55
      throwing: 0
      strength: 20
      psiStrength: 100
      psiSkill: 0
      melee: 0
    armor: STR_UAV_ARMOR
    standHeight: 19
    kneelHeight: 19
    value: 20
    intelligence: 0
    aggression: 0
    moveSound: 15 #consider this
    energyRecovery: 20
    deathSound: 23
    livingWeapon: true
  - type: STR_ALLOY_UAV_TEST
    race: STR_UAV
    stats:
      tu: 75
      stamina: 30
      health: 45
      bravery: 110
      reactions: 95
      firing: 70
      throwing: 0
      strength: 20
      psiStrength: 100
      psiSkill: 0
      melee: 0
    armor: STR_ALLOY_UAV_ARMOR
    standHeight: 19
    kneelHeight: 19
    value: 20
    intelligence: 0
    aggression: 0
    moveSound: 15 #consider this
    energyRecovery: 20
    deathSound: 23
    livingWeapon: true
armors:
#UAV TEST
  - type: STR_UAV_ARMOR
    spriteSheet: FLOATER.PCK #make sure this is appropiate!
    spriteInv: MAN_1 #make sure this is appropiate!
    corpseBattle:
      - STR_UAV_CORPSE #use an actual corpse
    personalLight: 4 # 100 I know it doesnt go up that much
    drawingRoutine: 1
    movementType: 1
    fearImmune: true
    zombiImmune: true
    movementType: 1
    allowsMoving: true
    builtInWeapons:
      - STR_UAV_LASER_TARGETTER
      - STR_UAV_DETONATE
    frontArmor: 20
    sideArmor: 12
    rearArmor: 8
    underArmor: 4
    overKill: 1500
    loftempsSet: [ 3 ]
  - type: STR_ALLOY_UAV_ARMOR
    spriteSheet: FLOATER.PCK #make sure this is appropiate!
    spriteInv: MAN_1 #make sure this is appropiate!
    corpseBattle:
      - STR_ALLOY_UAV_CORPSE #use an actual corpse
    personalLight: 4 # 100 I know it doesnt go up that much
    drawingRoutine: 1
    movementType: 1
    fearImmune: true
    zombiImmune: true
    movementType: 1
    allowsMoving: true
    builtInWeapons:
      - STR_ALLOY_UAV_LASER_TARGETTER
      - STR_ALLOY_UAV_DETONATE
    frontArmor: 35
    sideArmor: 20
    rearArmor: 16
    underArmor: 8
    overKill: 1500
    loftempsSet: [ 3 ]

The UAV is pretty simple, you have a console that will spawn a UAV and this UAV has two items on each hand: A holotargetter/laser designator and a Self-destruct button
Upon being holo-targetted (you hit the enemy with your laser) its distance is displayed everytime you shoot at him and depending on your action you get a different bonus:
- Aimed Shots: 20% damage buff, always
- Snap Shot: 50% chance to get your TU's refunded for that shot
- Auto-Shots: No change

Things I'd like to improve:
- Make sure it always works, this one has been particularly tricky to debug, it should be working now for the most part
- Get an accuracy buff only for aimed shots rather than than a damage bonus
- Take away unit's camouflage while laser designated when I learn how visibility works
- Still learning how to add special weapons, but I'd add a motion scanner on the special items option
Things outside the scope of my skills and scripting engine that'd be cool:
- Actually use it as a laser designator for air-burst explosives (if unit is at 14 tiles, you can shoot a missile that could explode right over the unit at that exact distance or much closer to it rather than risk a full miss)
« Last Edit: July 05, 2021, 08:45:35 pm by 8mono »