Simple help needed

Place to get help with not working mods / modding interface.
Post Reply
bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Simple help needed

Post by bblewittAG »

I have just created my first mod in Factorio and it is very basic but only to get use to the code and how things work within the game.

All I need help with is adding a trash can to Factorio where it deletes the item in the 1 and only slot from the game so for an example:
I put in there 20 wood and then click confirm and it is deleted from the world.

Another thing I need help with is adding a crafting tab for all my own recipes that I want to add.

This mod is personal and not being public yet and before anyone asks yes it is a bit of a cheat but I will take that out soon as I am done with everything that I want to add. Just to confirm that I do play Factorio legit and I only use the quick recipes for testing purposes only.
If anyone needs to see the code then PM me with a good enough reason and I will show you it.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Simple help needed

Post by FreeER »

um, I'd suggest testing mode mod for free items rather than 'test' recipes to be honest, though if you actually need recipes then new tabs are created by making an "item-group" prototype, see data/base/prototypes/item/item-groups.lua (and giving the group's name as the subgroup property of, well the base game places it in the item prototype, but the oil recipes have the subgroup="fluid" so perhaps it'd work fine there as well?)

As for deleting items, if there is only a single slot in the inventory you can use entity.getinventory(defines.inventory.chest).clear() (assuming it's a chest/container, if not check data/core/lualib/defines.lua or test various numbers to find the right one...), you can use the command entity.removeitem{name="name", count=x} to remove a certain number of a certain item (or the "remove" function on an inventory, same argument/parameter, different name for some reason). Of course you could create a function in the console with those, or for a remote interface, or place them in a file in the lualib directory (which Factorio will load for you), or I made a simple dev null (direct) chest mod a while back that you could use/look at.

edit: if for some reason you want only a specific slot to be cleared...that may not be possible perfectly. you can use entity.getinventory(x)[y] to select a slot, but you can't just assign it a value (like nil ) or call destroy()/clear()/remove() on it so you'd have to get the name and count of the stack in that slot and then call removeitem/remove (and kind of hope that it doesn't find that same item in a different slot before it gets to the one you wanted to clear). Perhaps there's a better way to do that, but I'm not currently aware of it.

edit2: right.. I should probably lnk to the dev null mod if I expect you to find it.

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

It is a personal preference to add recipes to the game for testing purposes and I know it is more work for myself :)

for links to the mod/other help I need would be nice to have so that I can quickly look at it and I am doing this in any spare time I have and I don't have a lot because since 0.9.x I have made the mod and now it is 0.10.12 and not be able to get help due to no spare time to do it in and it may take like another 5 to 10 updates to add them in :)

FreeER for your tutorial on how to mod could you add a section in at the end for packaging the mod so that it does not mess up the resources need for an item, example
lab would need 0.2 of iron plate and 0.0 of copper plate.
I have fixed that myself by zipping the folder up like shown in the attachments and I have blacked out the mod name and my PC name for reasons of ID + don't want the mod name shown.
Attachments
mods folder.PNG
mods folder.PNG (6.72 KiB) Viewed 5750 times
mod.PNG
mod.PNG (51.93 KiB) Viewed 5750 times
mod zip.PNG
mod zip.PNG (43.39 KiB) Viewed 5750 times

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Simple help needed

Post by FreeER »

bblewittAG wrote:for links to the mod/other help I need would be nice to have so that I can quickly look at it
the inventory info is on the wiki here I already added a link for the dev null mod, the only other information would be entity.removeitem and entity.getinventory which are on the wiki here. of course if you can remember the name you can just search it on the wiki or if you know what object it should be on you can go to the Lua_objects page on the wiki and follow the links (or save a link/bookmark to this post) :)
bblewittAG wrote:FreeER for your tutorial on how to mod could you add a section in at the end for packaging the mod so that it does not mess up the resources need for an item, example lab would need 0.2 of iron plate and 0.0 of copper plate.
I'm not entirely sure what you mean there...nothing in the tutorial should change the lab requirements...if it was from one of the 'completed' downloads then let me know which (if you can) and I'll look/fix it.
edit: done, now I understand what you were saying :) it just didn't register for me at first, but it hit me as I was putting it on the wiki.

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

Just add this to this page on the wiki : https://forums.factorio.com/wiki/inde ... the_mod.3F

Chapter 10 - Packaging the mod.
To stop the item requirements bug when having a folder that is not zipped up in the mods folder then right click on the modname folder and use 7zip or winRAR to make a modname.zip or modname.rar and then move the modname folder out of the mods folder and when you play the game with your mod installed the raw materials needed will be correct and not show odd numbers. (works in 0.10.12 of Factorio)

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

