Detect a click on inventory screen (before craft)

Place to get help with not working mods / modding interface.
User avatar
SHiRKiT
Filter Inserter
Filter Inserter
Posts: 706
Joined: Mon Jul 14, 2014 11:52 pm
Contact:

Detect a click on inventory screen (before craft)

Post by SHiRKiT »

Hey,

I'd like to listen for click events on the player inventory GUI screen, but I have no idea how to do it. Doing: script.on_event(defines.events.on_gui_opened, FUNCTION_HERE) does not get called on any clicks.

My goal is to do this
  1. Open up the inventory (pressing E)
  2. (ctrl+shift) click on a recipe
  3. Do some logic + prevent crafting
Is it possible to achieve this?

Thanks
asdff45
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Sun Aug 07, 2016 1:23 pm
Contact:

Re: Detect a click on inventory screen (before craft)

Post by asdff45 »

I'm not sure, but the event `on_gui_click` could help.

But when you only want to disable handcrafting, you can type `/permissions` in the chat, to open the permissions tab and there you can remove the checkbox on "Craft" to disable Handcrafting.
User avatar
SHiRKiT
Filter Inserter
Filter Inserter
Posts: 706
Joined: Mon Jul 14, 2014 11:52 pm
Contact:

Re: Detect a click on inventory screen (before craft)

Post by SHiRKiT »

asdff45 wrote: Thu Jan 30, 2020 1:16 pm I'm not sure, but the event `on_gui_click` could help.

But when you only want to disable handcrafting, you can type `/permissions` in the chat, to open the permissions tab and there you can remove the checkbox on "Craft" to disable Handcrafting.
I can't get on_gui_click to fire on any clicks, do you know how to use it?

I do not want to disable handcrafting, I just want to do some logic on step 3 instead of crafting an item.
Klonan wrote: Thu Jan 30, 2020 1:26 pm We have this:

https://lua-api.factorio.com/latest/eve ... afted_item
That does not get called when the player doesn't have the materials. I wanted to hook when an recipe button on the inventory screen gets clicked.
billbo99 wrote:From: https://mods.factorio.com/mod/additiona ... 000d6a8bc4

One of the guys in our discord forum had this idea and I thought it might be something you could add to this mod.

Open up your inventory
(ctrl+shift) click on a recipe
The mod then adds the ingredients to the players logistics request
each additional click would increment the ingredients in the logistics request
That's my final goal, I tried on_gui_click but I can't get it to work.
Honktown
Smart Inserter
Smart Inserter
Posts: 1044
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Detect a click on inventory screen (before craft)

Post by Honktown »

SHiRKiT wrote: Fri Jan 31, 2020 2:37 pm ...
Sorry I can't help you, but I wanted to say I had the same issue. I think it's because the gui's aren't owned by your mod, and/or base gui events don't get fired, other than entity open and entity closed (which aren't really gui events, so to speak). I tried:

Code: Select all

script.on_event(defines.events.on_gui_click, gui_click)
script.on_event(defines.events.on_gui_elem_changed, gui_click)
script.on_event(defines.events.on_gui_selection_state_changed, gui_click)
script.on_event(defines.events.on_gui_confirmed, gui_click)
And none of those fire. I was making a mod where something happened while someone was clicking in a requester chest, and... I couldn't detect anything. Another modder even had the same issue: they did their thing on entity close, like I had to.
I have mods! I guess!
Link
User avatar
SHiRKiT
Filter Inserter
Filter Inserter
Posts: 706
Joined: Mon Jul 14, 2014 11:52 pm
Contact:

Re: Detect a click on inventory screen (before craft)

Post by SHiRKiT »

Honktown wrote: Fri Jan 31, 2020 3:05 pm
SHiRKiT wrote: Fri Jan 31, 2020 2:37 pm ...
Sorry I can't help you, but I wanted to say I had the same issue. I think it's because the gui's aren't owned by your mod, and/or base gui events don't get fired, other than entity open and entity closed (which aren't really gui events, so to speak). I tried:

Code: Select all

