pithy wrote:azekill_DIABLO wrote:when it falls, it's an entity. you should override it. check builtin dir.
Um, how do I override an entity?
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)Icalasari wrote:Is there a good guide to metadata anywhere?
pithy wrote:Um, how do I override an entity?
local my_entity_def = minetest.registered_entities["__builtin:<somewhat>"]
my_entity_def.on_step = function(arg1, arg2, foobar)
-- Things here
end
-- This step is USELESS, 'my_entity_def' is a direct reference to the entity table.
-- These tables are ALWAYS equal, until you call a copy function like 'local foobar = table.copy(blarg)'
minetest.registered_entities["__builtin:<somewhat>"] = my_entity_def
pithy wrote:Is there a way to make a node kill you when it falls on your head?
PlanetKiller wrote:1. check a specific pixel on the player texture to determine character type (using alpha channel)
2. give character multi-jumps and low grav based upon type
3. swap player model when jumping, or based upon gender
4. modify/view player hitbox
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
local node = minetest.get_node_or_nil(pointed_thing.under)
local tile = node.textures
--...code...
end)Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)local tiles = minetest.registered_nodes[node.name].tiles
print(tiles[1])
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)Krock wrote:Icalasari wrote:Is there a good guide to metadata anywhere?
Item Metadata: https://github.com/minetest/minetest/bl ... .txt#L2968
Use minetest.serialize to convert a table into a string, minetest.deserialize for the reverse.
Node Metadata: lua_api.txt#L2683 and lua_api.txt#L1405
AFAIK, there's no other guide than rubenwardy's and the lua_api.txt file itself. Please specify which metadata type you meant.
Icalasari wrote:Thanks. And yeah it was node metadata - It slipped my mind at the time that item metadata was also a thing
[colorize:<color>:<ratio>Krock wrote:There's a good example in the Lua API file, it shows how to set (and save) strings and how to create an inventory: https://github.com/minetest/minetest/bl ... .txt#L1405
You can use these functions basically everywhere but only callback functions like on_place really make sense, because it's when a change happens.
I always recommend to look at the source code of other mods when you're not sure how it works ;)
Icalasari wrote:If one wanted to make ambient mobs that at most disappeared and put an item or two in the inventory when a specific tool was used on it, would that be something to code from scratch, or use one of the existing mob APIs for?
Icalasari wrote:I'm doing a "bug collecting" mod for my first mod, but other than the tarantula, the others wouldn't need anything complex behaviour wise outside of flight nor a health system, but at the same time I'm not even sure where to begin with making custom AI, and I'm not even sure if Minetest has AI in it as a default
Icalasari wrote:If the most complex behaviour a mob may show is flight with a preference of seeking either dark or light along with sky,
kaeza wrote:I'm saying that in your snippet, you use the `fr1` variable before it gets a value (in the `if` block), thus its value may be nil. More context is needed.
kaeza wrote:PlanetKiller wrote:1. check a specific pixel on the player texture to determine character type (using alpha channel)
There's no way to read image data in the engine. An alternative is to associate data with each texture (I won't go over how to load and/or define that data) separately of the texture file itself. Except on very rare occasions when you really have no other way, you should not store data in the textures.
taikedz wrote:Will it drop as "fried bug" item if it touches a torch? :D
Icalasari wrote:Thanks for all the advice theretaikedz wrote:Will it drop as "fried bug" item if it touches a torch? :D
And now I need to figure that out somehow. So far the only joke thing in it is that you get a captured stick "bug" by using the recipe of Jar and Stick
print(user.get_player_name(user))
minetest.register_chatcommand("GiveName", {
func = function(name, param)
minetest.show_formspec(name, "turtle_miner:form",
"size[8,3]" ..
"label[0,0;Hello, " .. name .. ", what is the name of you turtle?]" ..
"field[1,1.5;3,1;name;Name;]" ..
"button_exit[1,2;2,1;exit;Save]")
end
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "turtle_miner:form" then
return false
end
minetest.chat_send_player(player:get_player_name(), "Okay lets call it " .. fields.name .. "!")
return true
end)
minetest.register_node("turtle_miner:firstturtle", {
description = "First Turtle for Trials",
tiles = {"turtle_miner_firstturtle_top.png", "turtle_miner_firstturtle_buttom.png", "turtle_miner_firstturtle_right.png", "turtle_miner_firstturtle_left.png", "turtle_miner_firstturtle_back.png", "turtle_miner_firstturtle_front.png"},
groups={oddly_breakable_by_hand=1},
on_punch = function(pos, node, puncher, pointed_thing)
local wielditem = puncher:get_wielded_item()
local wieldname = wielditem:get_name()
if wieldname == "turtle_miner:remotecontrol" then
minetest.show_formspec(puncher, "give_name",
"size[8,3]" ..
"label[0,0;Hello, " .. puncher .. "]" ..
"field[1,1.5;3,1;name;Name;]" ..
"button_exit[1,2;2,1;exit;Save]")
else
minetest.chat_send_player(user:get_player_name(), "Nimm die Fernbedienung!")
end
end
})
ERROR[Main]: ServerError: Lua: Runtime error from mod 'turtle_miner' in callback node_on_punch(): /home/birgit/.minetest/mods/turtle_miner/init.lua:19: attempt to concatenate local 'puncher' (a userdata value)
2016-10-12 12:44:50: ERROR[Main]: stack traceback:
2016-10-12 12:44:50: ERROR[Main]: /home/birgit/.minetest/mods/turtle_miner/init.lua:19: in function </home/birgit/.minetest/mods/turtle_miner/init.lua:11>minetest.register_craft({
output = 'cash:platinum',
type = 'shapeless',
recipe = {'cash:gold', count = 100, wear = 0, metadata = ''}
})Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)D00Med wrote:Does anyone know why this doesn't work when damage is enabled? The problem seems to be the "if player:hud_get(fr1) == nil", but I don't understand why, or how to get around the problem. It works fine on creative.Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
function tool_anim(player, interval, frame1, frame2, frame3)
if player:hud_get(fr1) == nil then
fr1 = player:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
scale = {
x = -100,
y = -100
},
text = frame1
})
end
...(continues)
function tool_anim(player, interval, frame1, frame2, frame3)
if not fr1 then --if you havent initialized fr1, you can assume the hud does not exist
fr1 = player:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
scale = {
x = -100,
y = -100
},
text = frame1
})
end
...(continues)fr1={}
...
if not fr1[player:get_player_name()] then
fr1[player:get_player_name()]=hud_add(...)
zm78 wrote:Topic: How do i upload a zip file?
Reason: I want to make a zip file as well as a git file.
More Info: I've tried but it is not working.
function(pos, node, puncher, pointed_thing)local node = get_node(pos) --obtain current node
local meta = get_meta(pos):to_table() --get metadata of current node
remove_node(pos)
local value = pos[axis] --store current position
pos[axis] = value + amount --move along axis
add_node(pos, node) --move node to new position
get_meta(pos):from_table(meta) --set metadata of new node
pos[axis] = value --restore old position
pos.z = pos.z + 1
BirgitLachner wrote:TL;DR
2.) I understand that I need to position/id/? of the node to move it but how do I get it? I show the formspec after that call(?) ...
-- Table to know where the players turtles are
local turtle_formspec_positions = {}
minetest.register_node("turtle:turtle", {
...
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
-- When the player does a right click on this node
local player_name = clicker:get_player_name()
-- Save the last turtle in a table
turtle_formspec_positions[player_name] = pos
minetest.show_formspec(player_name, "turtle:control_formspec", "<formspec>")
return itemstack
end,
})
-- Catch user inputs from the formspec
minetest.register_on_player_receive_fields(function(sender, formname, fields)
if formname ~= "turtle:control_formspec" then
return -- Not a turtle formspec
end
local player_name = sender:get_player_name()
local pos = turtle_formspec_positions[player_name]
if not pos then
return -- Something went wrong. No position found for this player
end
local node = minetest.get_node(pos)
if node.name ~= "turtle:turtle" then
turtle_formspec_positions[player_name] = nil
return -- Data invalid. There's no turtle at the given position
end
local new_pos = vector.new(pos)
local meta = minetest.get_meta(pos):to_table()
if fields.up then
-- Button up was pressed
new_pos.y = new_pos.y + 1
end
if not vector.equals(pos, new_pos) then
-- Move node to new position
minetest.remove_node(pos)
minetest.set_node(new_pos, node) --move node to new position
minetest.get_meta(new_pos):from_table(meta) --set metadata of new node
-- Update formspec reference position, wait for next instructions
turtle_formspec_positions[player_name] = pos
end
end)Users browsing this forum: No registered users and 4 guests