Modding Help LUA Help

Discussion in 'Starbound Modding' started by ThatForgottonGuy, Jul 20, 2021.

  1. ThatForgottonGuy

    ThatForgottonGuy Scruffy Nerf-Herder

    I have been working on an item that uses the in game capture mechanics for gun fired capture disks. I created a new LUA file that is a carbon-copy of "scripts/companions/capturable.lua" and called it "scripts/companions/diskcapturable.lua". I have also patched monster.lua to call this new file as well as capturable.lua, with the idea being that the disks have a higher capture health fraction than a capture pod. However, the game reads both files and uses the highest capture health fraction it finds for both, so I'm wondering if there is some way to add in diskcapturable.lua a check for the capture device having been "capturedisk.projectile". I am not terribly skilled with LUA programming, but the few things I've tried have had odd results such as monsters instantly dying on spawn, or not being capturable at all... Any help would be greatly appreciated!
     
  2. ThatForgottonGuy

    ThatForgottonGuy Scruffy Nerf-Herder

    Incase it helps, I believe I would need to add the projectile check into this function:
    Code:
    function capturable.capturable(capturer)
      if capturable.ownerUuid() or storage.respawner then
        return false
      end
    
      local isCapturable = config.getParameter("capturable")
      if not isCapturable then
        return false
      end
    
      local captureHealthFraction = config.getParameter("captureHealthFraction", 0.75)
      local healthFraction = status.resource("health") / status.resourceMax("health")
      if healthFraction > captureHealthFraction then
        return false
      end
    
      return true
    end
     
  3. Zaakari

    Zaakari Pangalactic Porcupine

    The reason for this is that your carbon copy diskcapturable.lua file has all the same function names as the original capturable.lua file. This means that the later script's functions (from diskcapturable) overwrites all the former script's functions; hence the higher value getting used for both projectiles.

    It definitely looks like you've got a good start, though. I do believe you've identified the right function to modify (capturable.capturable). I'm not sure that projectile type can be detected in that script, but I think we should be able to modify some functions in order to pass in some extra information. I don't have tons of time at the moment, but I'm going to attach some files that you can try to implement, and try to walk you through what I think should work (though a little modification might be necessary).

    You probably all ready have your own projectile, but I whipped up a pretty simple copy of the vanilla capture pod named "captureDisk". This projectile has a new field named "captureHealthMultiplier" which the attached script ("capture_disk.lua") utilizes like so:
    Code:
    function hit(entityId)
      if self.hit then return end
      if world.isMonster(entityId) then
      self.hit = true
    
      -- Get the multiplier from the capture_disk.projectile file (or use 1.0 if it doesn't have a multiplier).
      local healthMultiplier = config.getParameter("captureHealthMultiplier", 1.0)
    
      -- Pass the multiplier to the monster's "attemptCapture" function.
      promises:add(world.sendEntityMessage(entityId, "pet.attemptCapture", projectile.sourceEntity(), healthMultiplier), function (pet)
      self.pet = pet
      end)
      end
    end
    
    The thing I'm not sure about in all of this is how to pass extra parameters into that "world.sendEntityMessage" function. You can see that function's definition here. I'm not sure if I can just add an extra parameter on the end like I did above or if it would have to be added within an array (curly braces) like so:
    Code:
    world.sendEntityMessage(entityId, "pet.attemptCapture", {projectile.sourceEntity(), healthMultiplier})
    The other file of importance is the "disk_capturable.lua" which you would need to patch into your monsters.lua as you did your file. I trimmed it down from a "carbon copy" version, as I think there are only two functions that need to be modified (overwritten). I added some comments to the file (and most of the others) to help describe what's going on, so have a look. But if you can't get it to work, let me know.

    I am curious, though, how did you patch the diskcapturable.lua into the monsters.lua file?
     

    Attached Files:

  4. ThatForgottonGuy

    ThatForgottonGuy Scruffy Nerf-Herder

    Thank you very much Zaakari,
    I will take a good stab at this and get back to you! With any luck I'll have some good news, and thanks again!
     
  5. ThatForgottonGuy

    ThatForgottonGuy Scruffy Nerf-Herder

    Zaakari you are a lifesaver!
    Sorry it took so long, but between finishing assets for the Capture Disk Launcher, and figuring out how to implement the code you did, it took a while to get everything working. With that said, it works beautifully! Thank you so much for the help, I never would have been able to get this working so perfectly without the help! One thing to note was a weird error I got with regards to handling nil or negative multiplier values... I just removed the code and patched the base game capture pods to get around the error, but it does leave an interesting handling issue where if a pod or disk has no multiplier it instantly kills the target regardless of health... I may try to fix this in the future, but for now the code works largely as intended, and the handling issue can't occur with the capture pods patched. Thanks again so much, and sorry it took so long to get back to you!
     

Share This Page