aliens

Author Topic: [problem] Strange behavior of damaging_item.setAmmoQuantity in hitUnit script  (Read 102 times)

Offline Kozinsky

  • Colonel
  • ****
  • Posts: 142
  • Sorry for my bEd English
    • View Profile
I have a certain number of guns that can only fire with aimed or snap shots. I made a skill that enables to use this weapon in automatic firing. For this weapon I have set the number of shots when firing automatically to 1 (via “autoShots: 1”). Now in the script “hitUnit” I handle a hit from this weapon on the target and I want that after this shot the number of shots is equal to zero. I use the function “damaging_item.setAmmoQuantity 0;”, but it doesn't work properly - after the script finishes, the weapon has one shot left instead of zero.

For example, I have a weapon in which there are three shots, I activate the skill and shoot, while the bullet flies it can be seen that the number of shots in the weapon became equal to two. Then there is a hit on the target and the script “hitUnit” starts working, the function “damaging_item.setAmmoQuantity 0;” is executed and I see that the weapon now has one shot instead of zero.

I tried using “damaging_item.setAmmoQuantity -1;” but the result is the same - one shot remains.
« Last Edit: December 20, 2024, 02:14:49 pm by Kozinsky »

Offline CrazedHarpooner

  • Colonel
  • ****
  • Posts: 113
    • View Profile
It's probably designed that way to prevent unwanted 0 ammo in clips. Normally said clip ceases to exist as far as I know when it reaches 0. Ideally you would need a script operation that would "destroy" the clip in the weapon, but I don't see one.

Alternatively, note that rulesets allow you to define how any shots are consumed for each shot action type, perhaps the example provided here will help with what you want to do https://openxcom.org/forum/index.php?topic=9293.msg135896#msg135896

Offline Kozinsky

  • Colonel
  • ****
  • Posts: 142
  • Sorry for my bEd English
    • View Profile
This works, but only partially, because this feature requires the weapon to be loaded for at least the specified number of shots. If less than that, the user gets a message that the weapon does not have enough shots. In my example, the weapon accepts different clips with different numbers of shots, and I need them all to be fully discharged after a shot. I also need the weapon to empty if a loaded clip is not full.

I tried to discharge weapons in the “skillUseUnit” script - there the function “setAmmoQuantity 0;” also leaves one shot in the weapon, but then when the user shoots, this last shot is consumed. However, it looks terrible.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3374
    • View Profile
`setAmmoQuantity` have limit that it can only set min 1 as ammo count. This is to prevent clashes with engine and its removal of used ammo.
I would probably need add "script cleanup" after each script to remove all items that reach "zero" ammo count. This would require some work and
thus I added limit to make overall code simpler.

If this current behavior is very problematic I could consider changing it and implement proper "item cleanup", hat any ammo any where have clip size 0 then it will be removed from game.

Offline Kozinsky

  • Colonel
  • ****
  • Posts: 142
  • Sorry for my bEd English
    • View Profile
That would be logical, but not urgent.