Modding Help Liquid Pump code?

Discussion in 'Starbound Modding' started by Meteor_Strike, May 23, 2015.

  1. Meteor_Strike

    Meteor_Strike Scruffy Nerf-Herder

    Basically, I have a slight understanding of how to use Lua, but only the most basic. I've worked with Java, C#, and Visual Basic a bit, so I can figure much of it out from context. That being said, I have no idea of how to go about creating a part of a mod I'm building.

    I intend to have a set of liquid pumps in this mod where they could be placed in a liquid, be turned on and off via wiring, and have small 3 slot inventories. Upon being activating one, it would drain any liquid touching it into its inventory, much like when you collect liquid with your beam tool.

    Now, here's the lame part. I haven't the slightest idea of how to build that script. So, I was hoping that someone might be willing to build me a template. Once I have the template, I should be able to modify it myself to have the separate types. I just need it to have a speed variable I can change.

    If someone could help me, or at least direct me to a mod that has the code so I can look at it and figure it out, I would be eternally grateful.
     
  2. Kayuko

    Kayuko Oxygen Tank

    That's quite the difficult code.
    You would have the object to be a container.
    Then, theres the node part, see below.
    You would also need to detect the liquid, or rather how far the liquid on the block placed goes.
    If that value is true, it would need to pump the liquid, so you would need to detect which KIND of liquid it is.
    You'd then push that to the free container slot of the item. (As in, remove it from the spot and add an instance of the liquidId to the container, not transfering the liquid.)

    Just a note here, I'm not sure how advanced of a coder you are, but that's FAR from basic stuff.

    /objects/wired/liquidsensor
    /objects/wired/shieldgenerator
    /objects/scripts/autofill

    These can help you getting started.
    I can't recall an instance of container specific lua atm, but just check this documentation part.

    This should be everything you need to get started.

    There are some people that worked on something like this, I'm not too sure who it was tho.
    Maybe you'll get a response here, but for lua questions like THIS I really recommend joining the irc at ##starbound-modding while you develop the mod.
    You will most certainly come up with tons of questions, they can be answered there more easily then in the forum.

    I wish you good luck tho!X3
     
    Meteor_Strike likes this.
  3. Meteor_Strike

    Meteor_Strike Scruffy Nerf-Herder

    Thanks! I figured that it probably wouldn't be too easy, but looking at those scripts it's quite a lot harder than I thought. o_O

    This may take awhile and be rather difficult. But hey, at least that means that no one else is likely to do it! :p
     
    Kayuko likes this.
  4. Kayuko

    Kayuko Oxygen Tank

    If someone will be looking for that in the future:

    Code:
    function init()
        entity.setInteractive(true)
        t = {
        "liquidwater", 
        "liquidlava", 
        "liquidpoison",
        "liquidalienjuice",
        "liquidoil",
        "liquidhealing",
        "liquidmilk",
        "liquidlava",
        "liquidcoffee",
        "liquidwater",
        "liquidfuel",
        "swampwater",
        "liquidoil"}
        isActive = nil
    end
    
    function onNodeConnectionChange(args)
      if entity.isInboundNodeConnected(0) then
        onInboundNodeChange({ level = entity.getInboundNodeLevel(0) })
      end
    end
    
    function onInboundNodeChange(args)
      if args.level then
          isActive = true
      else
          isActive = false
      end
    end
    
    function update(dt)
        local liquid = t
        local sample = world.liquidAt(entity.position())
    
        if entity.isInboundNodeConnected(0) and isActive and sample[1] == 1 then
            world.containerAddItems(entity.id(), liquid[1])
            world.destroyLiquid(entity.position())
        elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 2 then
            world.containerAddItems(entity.id(), liquid[2])
            world.destroyLiquid(entity.position())       
        elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 3 then
            world.containerAddItems(entity.id(), liquid[3])
            world.destroyLiquid(entity.position())
        elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 4 then
            world.containerAddItems(entity.id(), liquid[4])
            world.destroyLiquid(entity.position())
        elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 5 then
            world.containerAddItems(entity.id(), liquid[5])
            world.destroyLiquid(entity.position())
        elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 6 then
            world.containerAddItems(entity.id(), liquid[6])
            world.destroyLiquid(entity.position())
        elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 7 then
            world.containerAddItems(entity.id(), liquid[7])
            world.destroyLiquid(entity.position())
         elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 8 then
            world.containerAddItems(entity.id(), liquid[8])
            world.destroyLiquid(entity.position())
         elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 9 then
            world.containerAddItems(entity.id(), liquid[9])
            world.destroyLiquid(entity.position())
         elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 10 then
            world.containerAddItems(entity.id(), liquid[10])
            world.destroyLiquid(entity.position())
         elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 11 then
            world.containerAddItems(entity.id(), liquid[11])
            world.destroyLiquid(entity.position())
         elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 12 then
            world.containerAddItems(entity.id(), liquid[12])
            world.destroyLiquid(entity.position())
         elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == 13 then
            world.containerAddItems(entity.id(), liquid[13])
            world.destroyLiquid(entity.position())
         elseif entity.isInboundNodeConnected(0) and isActive and sample[1] == nil then
            world.containerAddItems(entity.id(), "perfectlygenericitem")
            world.destroyLiquid(entity.position())
         end
    
    end
    
     
  5. Meteor_Strike

    Meteor_Strike Scruffy Nerf-Herder

    Holy crap, Kayuko. I am simultaneously extremely impressed and confused. :p

    Would you care if I copied this script and gave it a sprite and item that goes with it so it is usable as a mod? I'll give credit to you. I think even if I tried to take all the credit myself, no one would believe it was actually me. :rofl:
     
  6. Kayuko

    Kayuko Oxygen Tank

    Sure, keep in mind to declare the object as container tho, and edit the chest config to a 3-slot one if you only want 3 slots.
     
  7. Meteor_Strike

    Meteor_Strike Scruffy Nerf-Herder

    Okay! Thanks! Gonna start working on it right now! :D
     
  8. Azraile

    Azraile Ketchup Robot

  9. Wellbott

    Wellbott Existential Complex

    That massive switch statement can be collapsed a bit, into
    Code:
    if entity.isInboundNodeConnected(0) and isActive and sample and sample[1] and liquid[sample[1]] ~= nil then
      world.containerAddItems(entity.id(), liquid[sample[1]])
      world.destroyLiquid(entity.position())
    end
    
    Also note that I think world.liquidAt returns nil when it finds no liquid, so calling sample[1] there would crash the script.
     
    UnknownX and Kayuko like this.

Share This Page