A few questions

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Xecutor
Filter Inserter
Filter Inserter
Posts: 260
Joined: Mon Jun 23, 2014 10:15 am
Contact:

A few questions

Post by Xecutor »

Hello there.
Here they are:
1) How can I make my custom container with request interface like requester chest, but not part of logistics network?
2) If I make custom container with type='smart-container' will I be able to hook smart inserter to it?
3) If I want to store some value I need to store it in the glob table?
4) How can I find (in a mod) mining hardness of a resource?
5) Is it possible to traverse receipts? Is it possible to get crafting time from receipt?

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

Re: A few questions

Post by FreeER »

1) not that I am aware of
2) yes
3) yes
4) .. depends. While Factorio is loading (and assuming your mod is loaded after the resource was added to Factorio using the info.json dependencies) you can read that information from data.raw and have full access to the prototype. In game you have limited access to prototypes through game.itemprototypes, game.entityprototypes, game.forces.player.technologies, and game.forces.player.recipes, all of which are tables indexed by the name of the prototype, and you can see what you have access to by using game.player.print(prototype_table[prototype_name].help()) where prototype_table is one of the four mentioned table and prototype_name is the index to look up.

For example, with game.player.print(game.entityprototypes["iron-ore"].help()) you'll see that you have access to the hasflag method, and the following readonly (R) properties maxhealth, minimumresourceamount, name, resourcecategory, type, and valid. game.player.print(game.itemprototypes["iron-ore"].help()) reveals access to the hasflag method, and the readonly properties fuelvalue, group, name, placeresult, stacksize, type, and valid. So it would appear that during runtime you would not be able to easily find the mining hardness of a resource (you could hard code it however, or since Factorio doesn't have a nice way to store 'dynamic'/'unknowable' data for runtime use likely because a method of doing so that doesn't break determinism would be somewhat difficult, you use some string manipulations and the creation of 'fake' recipes created during loading to store that value in the fake recipe's name and parse that name during runtime. since the recipe will never be unlocked it doesn't matter what the ingredients and results are as long as Factorio will accept it as a 'valid' recipe :) note, you can't have '.'s in names, easy enough to multiply by an arbitrary magic value like 10000 though)

5) see 4, but game.player.print(game.forces.player.recipes["wooden-chest"].help()) reveals only category, enabled (read write), name, and valid are available (along with the reload function).

n9103
Smart Inserter
Smart Inserter
Posts: 1067
Joined: Wed Feb 20, 2013 12:09 am
Contact:

Re: A few questions

Post by n9103 »

RE #4:
Get Notepad++ (if you're writing mods, I only have to ask why you don't already use it? :P)
Use the Find in Files command (Ctrl+Shift+F).
Type the text you want to find, leave replace blank, select the mod's directory (or the entire mod directory if you don't have a specific target mod).
Make sure sub directories is selected, and search mode is Normal. You'll probably want the whole word only selected as well.
Most of these should be the defaults in anycase.

Here's the results of a search on my mods directory:
Image
Colonel Failure wrote:You can lose your Ecologist Badge quite quickly once you get to the point of just being able to murder them willy-nilly without a second care in the world.

User avatar
Xecutor
Filter Inserter
Filter Inserter
Posts: 260
Joined: Mon Jun 23, 2014 10:15 am
Contact:

Re: A few questions

Post by Xecutor »

FreeER wrote:1) not that I am aware of
That's most unfortunate.
Hm. In order to somehow emulate that I need some custom GUI like in TestMode...
Can I make custom container with custom gui?

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

Re: A few questions

Post by FreeER »

Xecutor wrote:Can I make custom container with custom gui?
Not like there are for the regular entities, the best you can do from a mod are the guis like those in TestMode. Of course you control when they open so you can have the player attempt to open the container with an item and use the onputitem event to open the gui, or anything else you can think of.
The wiki page for Lua/GuiElements is here by the way.

User avatar
Xecutor
Filter Inserter
Filter Inserter
Posts: 260
Joined: Mon Jun 23, 2014 10:15 am
Contact:

Re: A few questions

Post by Xecutor »

Hm. What I was hoping to do is to make kind of 'interstallar trading' mod.
With 'import chest' and 'export chest'.
Import chest is like requester chest, but requests items from the orbit/space (as long as you have enough money), and items from export chest are taken away (and paid for).
All this happens periodically, like 4 times a day, for example.
I hoped to calculate prices for resources based on mining hardness and prices for other items based on cost of basic resources multiplied by production time and may be some constant.

Any ideas how I can make this with current mod api?

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

Re: A few questions

Post by FreeER »

Well, you'd need a way for the player to tell you want they want to 'buy' (the selling part could be as easy as whatever is placed in an "exports" chest, or as 'complicated' as the buying). There are a couple ways that I can think of off the top of my head.
  1. Remote interfaces (annoying to use)
  2. GUI with textfield and/or buttons (see TestMode)
  3. An entity with filters (or circuit conditions) and getfilter/setfilter, getrequestslot/setrequestslot, and/or getcircuitcondition/setcircuitcondition (depending on entity/filter type).
    Obviously choosing the entity type that you use matters, a requester chest could interfere with the player's network, whereas a new 'smart' inserter probably wouldn't and would allow using both the pickup filter and the circuit conditions as an interface for the player.
I'd probably use the GUIs myself for a couple reasons. Doing so lets you stay consistent with other features that you might want to implement later (instead of using various different hacks that could confuse the player when they try to interact with them), they're more flexible since you write the code that interprets the data (precise values for how many items for example), and they are likely to be improved eventually anyways.
Xecutor wrote:All this happens periodically, like 4 times a day, for example.
a simple "if event.tick % some_constant == a_valid_result then runImportExports() end", within ontick allows that. some_constant would be the number of ticks in a day (I... don't actually know that, it'd be the number of seconds * 60 though) divided by the number of times in a day you wanted it to happen (and a_valid_result would be in the range (0, some_constant-1) since some_constant % some_constant is 0). and runImportExports would of course be a function that checks "import" and "export" chests (found and stored in the glob table via onbuiltentity) against the import/export data (also stored in the glob, but from the GUI) and inserts/removes as necessary.
Xecutor wrote:I hoped to calculate prices for resources based on mining hardness and prices for other items based on cost of basic resources multiplied by production time and may be some constant.
if you are implementing only a small number of trade items then you can do that with hard coding, but if you really want it to work then you'd need a way to get those values during runtime. The only way that I currently know is the hack I described earlier and used when creating the framework for DyTech's modular tools, and in this code I wrote for a never released belt replacer mod (the other side of that code, to read the recipes, is in the control.lua). I did implement it slightly differently in each (DyTech only looks at valid recipes since it expects mods to make their parts modular (by creating a valid recipe), belt replacer looks at all entities of type "transport-belt" and uses a default value if it doesn't find a recipe) but it's the same technique.

Post Reply

Return to “Modding help”