Author Topic: [Answered] New Modscript hook: fire_weapon, to get "pump action" for a shotgun  (Read 3426 times)

Offline Eddie

  • Commander
  • *****
  • Posts: 560
    • View Profile
Heya,

so I wanted to create a script to give a shotgun "pump action". Meaning that after you fired a shot, you would need to pump the shotgun to chamber the next round. I want to block any fire modes with a different action that needs to be performed before the next shot can be fired. Other uses of such a script could be bolt action rifles and crossbows or bows where the arrows/bolts are not individual items but packs. Another possibility is a charge-up energy weapon.

I'm no scripting expert yet, but I think right now the functionality to create such a script is not available. Feel free to correct my if I'm wrong. I would need a "fire_weapon" hook for a start. Not sure what else I need...

« Last Edit: February 19, 2023, 10:31:24 am by Meridian »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3347
    • View Profile
This is right now not possible

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9078
    • View Profile
A "script hook" is a place in the source code where:
1. normal program execution stops
2. the currently processed variable holding some number (e.g. damage to be dealt to a target unit) is passed to a script
3. script executes and potentially transforms that number into a different number (e.g. damage 100 to damage 200)
4. the new number is assigned to the currently processed variable
5. normal program execution is resumed

Or in simpler words... a place where you can change a value of some variable from value A to value B, using a script that does some math.


What number/variable would your "fire_weapon" hook be changing?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
You'd need multiple hooks for this most likely - first, one on firing that would be capable of setting a tag on the weapon to mark that it fired. Then another on adding items to the list of actions when clicking a weapon, capable of setting the name of the action and its cost. Then finally another, or possibly another version of the first that reads the tag that was set to prevent the shot, but it resets the tag.

The "on firing" hook itself is probably easier to tackle, but as Meridian said we'd have to pick what number should be altered by the script that would be important here. Maybe something like a chance of preventing the firing from happening, or amount of ammo consumed? I'm somewhat interested in a script like this as well to have energy weapons that have more powerful shots that take up more of a battery than a lower power shot, but it's a low priority for me.

The alterations of the action menu items in a script will likely never happen as the costs and types of actions are important "constants" throughout the code.

I guess if the "on firing" hook could determine both a chance of the shot firing and the ammo consumed by the shot, you could make two actions on the shotgun: 1. firing, which sets a tag on the weapon saying it just fired, but is scripted to not shoot or consume ammo if 'just fired' is set and 2. pumping, which resets the 'just fired' tag.

More importantly, what would pumping a shotgun add to a mod that increasing the TU cost of firing wouldn't? It seems to me like extra fine-grain detail for detail's sake, not making the game more enjoyable.

Offline Eddie

  • Commander
  • *****
  • Posts: 560
    • View Profile
Ok, I thought this would be way easier to implement. If it's that complicated forget about it, not worth the trouble.

Now that I think about it, it's probably a bad idea anyway. The AI wouldn't be able to handle it and multiple reaction shots would be a problem as well.

Offline Eddie

  • Commander
  • *****
  • Posts: 560
    • View Profile
Re: [Suggestion] New Modscript functionality
« Reply #5 on: February 24, 2020, 02:53:54 am »
Ok, here is my next attempt to do something useful with the modscript: marksman targeting of weak armor side

functionality: if the attack accuracy is higher than x, there is a chance of (accuracy - x)% to purposefully target the weak part of the opponent armor (if it exists and is hittable from that direction)

I can get the facing of the attacker, facing of the unit hit, and the armor on all sides of the unit hit. From this I can calculate if there would be a preferable part of the armor that should be aimed for, and if it is possible that this armor part can be targeted.
What I think the modscript can't do right now: give me the accuracy value that was used for the attack.
Yes, I can get the firing skill of the attacker and the accuracy of the weapon used and calculate it this way. But I think this would not include any accuracy reductions because of range or no line of sight. I would also get wrong results if any other skill than firing is used as a skill to calculate accuracy.

Other thing I have not found out how to do is to check if it is an area type weapon. That would always hit under armor for a direct hit and would not be targetable for an area of effect directional hit.
What I would also like to check for is if attacker and hit unit are on the same team. Though an accidental friendly fire hit is rare at the accuracies this script should activate at, I want to check for it none the less. A friendly fire hit would not have increased chance of targeting the weak part of the armor.

So, are the things I want to do possible with the current modscript functionality?
If no, are they easy enough to add that I wont feel bad for asking them to be added?

Offline Bobit

  • Colonel
  • ****
  • Posts: 186
    • View Profile
Re: [Suggestion] New Modscript functionality
« Reply #6 on: February 26, 2020, 06:00:42 pm »
The answer is going to be no, you're asking the scripts to access too many variables like Inventory and Facing. Here are some alternatives with a similar gameplay effect:

Simply increase armor penetration on weapons that require high accuracy to be used effectively. Most games and mods do this.

A pump action weapon, that is a weapon that is easy to reload the first time but hard to reload the sixth, is implemented using a quickdraw slot. Increase inventory movement costs, then make a slot which has very low inventory costs when moving to the hand, but is only 1 row high. Then make all ammo that you want to be easy to reload the first time but hard to reload later 1 row high, and all other ammo 2 rows high. In the popular mods these tend to be weapons like Shurikens which are easy to reload the first few times, while Crossbows have a very difficult time reloading. You're surely already aware of this technique, but it can be further emphasized by increasing costs and making frequent 2-row ammo.
« Last Edit: February 26, 2020, 06:03:27 pm by Bobit »