Modding Help Making disposable weapons

Discussion in 'Starbound Modding' started by supredude11, Mar 25, 2020.

  1. supredude11

    supredude11 Void-Bound Voyager

    So, I've been trying to make some powerful guns for Starbound. But to balance them out they will be disposable and will have limited uses. The problem is that I can't seem to figure out how to do that. Adding durability doesn't seem to work, nor does trying to make the gun consumable. If anyone can help me out, that'd be great.
     
  2. Isaac MacPherson

    Isaac MacPherson Scruffy Nerf-Herder

    Perhaps you could make multiples of them and have them function like spears and bombs?
     
  3. supredude11

    supredude11 Void-Bound Voyager

    I've looked into it and throwable items are a separate type of item and the tags that cause them to be consumed don't seem to work on guns.
     
  4. Sock_Bunny

    Sock_Bunny Existential Complex

    (note to self: 'tab' sends post)
    you'll need to make a copy of the script that guns use, and modify the activate function

    function activate(<your args here>)
    if <requirements for gun to shoot> then
    activeItem.setInstanceValue("supredude11_gunUses",config.getParameter("supredude11_gunUses",5)-1)
    if config.getParameter("supredude11_gunUses") <= 0 then item.consume(1) end
    end


    in the item file, add a new parameter called "supredude11_gunUses" and set it to the number of times the gun can be shot
    "supredude11_gunUses" : 5

    means the gun can be shot 5 times before it vanishes from the players hands
     
    Isaac MacPherson likes this.
  5. supredude11

    supredude11 Void-Bound Voyager

    in the line
    activeItem.setInstanceValue("supredude11_gunUses",config.getParameter("supredude11_gunUses",5)-1)
    what does the 5 at the very end mean?

    also if possible could you break down the bit of code that you posted?
    I'm a bit new and don't quite understand whats happening
     
    Last edited: Apr 6, 2020
  6. Sock_Bunny

    Sock_Bunny Existential Complex

    the 5 is the default value. if the gun doesn't have the parameter, it'll use 5 instead
     
  7. supredude11

    supredude11 Void-Bound Voyager

    what kind of requirements for the gun to shoot are there? Like primary fire?
     
  8. Sock_Bunny

    Sock_Bunny Existential Complex

    yep! it's best to just add the line of code to a copy of gun.lua though
     
  9. Isaac MacPherson

    Isaac MacPherson Scruffy Nerf-Herder

    How do you do that? Is it like dot-patch files? Or does it just replace code like graphics mods do?
     
  10. supredude11

    supredude11 Void-Bound Voyager

    ok i will try that
     
  11. supredude11

    supredude11 Void-Bound Voyager

    So I put in the code into an copied gun.lua and this is what it looks like:
    Code:
    require "/scripts/util.lua"
    require "/scripts/vec2.lua"
    require "/items/active/weapons/weapon.lua"
    
    function init()
      activeItem.setCursor("/cursors/reticle0.cursor")
      animator.setGlobalTag("paletteSwaps", config.getParameter("paletteSwaps", ""))
    
      self.weapon = Weapon:new()
    
      self.weapon:addTransformationGroup("weapon", {0,0}, 0)
      self.weapon:addTransformationGroup("muzzle", self.weapon.muzzleOffset, 0)
    
      local primaryAbility = getPrimaryAbility()
      self.weapon:addAbility(primaryAbility)
    
      local secondaryAbility = getAltAbility(self.weapon.elementalType)
      if secondaryAbility then
        self.weapon:addAbility(secondaryAbility)
      end
    
      self.weapon:init()
    end
    
    function update(dt, fireMode, shiftHeld)
      self.weapon:update(dt, fireMode, shiftHeld)
    end
    
    function uninit()
      self.weapon:uninit()
    end
    
    function activate()
    if primaryAbility then
    activeItem.setInstanceValue("supredude11_gunUses",config.getParameter("supredude11_gunUses",5)-1)
    if config.getParameter("supredude11_gunUses") <= 0 then item.consume(1) end
    end
    also note that the function at the very end is the only thing that I added/changed
     
  12. supredude11

    supredude11 Void-Bound Voyager

    Now, in the game, without the function you posted, the script works fine. With the function though, the gun will not aim or shoot and instead just points horizontally.
     
  13. Isaac MacPherson

    Isaac MacPherson Scruffy Nerf-Herder

    Where does the modified lua file go after modifying it? Back into the base files? Into a mod that you want it to be a part of?

    As I said in another thread, I don't fully understand lua, and any tips would be greatly appreciated.
     
  14. Sock_Bunny

    Sock_Bunny Existential Complex

    that should be an easy fix. can you tell me what ability the weapon uses, though? I think we'll have to edit the ability script
     
  15. supredude11

    supredude11 Void-Bound Voyager

    it uses a standard gunfire ability. here is the code for the ability, which is in the item file directly
    Code:
      "primaryAbility" : {
        "scripts" : ["/items/active/weapons/ranged/gunfire.lua"],
        "class" : "GunFire",
    
        "fireTime" : 0.1,
        "baseDps" : 8.0,
        "energyUsage" : 10.0,
        "inaccuracy" : 0.05,
        "projectileCount" : 1,
    
        "burstCount" : 4,
        "burstTime" : 0.1,
        "fireType" : "burst",
    
    
        "projectileType" : "hmgbullet",
        "projectileParameters" : {
          "knockback" : 10
        },
        "stances" : {
          "idle" : {
            "armRotation" : 0,
            "weaponRotation" : 0,
            "twoHanded" : true,
    
            "allowRotate" : true,
            "allowFlip" : true
          },
          "fire" : {
            "duration" : 0,
            "armRotation" : 3,
            "weaponRotation" : 3,
            "twoHanded" : true,
    
            "allowRotate" : false,
            "allowFlip" : false
          },
          "cooldown" : {
            "duration" : 0.10,
            "armRotation" : 3,
            "weaponRotation" : 3,
            "twoHanded" : true,
    
            "allowRotate" : false,
            "allowFlip" : false
          }
        }
      },
     
  16. supredude11

    supredude11 Void-Bound Voyager

    as well with the modified lua file, you put into the mod folder. somewhere where the item file can reference it without problems.
     
  17. Isaac MacPherson

    Isaac MacPherson Scruffy Nerf-Herder

    So it's like how images in mods replace images in the base files?
     
  18. supredude11

    supredude11 Void-Bound Voyager

    sort of. it's like when making a new item. It doesn't interfere with the base game however your mod adds it so that your other things can use it. this applies to weapon abilities, projectiles, sfx, etc.
     
    Isaac MacPherson likes this.
  19. supredude11

    supredude11 Void-Bound Voyager

    I'm kinda still not sure what to do.
     

Share This Page