- rightclickNode
- pickupItem
triggers needed
- theFox
- Member
- Posts: 192
- Joined: Sun Feb 12, 2017 14:08
- GitHub: theFox6
- In-game: theFox
- Location: Germany
triggers needed
I would like to have some global triggers:
Last edited by theFox on Fri Feb 23, 2018 10:34, edited 1 time in total.
my mods and subgames (ง'̀-'́)ง
- Linuxdirk
- Member
- Posts: 3219
- Joined: Wed Sep 17, 2014 11:21
- In-game: Linuxdirk
- Location: Germany
- Contact:
Re: triggers needed
This can be done by adding an on_rightclick function to the node in question.theFox wrote:rightclickNode
http://dev.minetest.net/minetest.regist ... rightclick
- theFox
- Member
- Posts: 192
- Joined: Sun Feb 12, 2017 14:08
- GitHub: theFox6
- In-game: theFox
- Location: Germany
Re: triggers needed
I meant global triggers (like register minetest.register_on_punchnode)Linuxdirk wrote:to the node in question
my mods and subgames (ง'̀-'́)ง
- Linuxdirk
- Member
- Posts: 3219
- Joined: Wed Sep 17, 2014 11:21
- In-game: Linuxdirk
- Location: Germany
- Contact:
Re: triggers needed
When you use a tool for that action you can register it with an on_use function where you can do whatever you want. By just quick skipping to the API documentation I can't find such a register.theFox wrote:I meant global triggers (like register minetest.register_on_punchnode)Linuxdirk wrote:to the node in question
What is your use case? Maybe there is a workaround or other/better/different solution.
- TechNolaByte
- Member
- Posts: 465
- Joined: Wed May 10, 2017 21:00
- GitHub: TechNolaByte
Re: triggers needed
If these features would be implemented it would greatly improve the quest line for my soon to be released skyfactory subgame
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.
- theFox
- Member
- Posts: 192
- Joined: Sun Feb 12, 2017 14:08
- GitHub: theFox6
- In-game: theFox
- Location: Germany
Re: triggers needed
I am only building a trigger api...Linuxdirk wrote:What is your use case? Maybe there is a workaround or other/better/different solution.
RSLRedstonier is requesting it from my mod, so he's the boss here.
my mods and subgames (ง'̀-'́)ง
- Linuxdirk
- Member
- Posts: 3219
- Joined: Wed Sep 17, 2014 11:21
- In-game: Linuxdirk
- Location: Germany
- Contact:
Re: triggers needed
You could register a tool that looks like and acts like the hand but with changes to the on_use function.
https://github.com/minetest/minetest/bl ... .txt#L2210
https://github.com/minetest/minetest/bl ... .txt#L2210
- theFox
- Member
- Posts: 192
- Joined: Sun Feb 12, 2017 14:08
- GitHub: theFox6
- In-game: theFox
- Location: Germany
Re: triggers needed
Naw, that won't be useful...Linuxdirk wrote:You could register a tool that looks like and acts like the hand but with changes to the on_use function.
https://github.com/minetest/minetest/bl ... .txt#L2210
I guess that leaves only the on_pickup problem.Lejo wrote:Have a look at this mod:https://github.com/Arcelmi/minetest-controls
It's for my journal mod btw.
my mods and subgames (ง'̀-'́)ง
Re: triggers needed
Why not use on_drop and minetest.handle_node_drops?theFox wrote: I guess that leaves only the on_pickup problem.
You could override all items with a trigger on drop.
- TechNolaByte
- Member
- Posts: 465
- Joined: Wed May 10, 2017 21:00
- GitHub: TechNolaByte
Re: triggers needed
hmm i know that mineclone 2 uses a custome item drop mod which does have an on_pickup functiontheFox wrote: I guess that leaves only the on_pickup problem.
perhaps other item drop mods would have likewise?
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.
- theFox
- Member
- Posts: 192
- Joined: Sun Feb 12, 2017 14:08
- GitHub: theFox6
- In-game: theFox
- Location: Germany
Re: triggers needed
Like this I can't get the target of the player's right click.theFox wrote:I guess that leaves only the on_pickup problem.Lejo wrote:Have a look at this mod:https://github.com/Arcelmi/minetest-controls
The ones I use don't...RSLRedstonier wrote:hmm i know that mineclone 2 uses a custome item drop mod which does have an on_pickup function
perhaps other item drop mods would have likewise?
If you used your own version in your subgame, you can register a trigger there.
my mods and subgames (ง'̀-'́)ง
Re: triggers needed
Then just override all nodes with a trigger on_rightclick = func(pos, node, clicker, itemstack, pointed_thing).theFox wrote: Like this I can't get the target of the player's right click.
- TechNolaByte
- Member
- Posts: 465
- Joined: Wed May 10, 2017 21:00
- GitHub: TechNolaByte
Re: triggers needed
but what if they already have their own on_rightclick function?Lejo wrote:Then just override all nodes with a trigger on_rightclick = func(pos, node, clicker, itemstack, pointed_thing).theFox wrote: Like this I can't get the target of the player's right click.
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.
Re: triggers needed
I have done the same with on_drop it works with a trick.RSLRedstonier wrote:but what if they already have their own on_rightclick function?Lejo wrote:Then just override all nodes with a trigger on_rightclick = func(pos, node, clicker, itemstack, pointed_thing).theFox wrote: Like this I can't get the target of the player's right click.
You have to store their own on_rightclick in a extra value.
Re: triggers needed
Here is the register code for it, just put it to your code.
It should work with
minetest.register_on_rightclick(function(pos, node, clicker, itemstack, pointed_thing)
-- Your Code
end)
Code: Select all
minetest.registered_on_rightclick = {}
function minetest.register_on_rightclick(func)
table.insert(minetest.registered_on_rightclick, func)
end
local rightclickfuncs = {}
function minetest.handle_rightclick(pos, node, clicker, itemstack, pointed_thing)
if clicker and clicker:is_player() then
local name = clicker:get_player_name()
if rightclickfuncs[node.name] then
return rightclickfuncs[node.name](pos, node, clicker, itemstack, pointed_thing)
end
local todo
for _,value in pairs(minetest.registered_on_rightclick) do
local result = value(pos, node, clicker, itemstack, pointed_thing)
if result then
todo = result
end
end
return todo
end
end
minetest.after(3, function()
for name, def in pairs(minetest.registered_items) do
if def.on_rightclick then
rightclickfuncs[name] = def.on_rightclick
end
minetest.override_item(name, {on_rightclick=minetest.handle_rightclick})
end
end)
minetest.register_on_rightclick(function(pos, node, clicker, itemstack, pointed_thing)
-- Your Code
end)
- theFox
- Member
- Posts: 192
- Joined: Sun Feb 12, 2017 14:08
- GitHub: theFox6
- In-game: theFox
- Location: Germany
Re: triggers needed
And if you want to use it together with my journal...
Look into the api.md and lower part of triggers.lua there you can learn how to register new triggers for the journal mod.
Look into the api.md and lower part of triggers.lua there you can learn how to register new triggers for the journal mod.
my mods and subgames (ง'̀-'́)ง
Re: triggers needed
Do it like so:theFox wrote:And if you want to use it together with my journal...
Look into the api.md and lower part of triggers.lua there you can learn how to register new triggers for the journal mod.
Code: Select all
triggers.register_trigger("rightclick")
local rightclickfuncs = {}
function triggers.handle_rightclick(pos, node, clicker, itemstack, pointed_thing)
if clicker and clicker:is_player() then
local name = clicker:get_player_name()
if rightclickfuncs[node.name] then
rightclickfuncs[node.name](pos, node, clicker, itemstack, pointed_thing)
end
local data ={
target = node.name,
playerName = name,
tool = clicker:get_wielded_item():get_name(),
}
triggers.run_callbacks("rightclick", data)
end
end
minetest.after(3, function()
for name, def in pairs(minetest.registered_items) do
if def.on_rightclick then
rightclickfuncs[name] = def.on_rightclick
end
minetest.override_item(name, {on_rightclick=triggers.handle_rightclick})
end
end)
But not tested.
- TechNolaByte
- Member
- Posts: 465
- Joined: Wed May 10, 2017 21:00
- GitHub: TechNolaByte
Re: triggers needed
ty!
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.
- theFox
- Member
- Posts: 192
- Joined: Sun Feb 12, 2017 14:08
- GitHub: theFox6
- In-game: theFox
- Location: Germany
Re: triggers needed
Edit: never mind, didn't read the code quite right.
Last edited by theFox on Sun Feb 25, 2018 20:05, edited 1 time in total.
my mods and subgames (ง'̀-'́)ง
Re: triggers needed
The rightclickfuncs is important it does that, if a block has a function on_rightclick that this function is not ignored.theFox wrote:You can cut out the rightclickfuncs stuff, it's not needed here...
- theFox
- Member
- Posts: 192
- Joined: Sun Feb 12, 2017 14:08
- GitHub: theFox6
- In-game: theFox
- Location: Germany
Re: triggers needed
The triggers are now avalible in the extra_triggers mod inside the journal modpack!
my mods and subgames (ง'̀-'́)ง
Who is online
Users browsing this forum: Ahrefs [Bot] and 7 guests