Implementing Player Restrictions

Place to get help with not working mods / modding interface.
camelCase
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sun Jun 28, 2015 9:28 am
Contact:

Implementing Player Restrictions

Post by camelCase »

I had an Idea for a mod, so I thought I would give it a try.

The Basis of the mod is basicly to implement rules similar to FishSandwich's Split dependencies video series.

I've been reading the modding information on the wiki, and I believe I had read most of the information there.

I havn't put fingers to keyboard yet in order to attempt investigating what is possible yet, but the summary of the api requirements I need are as follows:
  • Prevent where a player can build
  • Prevent what a player can select in Assembly Machines and Chemical factories etc..
If anyone more experienced with the game can help direct me to how the above two items could be implemented, I would be very grateful.

I am a professional software developer, however I don't know LUA, I have used it in a limited fashion some years ago.
kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Contact:

Re: Implementing Player Restrictions

Post by kds71 »

1. Prevent what a player can select in Assembly Machines and Chemical factories etc..

This is rather simple - each assembling machine has a list of recipe categories that it can craft. By altering this list or moving a recipe to a different category, you can change recipes that are available in a given assembling machine. There is only one problem - player can craft only these recipes that are in "crafting" category, so if you move a recipe from this category to another, player will not be able to craft it anymore.

Take a look at this example - it adds a custom recipe category and moves the recipe for plastic bars into it, so plastic bars can't be crafted in chemical plants anymore:

Code: Select all

data:extend({
    {
        type = "recipe-category",
        name = "custom-category"
    }
})

data:raw["recipe"]["plastic-bar"].category = "custom-category"
Of course, you should provide some other means for a player to obtain plastic bars after doing it.

2. Prevent where a player can build

This one is a little bit more complicated and I'm not entirely sure what are you trying to achieve. However, you should look into onbuiltentity event.
Here is an example:

Code: Select all

require "defines"

game.onevent(defines.events.onbuiltentity, function(event) 

    local entity = event.create_entity

    if CONDITION then
        event.player.insert{ name = entity.name, count = 1 } -- return the item to the player inventory
        entity.destroy() -- remove the entity from the map
    end

end)
If CONDITION (make it whatever you want to be, for example check if position of placed entity is outside the area that player can build in) is fullfilled, the item used to build this entity will be returned to the inventory and entity will be removed from the map. Note that it works only if name of the entity is exactly same as name of the item used to build it (which is for all entities and items in vanilla Factorio and for the vast majority of the mods).
Last edited by kds71 on Sun Jun 28, 2015 12:03 pm, edited 1 time in total.
camelCase
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sun Jun 28, 2015 9:28 am
Contact:

Re: Implementing Player Restrictions

Post by camelCase »

Thanks kds71,

I'll start experimenting with your suggestions now.
kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Contact:

Re: Implementing Player Restrictions

Post by kds71 »

I forgot to mention that code from the first example should go into data.lua file, and code from the second example into control.lua file.

I also made a small mistake in the second example - it should be "event.player.insert", not "player.insert".
Post Reply

Return to “Modding help”