Shoot2Scoot

by Theis

Applies high recoil to firing weapons, allowing for extra mobility. Biters are not recommended.

Tweaks
a month ago
1.1
13
Transportation Combat Cheats

g Consider passengers when checking vehicles!

a month ago
(updated a month ago)

Hi! I just had to check out your mod because one of my own mods (Autodrive) has something similar to your recoil effect: it lets vehicles bounce on collision. Something I've noticed in your function apply_recoil():

  -- Extremely horrible way to get the target position of an effect
  -- No, event.target_entity.position doesn't work. It just gives the source position.
  local shooting_state
  if source.type == "character" then
      shooting_state = source.shooting_state
  elseif vehicle_types[source.type] then
      local driver = source.get_driver()
      if driver == nil then return end
      if driver.type ~= "character" then return end
      shooting_state = driver.shooting_state
  end

Autodrive handles vehicles based on car and on spider-vehicle prototypes. When a vehicle is autodriving, there may be a player or character inside -- but it is not guaranteed. If no player has entered the vehicle, Autodrive may create a dummy character and use it as vehicle.passenger. This happens when the vehicle is following a path where it must open gates, or if it has sensed enemies within range of its selected weapon (if that has ammo).

Your mod will miss auto-driving vehicles that have a dummy passenger but no driver. I suggest the following change to fix that:

  local shooting_state
  if source.type == "character" then
      shooting_state = source.shooting_state
  elseif vehicle_types[source.type] then
      local shooter
      if source.type == "car" or source.type == "spider-vehicle" then
        shooter = source.driver_is_gunner and source.get_driver() or source.get_passenger()
      else
        shooter = source.get_driver()
      end
      if (not shooter) or shooter.type ~= "character" then return end
      shooting_state = shooter.shooting_state
  end
a month ago

Thanks for the response and code.
I don't think i will implement it at this time, as the goal of this mod is to move the character.
You are of course free to fork the mod, implement it and set the values of recoil to something sensible for your needs.

New response