Adding a clickable entity
Adding a clickable entity
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.
Re: Adding a clickable entity
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.
Only problem is that UI will not replace the existing entity UI and that UI will show on top as well.
Re: Adding a clickable entity
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)
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)
Re: Adding a clickable entity
I think you can just omit the power source from the entity definition in data.lua files.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)
Re: Adding a clickable entity
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?
Re: Adding a clickable entity
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.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?
If you want to get ahold of me I'm almost always on Discord.
Re: Adding a clickable entity
Well you should add that (jk, it probably isn't something that's requested enough to bother with)Rseding91 wrote: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.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?
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.
Re: Adding a clickable entity
Constant combinator is one.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.