Adding a clickable entity

Place to get help with not working mods / modding interface.
Post Reply
ATMunn
Inserter
Inserter
Posts: 37
Joined: Thu Jan 12, 2017 2:22 am
Contact:

Adding a clickable entity

Post by ATMunn »

So I had an idea for a mod. Basically, the mod wouldn't be meant to be played in any map, (I may make it so it won't even do anything if you load it in freeplay) but when played in a certain scenario, it would help enhance that scenario by adding specific things to the game that I wouldn't be able to do with just a normal scenario. One of the things I wanted to have was a new entity, that when clicked, would either display a message in chat or pop up a message dialogue. Preferably, the entity would have the text of the message stored with the entity, however if I can't do that I can figure out a way to still make it work in the control.lua. The only problem with it is, I don't know of a way to make an entity that when clicked can fire a specific event in a control.lua. There's no "on_player_clicked_entity" in the API. So, how would I make such an entity? There's nothing in the base game (that I can think of) that does this, so there's nothing I can copy and edit.

Yoyobuae
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Nov 04, 2016 11:04 pm
Contact:

Re: Adding a clickable entity

Post by Yoyobuae »

I checked the code on Creative Mode, does it by keeping track of which entity each player has opened by using the on_tick event. So when player opens your entity the control.lua can detect it and show some UI.

Only problem is that UI will not replace the existing entity UI and that UI will show on top as well.

ATMunn
Inserter
Inserter
Posts: 37
Joined: Thu Jan 12, 2017 2:22 am
Contact:

Re: Adding a clickable entity

Post by ATMunn »

That should work. If I delete the entity and then place it back, it should close the gui, right?
EDIT: What type of entity should I use? I need something that can be clicked on, however I also don't want it to use power. (I don't want the little flashy icon over it)

Yoyobuae
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Nov 04, 2016 11:04 pm
Contact:

Re: Adding a clickable entity

Post by Yoyobuae »

ATMunn wrote:That should work. If I delete the entity and then place it back, it should close the gui, right?
EDIT: What type of entity should I use? I need something that can be clicked on, however I also don't want it to use power. (I don't want the little flashy icon over it)
I think you can just omit the power source from the entity definition in data.lua files.

ATMunn
Inserter
Inserter
Posts: 37
Joined: Thu Jan 12, 2017 2:22 am
Contact:

Re: Adding a clickable entity

Post by ATMunn »

I think I tried that, and it gave me an error. I think a chest entity should work, since the player won't be able to access its actual gui, and I can probably set its storage slots to 0 anyways. The only other question I would have is: Is there a way to store a custom variable with an entity, and if so, is there any way I can make it accessible from the map editor?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Adding a clickable entity

Post by Rseding91 »

ATMunn wrote:I think I tried that, and it gave me an error. I think a chest entity should work, since the player won't be able to access its actual gui, and I can probably set its storage slots to 0 anyways. The only other question I would have is: Is there a way to store a custom variable with an entity, and if so, is there any way I can make it accessible from the map editor?
No and no. Also setting the container to have a slot count of 0 means it has no GUI and won't allow the player to open it and won't fire any events when clicked.
If you want to get ahold of me I'm almost always on Discord.

ATMunn
Inserter
Inserter
Posts: 37
Joined: Thu Jan 12, 2017 2:22 am
Contact:

Re: Adding a clickable entity

Post by ATMunn »

Rseding91 wrote:
ATMunn wrote:I think I tried that, and it gave me an error. I think a chest entity should work, since the player won't be able to access its actual gui, and I can probably set its storage slots to 0 anyways. The only other question I would have is: Is there a way to store a custom variable with an entity, and if so, is there any way I can make it accessible from the map editor?
No and no. Also setting the container to have a slot count of 0 means it has no GUI and won't allow the player to open it and won't fire any events when clicked.
Well you should add that :P (jk, it probably isn't something that's requested enough to bother with)

Hm. I just don't want the player to be able to ctrl click stuff in and/or out. I guess I could put a custom item in there with a stack size of 1 so the player can't ctrl click stuff in, and if they ctrl click it into their inventory, it gets removed and put back in the entity. Unless there's a type that I'm not thinking of that has no inventory, doesn't connect to power, and still has a gui. Seems unlikely though.

Yoyobuae
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Nov 04, 2016 11:04 pm
Contact:

Re: Adding a clickable entity

Post by Yoyobuae »

ATMunn wrote:Unless there's a type that I'm not thinking of that has no inventory, doesn't connect to power, and still has a gui. Seems unlikely though.
Constant combinator is one.

Post Reply

Return to “Modding help”