help with making a harvester

Place to get help with not working mods / modding interface.
McSpiffy
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon May 05, 2014 9:17 pm
Contact:

Re: help with making a harvester

Post by McSpiffy »

Ok so.... 2 things 1st seems to be a miner bug on line 34. The Harvester will mine but when there is 1 ore left the game crashes.
2014-05-15 23_18_17-Greenshot.jpg
2014-05-15 23_18_17-Greenshot.jpg (297.05 KiB) Viewed 5783 times
I tried to make it so it was if

Code: Select all

ore.amount <= ore.amount - oreAmount
but the game wont load
And 2nd would be the refinery still won't place the ore on the ground maybe its just I didn't set the storage position correctly like you said on line 87 I have been messing with it a bit but still no anvil.
So I'm going to up load the mod here so you could take a look at it.
harvester-mod.rar
(594.46 KiB) Downloaded 180 times
And once again thank you for all the help if it weren't for you none of this mod would be possible and I am very grateful
Update: I Seem to have fixed the 2nd problem. I had to change

Code: Select all

          elseif #storageEntities == 0 then
on line 102 to

Code: Select all

          elseif #storageEntities >= 0 then
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: help with making a harvester

Post by FreeER »

ok, 1 was a simple bug that I didn't realize was a bug lol (apparently you can not set the ore.amount to less than 1)
As for 2, it works for me.... edit: oh, oops i see what I did now... I thought I'd keep it from simply placing the items on top of everything that way and forgot that it'd see a transport belt as a regular entity and then not place the ore there lol. yeah that's probably the simplest fix... the 'better' way would be to check if (one of) the entities that it found were transport belts (that's what I've done below).
Control.lua
btw, the refinery inventory...is absolutely huge, it actually goes a bit off of my screen (on a laptop) :lol:
https://www.dropbox.com/s/cfsn3uwfdbwzaco/refinery.png, sigh silly img tag doesn't work for dropbox apparently
btw, the chest there (if you can see it through the inventory screen) is where the refinery was outputting items (before I place the chest it'd place a piece of ore down)
McSpiffy
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon May 05, 2014 9:17 pm
Contact:

Re: help with making a harvester

Post by McSpiffy »

Ok kool everything seems to work fine now Thanks! :D
Yea sry for the inventory i made it 3x the size of the harvester's inventory so I could dump full loads of ore. It fits on my 1920 x 1080 res monitor. I didn't realize the Gui
didn't get re-sized on different resolutions. I might just make it 2x the size of the harvester's inventory.

Time for me to work on getting the harvester to dump its cargo now ^_^

Update: Harvester still depletes ore fields after its inventory has filled up tiny bug. I will see what I can manage to come up with as a fix.
Last edited by McSpiffy on Fri May 16, 2014 4:41 am, edited 1 time in total.
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: help with making a harvester

Post by FreeER »

McSpiffy wrote:I didn't realize the Gui didn't get re-sized on different resolutions
Yeah, it's one of the more annoying um, features, yeah, of Factorio :) I hope they get some time in 0.10 or 0.11 to change that (and add scrollbars to really long lists of inventories, filters menus, etc)
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: help with making a harvester

Post by rk84 »

Instead using pairs() for getting one pair out of table, you could use next(table, key)

Code: Select all

local  name, count = next(refinery.getinventory(defines.inventory.chest).getcontents(), nil) -- nil key makes it return first pair
item = {name=name, count=count}
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: help with making a harvester

Post by FreeER »

rk84 wrote:Instead using pairs() for getting one pair out of table, you could use next(table, key)
hm, yeah you're right. I figured there was a different way but I wasn't sure what it was :lol:
McSpiffy
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon May 05, 2014 9:17 pm
Contact:

Re: help with making a harvester

Post by McSpiffy »

Ok so how should I go about adding the code to make the harvester empty Its "trunk" into the refinery? Also Is it possible to add a "Dumping" animation when Its over the refinery? And one more question Is it possible to set the animation property in the entity file(harv_entity) to a variable and use the control lua to tell what animation or sprite sheet to use under certain conditions example :
harv_entity : pictures = "animation_state"
controle.lua
if havrester is on ore then
get direction(?)
if harvester.direction = North then
animation_state = "N_mining"
N_mining=
{
filename = "__harvester-mod__/graphics/entity/harvester/north-sheet.png",
line_length = 5
frame_width = 140,
frame_height = 110,
shift={0.5, 0},
axially_symmetrical = false,
direction_count = 64
},
if harvester.direction = south then
animation_state = "S_mining"
S_mining=
{
filename = "__harvester-mod__/graphics/entity/harvester/south-sheet.png",
line_length = 5
frame_width = 140,
frame_height = 110,
shift={0.5, 0},
axially_symmetrical = false,
direction_count = 64
},
and so on
then else if its not on ore or refinery revert back to the original sprite sheet.
else if harvester. not on ore
animation_state = "normal"
normal =
{
filename = "__harvester-mod__/graphics/entity/harvester/harv-sheet.png",
line_length = 8,
frame_width = 140,
frame_height = 110,
shift={0.5, 0},
axially_symmetrical = false,
direction_count = 64
},
yes? no?
I just can't think of a way for the harv_entity file to read from the control.lua
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: help with making a harvester

Post by FreeER »

McSpiffy wrote:Is it possible to set the animation property in the entity file(harv_entity) to a variable and use the control lua to tell what animation or sprite sheet to use under certain conditions
no, this is not possible. You can not change the prototypes from the control.lua at this time. You can make an interface request for this, but it'll be up to the developers to implement it (and I don't think the 0.10 release date is too far off so it might not make it in until 0.11).
McSpiffy wrote:Ok so how should I go about adding the code to make the harvester empty Its "trunk" into the refinery?
For this I'd probably just add something like this on line 44 (before the end of the if statement on line 24)

