Determine if my entity has been clicked?

Place to get help with not working mods / modding interface.
coreyog
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Apr 09, 2015 7:11 am
Contact:

Determine if my entity has been clicked?

Post by coreyog »

I'm hoping to create a new kind of Assembling Machine. In order to do so, i need a way to open my own GUI when the building has been clicked on. I found a post back in 2013 asking if it was possible and they were told it wasn't. Somewhere I believe the wiki said the same thing. I'm hoping that both of these are out of date.

I've looked for work arounds but because I'm working on an assembling machine, I can't even use the onplayerrotatedentity event to see if the user has interacted with my assembling machine.

Is there any way to do this? If not, are there any work arounds?
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Determine if my entity has been clicked?

Post by Choumiko »

You still can't replace the vanilla gui with your own.
Here's a work around i'm using: (put it in control.lua)

Code: Select all

function ontick(event)
  if event.tick%10==0  then
    for pi, player in ipairs(game.players) do
      if player.opened ~= nil and player.opened.valid then
        if player.opened.name == "your-assembler-name" then
          if player.gui.left.your_custom_gui == nil then
          --create your gui
          end
        end
      elseif player.opened == nil then
        local gui=player.gui.left.your_custom_gui
        if gui then
        --one of your assemblers was open and has been closed
        --read the gui's textfields, checkboxe etc, do some stuff
        --destroy your gui
        end
      end
    end
  end
end
game.onevent(defines.events.ontick, ontick)
Post Reply

Return to “Modding help”