Just testing/playing around with the mod that I made and it has done this when I did the research for getting some stuff?
I have zipped it as I said to fix it?

This is where I have posted the code: https://github.com/bblewittAG/dupeitems

Is there anything you can do FreeER?
Attachments
Capture.PNG
Capture.PNG (209.62 KiB) Viewed 5720 times

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Simple help needed

Post by FreeER »

ah.. probably a 'bug' with trying to display the raw requirements per item by dividing the actual requirements by the result_count, thus there are small numbers (1/51, 1/101) that round to 0. Nothing technically wrong there.

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

Is there anything I can do FreeER to set it right in my code?
With not knowing how much I need per item it is hard to play.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Simple help needed

Post by FreeER »

bblewittAG wrote:Is there anything I can do FreeER to set it right in my code?
With not knowing how much I need per item it is hard to play.
well it's still 1 iron per craft (or whatever was specified in the ingredients), you'll just get 51/101/etc result items per craft. As said, there's nothing wrong there and if you want it 'fixed' in your code you'd need to make sure that the ingredient count/result item count is at least 0.1 (or better, a whole number). If it's just the recipes for testing then you really shouldn't bother since they'll be removed eventually...

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

OK but I meant like is there a way to fix it without changing the recipe needed/result because when I look online there is no tutorials on doing a particular thing but I think I know the problem and it is the crafting tab.
If you would be so kind to check it over and see if there is anything I can do to make it fully work because this problem only occurs when I add something new or new to me and it comes up with it saying well it works but not working lol

edit: It only happens when I do my technology it changes the raw resources needed

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

Now I have played around with the modding side of Factorio I want to start to make a fully working and releasable mod but I am having problems on getting a chest to slowly generate any items.

My plans for the mod is bigger than just that so if anyone can help me, that would be great :)

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: Simple help needed

Post by ludsoe »

What do you mean slowly generate items? Like it just pops new items into existence? Thats pretty easy.

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

So when you place down a chest it will generate 1 item over time till a limit but say 50 items may take 5 mins.

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: Simple help needed

Post by ludsoe »

Theres inventory functions: https://forums.factorio.com/wiki/inde ... /Inventory
You'd just store the chest entities in a table as their placed, loop them every once in a while and spawn items into them if they are below your limit.

Or you can just ask and I can spend 10 minutes throwing together some MoLogicCore functions and give you a working example.

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

ludsoe wrote:Theres inventory functions: https://forums.factorio.com/wiki/inde ... /Inventory
You'd just store the chest entities in a table as their placed, loop them every once in a while and spawn items into them if they are below your limit.

Or you can just ask and I can spend 10 minutes throwing together some MoLogicCore functions and give you a working example.
Ok well I am new to coding so any examples would be great and any people helping me will get credited so I am not steeling code

bblewittAG
Inserter
Inserter
Posts: 29
Joined: Tue Sep 16, 2014 8:27 pm
Contact:

Re: Simple help needed

Post by bblewittAG »

so I am having some problems with disabling ore generation so could anyone give me a clue on how to do that please.
All I know is using data.raw["resource"]["resource_name"].autoplace = nil but with modding where abouts does that go and I also want to know is how do you detect if the same mod is installed to use the disabler?

cartmen180
Filter Inserter
Filter Inserter
Posts: 358
Joined: Fri Jul 25, 2014 2:53 pm
Contact:

Re: Simple help needed

Post by cartmen180 »

put it in a .lua (i call it base-edit.lua) somwhere in the prototypes folder and call it in the data.lua
Check out my mods

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Simple help needed

Post by FreeER »

bblewittAG wrote:I also want to know is how do you detect if the same mod is installed to use the disabler?
yeah, good question there... You can just check if data.raw[type][name] ~= nil (since nil evaluates to false you wouldn't actually need the explicit ~= nil portion) for one of the prototypes that you know the mod adds, if it's there then the mod exists and was loaded before yours (you can force that with dependencies, though I believe it's on the devs feature list to separate mod loading into stages for this reason), if it's not there then it either doesn't exist or was loaded after your mod (in the last case there's not much you can do, except in control.lua use the onchunkgeneratedevent and findentitiesfiltered over it's area to search for the resource and destroy it).

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: Simple help needed

Post by rk84 »

Here is solution for prototypes that are loaded after your mod. I use this with test mode.
postprocessor.lua
Example of setting autoplace nil for resource types.
Adding procedure
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

Post Reply

Return to “Modding help”