script.on_event(defines.events.on_gui_click, gui_click)
script.on_event(defines.events.on_gui_elem_changed, gui_click)
script.on_event(defines.events.on_gui_selection_state_changed, gui_click)
script.on_event(defines.events.on_gui_confirmed, gui_click)
And none of those fire. I was making a mod where something happened while someone was clicking in a requester chest, and... I couldn't detect anything. Another modder even had the same issue: they did their thing on entity close, like I had to.
Sadness...
Honktown
Smart Inserter
Smart Inserter
Posts: 1044
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Detect a click on inventory screen (before craft)

Post by Honktown »

Hmm, you haven't stated your goal here. There could be another way to achieve it.
I have mods! I guess!
Link
User avatar
SHiRKiT
Filter Inserter
Filter Inserter
Posts: 706
Joined: Mon Jul 14, 2014 11:52 pm
Contact:

Re: Detect a click on inventory screen (before craft)

Post by SHiRKiT »

Honktown wrote: Sat Feb 01, 2020 1:30 pm Hmm, you haven't stated your goal here. There could be another way to achieve it.
Example usage:
  1. Open up your inventory
  2. (ctrl+shift) click on a recipe
  3. The mod then adds the ingredients to the players logistics request
    • each additional click would increment the ingredients in the logistics request (just as my mod does for chests)
https://mods.factorio.com/mod/additional-paste-settings
Honktown
Smart Inserter
Smart Inserter
Posts: 1044
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Detect a click on inventory screen (before craft)

Post by Honktown »

SHiRKiT wrote: Sat Feb 01, 2020 2:15 pm
Honktown wrote: Sat Feb 01, 2020 1:30 pm Hmm, you haven't stated your goal here. There could be another way to achieve it.
Example usage:
  1. Open up your inventory
  2. (ctrl+shift) click on a recipe
  3. The mod then adds the ingredients to the players logistics request
    • each additional click would increment the ingredients in the logistics request (just as my mod does for chests)
https://mods.factorio.com/mod/additional-paste-settings
I see. That would be difficult. A really messy way of doing it, that's so bad I'm putting it in spoiler:
Duplicate all recipes in the data-final-fixes stage to your own group. Change the cost to nothing, and result(s) to none. When the player holds the alternate key, disable_recipe_group for all existing recipe groups, and enable yours. Player crafts one of your infinite recipes. Remove from pre-player-hand-crafted if possible, and add ingredients for normal recipe into logistic requests. No idea how to remove ingredients if ingredient request is satisfied. Maybe decrement the request count when the player hand-crafts one of the requested recipes, if amount requested is greater than or equal to recipe cost? (doing the if would prevent going negative if the player cancelled the request themself) A table could be used to store per-player recipe requests, so when the player hand-crafts, it reduces the count in the table by 1, and subtracts from the requests. That's if you even care to have an "automatic" satisfaction that un-queues requests.

Don't know if there's a way to detect when the player releases an alternate key, but it could be a toggle instead: a "request ingredients" mode.
I have mods! I guess!
Link
User avatar
SHiRKiT
Filter Inserter
Filter Inserter
Posts: 706
Joined: Mon Jul 14, 2014 11:52 pm
Contact:

Re: Detect a click on inventory screen (before craft)

Post by SHiRKiT »

Honktown wrote: Sat Feb 01, 2020 3:41 pm
SHiRKiT wrote: Sat Feb 01, 2020 2:15 pm
Honktown wrote: Sat Feb 01, 2020 1:30 pm Hmm, you haven't stated your goal here. There could be another way to achieve it.
Example usage:
  1. Open up your inventory
  2. (ctrl+shift) click on a recipe
  3. The mod then adds the ingredients to the players logistics request
    • each additional click would increment the ingredients in the logistics request (just as my mod does for chests)
https://mods.factorio.com/mod/additional-paste-settings
I see. That would be difficult. A really messy way of doing it, that's so bad I'm putting it in spoiler:
That's extra an bad extra messy way of doing it :D Def not gonna go that route, but thanks for suggesting
User avatar
SHiRKiT
Filter Inserter
Filter Inserter
Posts: 706
Joined: Mon Jul 14, 2014 11:52 pm
Contact:

Re: Detect a click on inventory screen (before craft)

Post by SHiRKiT »

Maybe an alternative is to replace the Player Inventory GUI? Although I didn't find a way to re-instantiate it so I have control over it, so I could hook on on_gui_click for it's buttons.
Post Reply

Return to “Modding help”