Page 1 of 1

[Solved]LuaGuiElement question

Posted: Sun Feb 16, 2020 9:06 pm
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)

Re: LuaGuiElement question

Posted: Tue Feb 18, 2020 9:48 am
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

Re: LuaGuiElement question

Posted: Tue Feb 18, 2020 12:50 pm
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

Re: LuaGuiElement question

Posted: Tue Feb 18, 2020 1:33 pm
by CruWiT
@Deadlock989 @Bilka
I solve problem and now my script works thanks.