OpenXcom Forum

Modding => OpenXcom Extended => OXCE Suggestions DONE => Topic started by: Solarius Scorch on July 30, 2022, 01:17:19 pm

Title: [DONE][Suggestion] Hit side on weapon
Post by: Solarius Scorch on July 30, 2022, 01:17:19 pm
When defining a environmental hazard in environmentalConditions, you can specify which side the effect hits (the "side" parameter). I would like to request a similar property directly on a weapon.

(It can probably be scripted, but there's like 10 people on Earth who can write scripts and they rarely overlap with modders.)
Title: Re: [Suggestion] Hit side on weapon
Post by: ohartenstein23 on July 30, 2022, 05:21:33 pm
Code: [Select]
items:
  - type: STR_ITEM_HITS_SPECIFIC_SIDE
    scripts:
      hitUnit:
        # set part BODYPART_TORSO; # optional but you may want to set what part it hits too, HEAD, TORSO, LEFTARM, RIGHTARM, LEFTLEG, RIGHTLEG
        set side SIDE_UNDER; # can be FRONT, LEFT, RIGHT, BACK, UNDER
        return power part side;
Title: Re: [Suggestion] Hit side on weapon
Post by: Meridian on July 30, 2022, 05:35:34 pm
Thanks oharty.

To answer also the original request: it is very hard for us to add new non-script features to places where script support was already added. This has many different reasons; I will spare you the gruesome details. The bottomline is: in these cases, both Yankes and I (and others) will gladly help with writing a script; or even extend the scripting engine if a script cannot be written. Both of these options are much easier for us than trying to add a non-script feature and make it backwards-compatible with all the possible scripts that anyone may have written in the meantime.
Title: Re: [Suggestion] Hit side on weapon
Post by: Solarius Scorch on July 31, 2022, 01:17:07 pm
Code: [Select]
items:
  - type: STR_ITEM_HITS_SPECIFIC_SIDE
    scripts:
      hitUnit:
        # set part BODYPART_TORSO; # optional but you may want to set what part it hits too, HEAD, TORSO, LEFTARM, RIGHTARM, LEFTLEG, RIGHTLEG
        set side SIDE_UNDER; # can be FRONT, LEFT, RIGHT, BACK, UNDER
        return power part side;

Thanks, much appreciated. I'll experiment.

I don't get this, though: other scripts I am using under hitUnit have their offset and start with something like "code: |". This one doesn't?

To answer also the original request: it is very hard for us to add new non-script features to places where script support was already added. This has many different reasons; I will spare you the gruesome details. The bottomline is: in these cases, both Yankes and I (and others) will gladly help with writing a script; or even extend the scripting engine if a script cannot be written. Both of these options are much easier for us than trying to add a non-script feature and make it backwards-compatible with all the possible scripts that anyone may have written in the meantime.

I totally understand, and wouldn't push anyway. I hope to not bother you with questions much. ;)
Title: Re: [Suggestion] Hit side on weapon
Post by: ohartenstein23 on July 31, 2022, 09:10:00 pm
I don't get this, though: other scripts I am using under hitUnit have their offset and start with something like "code: |". This one doesn't?

I attached this to the specific item definition ("items:") instead of making it a global script ("extended: scripts:") accessed by putting a tag on the item.
Title: Re: [Suggestion] Hit side on weapon
Post by: Solarius Scorch on August 02, 2022, 02:55:48 pm
I attached this to the specific item definition ("items:") instead of making it a global script ("extended: scripts:") accessed by putting a tag on the item.

Thanks, a lot! Unfortunately I'm doing something wrong. I have no idea how to check which armour value was actually used, except checking which side is damaged on the unit stat screen. And going by that, the damage is being done not to the intended bottom armour, but by normal rules.

The idea is to give rats a special ability to always attack under armour (since their attack is pretty weak, and I want to give them some edge; bottom armour is usually the thinnest).

Here's the entire weapon entry:
Code: [Select]
  - type: STR_SHADOWBAT_WEAPON
    categories: [STR_BUILT_INS]
    weight: 0
    bigSprite: 595
    floorSprite: 31
    handSprite: 104
    meleeSound: 48
    meleeHitSound: 108
    clipSize: -1
    power: 15
    strengthApplied: false
    damageType: 7
    damageAlter:
      ArmorEffectiveness: 0.5
      ToTile: 0.33
    accuracyMelee: 120
    tuMelee: 20
    battleType: 3
    fixedWeapon: true
    invWidth: 2
    invHeight: 2
    recover: false
    flatRate: true
    scripts:
      hitUnit:
        set part BODYPART_HEAD;
        set side SIDE_UNDER;
        return power part side;

Help pls :)
Title: Re: [Suggestion] Hit side on weapon
Post by: Yankes on August 02, 2022, 04:02:12 pm
Ok, problem is that `hitUnit` is hook from unit perceptive not weapon.
This mean you need add global armor script and use tags in items.

I think I will simply fix it by adding new hook that is linked to weapon not armor,
as this use case repeat multiple times where you want specific behavior per weapon.
Title: Re: [Suggestion] Hit side on weapon
Post by: Solarius Scorch on August 02, 2022, 04:26:25 pm
Many thanks, Yankes. Please keep us posted!
Title: Re: [Suggestion] Hit side on weapon
Post by: ohartenstein23 on August 02, 2022, 06:00:16 pm
If you're going to have multiple weapons with this feature, I may have some time to write a global version.
Title: Re: [Suggestion] Hit side on weapon
Post by: Yankes on August 03, 2022, 09:23:15 pm
New hooks: `hitUnitAmmo` and `damageUnitAmmo`
Work exactly same as old ones but are defined on ammo (or weapon if it do not use ammo).
Title: Re: [Suggestion] Hit side on weapon
Post by: Solarius Scorch on August 04, 2022, 05:43:13 pm
New hooks: `hitUnitAmmo` and `damageUnitAmmo`
Work exactly same as old ones but are defined on ammo (or weapon if it do not use ammo).

Cool, cool.

Will this work on melee weapons?
Title: Re: [Suggestion] Hit side on weapon
Post by: Yankes on August 04, 2022, 06:21:15 pm
Yes, as I said if weapon do not use ammo then weapon itself is checked for this hook.
Rule of thumb is "item that defined damage type that is used to damage unit".
Title: Re: [Suggestion] Hit side on weapon
Post by: Solarius Scorch on August 07, 2022, 12:47:01 pm
Implemented the script, it works just fine.

Which means it's not only correct, but even suitable for morons. :P