Code: Select all

-- find refinery's within a 5x5 square centered around the vehicle
local refineries = game.findentitiesfiltered{name="refinery", area=getBoundingBox(game.player.vehicle.position, 5)}
if #refineries > 0 then -- if the returned table has at least one entry
   -- I think this is the correct inventory...I might be wrong
  local inventory = game.player.vehicle.getinventory(2)
  local contents = inventory.getcontents()
  local itemstack = {} -- temp var
  for name, count in pairs(contents) do
    itemstack.name = name
    itemstack.count = count
    -- loop through found refineries (err on side of caution, a radius of 5 might find more than one refinery)
    for _, refinery in pairs(refineries) do 
      if refinery.caninsert(itemstack) then -- if this refinery can hold the items
        refinery.insert(itemstack)
        inventory.remove(itemstack) -- remove from inventory (the harvester)
        break
        -- do not continue looking at the next refinery...this might be optimized by
        -- removing the full refinery from the refineries table...
        -- but it has a few caveats, if the refinery can accept say, 
        -- copper but not iron, then if you had both in the harvester the refinery 
        -- might not be filled properly, you'd also need a check for if
        -- the one you removed was the last possible refinery
      end
    end
  end
end
Since all of that is within the if statement on line 24 it requires the player to stay in the harvester, you could however use (in a loop over the glob.refineries table) game.findentitiesfiltered{name="harvester", area=getBoundingBox(refinery.pos, 5)}, and that way the player doesn't need to be in the harvesters, but it's also a bit more game intensive (since it must search the areas around all the refineries rather than just search for refineries around the harvester the player is in). You also might have noticed the for loop over the refineries, if it's impossible to get more than one refinery in the radius that loop can be removed (and just use the if statement without the break), though it shouldn't have a significant performance impact even if it's impossible to have more than on refinery in that radius (and 'future-proofs' the code against future changes that might allow such possibilities) :)
McSpiffy
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon May 05, 2014 9:17 pm
Contact:

Re: help with making a harvester

Post by McSpiffy »

Good stuff! I just got done tweaking it a bit and everything seems to be running great. I just need to do a bit more to it before I can release it. I need to set it so the harvester won't collide with the refinery is there a way to do that in the control.lua or should I just remove the collision box from the refinery? Also the refinery won't out put ore if it placed in the map editor and played after but if picked back up and placed it works fine. Minor bug was driving me crazy when trying to test >.<
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: help with making a harvester

Post by FreeER »

McSpiffy wrote: I need to set it so the harvester won't collide with the refinery is there a way to do that in the control.lua or should I just remove the collision box from the refinery?
I do not think this is possible with control.lua since it's part of the prototype of the entity(ies), you can remove the collision box or play around with collision masks (collision_mask = {"mask1", "mask2", "etc"}, the collision layers/masks are documented on the wiki here).
McSpiffy wrote:Also the refinery won't out put ore if it placed in the map editor and played after but if picked back up and placed it works fine. Minor bug was driving me crazy when trying to test >.<
This is because the code can only check the glob.refinery table which only gets entries from when the player places the refinery, you can add a script interface and/or use some code to insert entities that were given 'tags' in the map editor to get this to work.
script interface

Code: Select all

