[Solved]LuaGuiElement question

Place to get help with not working mods / modding interface.
CruWiT
Inserter
Inserter
Posts: 23
Joined: Wed Apr 17, 2019 6:22 pm
Contact:

[Solved]LuaGuiElement question

Post by CruWiT »

I want create right click event and 40 damage my character but I try "shift+right click" in game and notting happened. I look here https://lua-api.factorio.com/latest/LuaGuiElement.html but I don't understand I am new on modding. here is my control.lua ;

Code: Select all

local function right_mouse_click(event)
	local element = event.element --LuaGuiElement
	local player_index = event.player_index --uint
	local player =  game.get_player(event.player_index)
	local button = event.button --defines.mouse_button_type
	local alt = event.alt --boolean
	local control = event.control --boolean
    local shift = event.shift --boolean
	
	if element == {"button"} and player_index == player and button == defines.mouse_button_type.right and alt == false and control == false and shift == true then
	player.character.damage(40, "player")
	end
	
end


script.on_event(defines.events.on_gui_click, right_mouse_click)
Last edited by CruWiT on Tue Feb 18, 2020 1:33 pm, edited 1 time in total.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: LuaGuiElement question

Post by Deadlock989 »

You're confusing player input with GUIs. A GUI is a window like the inventory tab, and GUI elements are the buttons and slots etc. on those windows.

You just want to catch a player input instead: viewtopic.php?t=30644
Bilka
Factorio Staff
Factorio Staff
Posts: 3310
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: LuaGuiElement question

Post by Bilka »

Deadlock989 wrote: Tue Feb 18, 2020 9:48 am You just want to catch a player input instead: viewtopic.php?t=30644
A more up to date version of that thread on custom input/keybindings can be found on the wiki: https://wiki.factorio.com/Tutorial:Scri ... stom_input & https://wiki.factorio.com/Prototype/CustomInput
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
CruWiT
Inserter
Inserter
Posts: 23
Joined: Wed Apr 17, 2019 6:22 pm
Contact:

Re: LuaGuiElement question

Post by CruWiT »

@Deadlock989 @Bilka
I solve problem and now my script works thanks.
Post Reply

Return to “Modding help”