-- this can simply be at the bottom of your control.lua
-- to activate this function you'd type remote.call("harvester", "findrefineries" [, radius]) into the console
-- radius is optional, thus the square brackets
remote.addinterface("harvester",{
  findrefineries = function(radius)
    if radius and (radius < 1) then
      game.player.print("Radius must be greater than or equal to 1, it defaults to 10")
      return
    end -- a bit of error checking for 0 or negative radii
    local radius = radius or 10 -- sets radius to either pass parameter or 10 as a default
    local refineries = game.findentitiesfiltered{name="refinery", area=getBoundingBox(game.player.position, radius)}
    if #refineries > 0 then
      local isNew
      local totalNew = 0
      for _, refinery in ipairs(refineries) do
        isNew = true -- assume it's a new refinery, until tested in the next for loop
        for _, globref in pairs(glob.refineries) do
          if globref.valid and globref.equals(refinery) then
            isNew = false
            break
          end
        end
        if isNew then
          table.insert(glob.refineries, refinery)
          totalNew = totalNew + 1
        end
      end
      -- could add a script locale for these strings if you want translations to be possible
      game.player.print("Found "..totalNew.." new refineries, "..#glob.refineries.." are now known")
    else
      game.player.print("No refineries found") -- same here
    end
  end
})
now for the map editor discovery code

Code: Select all

-- I think this would be in oninit...not sure if oninit would fire on opening of edited maps though
-- if not it'd need to be in onload and you'd need a loop like the script interface
table.insert(glob.refineries, game.getentitybytag("tag name"))
obviously you could have a table of tag names and use a for statement to loop through it and call getentitybytag with each name instead of copy/pasting this line several times for multiple refineries.

The loop in the script interface code (and that I alluded in the map editor discovery code) is one that loops through the glob.refineries table and makes sure that the refinery about to be added is not already in the glob table...otherwise you could get duplicate entries :)

edit: the script interface is more flexible since it allows for finding refineries placed by construction robots or console game.createentity commands, however it requires user interaction (even if you were to add a gui that ran it when clicking a button, it's not automatic like the map editor code is, of course you can have both) :)
McSpiffy
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon May 05, 2014 9:17 pm
Contact:

Re: help with making a harvester

Post by McSpiffy »

Is there a way to remote call without needing to have the player use the console? I would to prefer not needing to use it. I could just leave it the way it is. I don't think its a big deal I could just make a note of it when I update the mod.
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: help with making a harvester

Post by FreeER »

McSpiffy wrote:Is there a way to remote call without needing to have the player use the console?
You can run that function when the player does something (like hovering over a certain area of the screen [time buttons and few other mods] or placing an entity on the ground [fmod], etc) or use a gui and a button within that gui and then tie that scan function to run when the button is clicked...I haven't actually used the guis yet however so you'd need to read the wiki and probably look at a few of the mods that use it (timebuttons, testingmode, fmod, etc.) to learn how to implement it yourself, it shouldn't be particularly difficult. Of course, you'd either need that gui to pop up whenever the game is loaded (which might be annoying for users who don't actually need it) or only pop up the gui when the player does something (see prior examples). It's possible to do it, but considering how rare it probably is to need it then it's usually easier to just use the console imo...I guess it really depends on if you want to put a bit more effort into it :)
McSpiffy
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon May 05, 2014 9:17 pm
Contact:

Re: help with making a harvester

Post by McSpiffy »

lol well idk if im up for that today maybe in the future. But I am have a problem with get my tech to pop up when running the game I want to make it so you need to research something in order to be able to craft the items in the mod. I have made a tech.lua and have added it to my data.lua but it still won't show >.>
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: help with making a harvester

Post by FreeER »

McSpiffy wrote:I have made a tech.lua and have added it to my data.lua but it still won't show
hm, I can't think of anything other than not having the data:extend({...}) in the tech file, so I'd probably have to see the code to pin-point anything
McSpiffy
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon May 05, 2014 9:17 pm
Contact:

Re: help with making a harvester

Post by McSpiffy »

Code: Select all

data:extend({
    type = "technology",
    name = "Old-World-Harvesting",
	    prerequisites = {"logistics-2", "engine"},
    icon = "__harvester-mod__/graphics/icons/refin_icon.png",
    effects =
    {
	   {
        type = "unlock-recipe",
        recipe = "harvester"
       },
	   {
        type = "unlock-recipe",
        recipe = "refinery"
       },
    },
    unit =
    {
      count = 100,
      ingredients =
      {
        {"science-pack-1", 2},
        {"science-pack-2", 1}
      },
      time = 20
    }
})
nvm i figured it out i was missing some more {}
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: help with making a harvester

Post by FreeER »

hm, must have been a slow down on email somewhere, I just got the notification that there was a post here...well at least you found it :D
McSpiffy
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon May 05, 2014 9:17 pm
Contact:

Re: help with making a harvester

Post by McSpiffy »

lol Np thanks again for everything ^0^
Post Reply

Return to “Modding help”