Post your modding questions here

User avatar
dpbqRman
New member
 
Posts: 4
Joined: Fri Oct 07, 2016 08:15

Re: Post your modding questions here

by dpbqRman » Fri Oct 07, 2016 08:37

would someone make a big screen nintendo?
o__l_ dpbqR o-l&&&&&
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: Post your modding questions here

by azekill_DIABLO » Fri Oct 07, 2016 11:05

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?


override_item("builtin_____") or something like that
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: Post your modding questions here

by Krock » Fri Oct 07, 2016 11:25

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.

pithy wrote:Um, how do I override an entity?

You cannot use minetest.override_item for this. Instead, it's possible to access the data table directly:
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
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
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

PlanetKiller
Member
 
Posts: 14
Joined: Mon Nov 23, 2015 22:50

Re: Post your modding questions here

by PlanetKiller » Fri Oct 07, 2016 17:40

I'm going to be making a quadruped player and these are a few things I'd like to add.
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

I'm going to use the default player as the base and add these and a few other things. I already have the model and just need to animate it.
([noun].. " tried to " ..[verb]..[noun].. " at protected position "..[noun].. " with a bucket")
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: Post your modding questions here

by pithy » Fri Oct 07, 2016 20:53

pithy wrote:Is there a way to make a node kill you when it falls on your head?

Thanks for the answers. I found out how to do this now. Other people can do this the easy way now with my falling_nodes mod.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Fri Oct 07, 2016 23:47

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.
2. give character multi-jumps and low grav based upon type

See the `set_physics_override` method of player objects (here's some docs)
3. swap player model when jumping, or based upon gender

Detecting when the player is jumping is not trivial (depending on how accurate you want the results), plus it is subject to lag. Changing per gender should be no problem, though. Take a look at `default.player_set_model` (you should depend on `default` mod).
4. modify/view player hitbox

Not possible at the moment, sorry.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: Post your modding questions here

by azekill_DIABLO » Sat Oct 08, 2016 10:49

Is it possible to know the texture of a node like this?
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
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)
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Sat Oct 08, 2016 11:11

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
local tiles = minetest.registered_nodes[node.name].tiles
print(tiles[1])
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: Post your modding questions here

by azekill_DIABLO » Sat Oct 08, 2016 13:44

thank you :)
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

Icalasari
Member
 
Posts: 17
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: Post your modding questions here

by Icalasari » Sat Oct 08, 2016 20:59

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.


Thanks. And yeah it was node metadata - It slipped my mind at the time that item metadata was also a thing
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: Post your modding questions here

by Krock » Sun Oct 09, 2016 07:50

Icalasari wrote:Thanks. And yeah it was node metadata - It slipped my mind at the time that item metadata was also a thing

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 ;)
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

amadin
Member
 
Posts: 471
Joined: Tue Jun 16, 2015 16:23
GitHub: Amadin

[colorize:<color>:<ratio>

by amadin » Sun Oct 09, 2016 08:19

Is
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
[colorize:<color>:<ratio>
decrease a client traffic amount if using "colorize" instead colored textures or not? Server will send to client just text or it will send colored texture created by "colorize"? It not undestand dark_grey and dark_green colors, why?
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Sun Oct 09, 2016 22:50

Re: traffic, with `[colorize` the server only sends the "base" texture; the client first creates a copy of the texture (possibly loading it from disk first), then modifies it in memory.

Whether or not `[colorize` uses more data depends on many factors which I won't go over here. Just trust me that for all practical purposes it isn't worth even thinking about it. Just use whatever gives the best results visually.

Re: named colors, the list of supported colors is here (here's the source). You probably meant `darkgrey` and `darkgreen` without underscores.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

Icalasari
Member
 
Posts: 17
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: Post your modding questions here

by Icalasari » Sun Oct 09, 2016 23:48

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 ;)


Thanks again. And yeah, I had checked a few mods that have achieved similar things, but they weren't organized in a way that made sense (Default Wool mod = confusing. Meanwhile a tornado mod I end up 99% understanding off the bat x.x). The other one is getting an item once a day on right click, maybe give it a sub inventory so it can store up to three days worth, but other than figuring out how to get it to reliably check at midnight in game, I'll probably manage to figure that one out now that I have these links, at least to the point that I can get help with a code snippet when I end up crashing the game in new and exotic ways
 

User avatar
taikedz
Member
 
Posts: 587
Joined: Sun May 15, 2016 11:11
GitHub: taikedz
IRC: DuCake
In-game: DuCake

Re: Post your modding questions here

by taikedz » Mon Oct 10, 2016 02:20

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?


You can use mobs_redo as it is, then use entity_override to add a special override on mob_punch or on_right_click

viewtopic.php?f=9&t=15518

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


None by default, best bet is mobs_redo for now

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,


To follow the sky/faraway light source would be a tall order... but you could make it fly randomly, checking each node around it for light level, until it found a zone with a light level greater than that of the current node, and cause it to move towards that node...

This would require some significant coding on top of mobs_redo's "mob_step" function, but it would not be insurmountable.... you could use an override, do your light check, if you find better light, move your mob, else if nothing suitable is found, handover to mobs_redo normal code to move randomly...

Will it drop as "fried bug" item if it touches a torch? :D
 

User avatar
D00Med
Member
 
Posts: 712
Joined: Sat Feb 07, 2015 22:49
GitHub: D00Med

Re: Post your modding questions here

by D00Med » Mon Oct 10, 2016 04:52

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.

That was my intention - I only want to add fr1 if it doesn't exist already
Look! I have a signature :]
My subgame: https://forum.minetest.net/viewtopic.php?f=15&t=14051#p207242
dmobs2 is coming...
 

PlanetKiller
Member
 
Posts: 14
Joined: Mon Nov 23, 2015 22:50

Re: Post your modding questions here

by PlanetKiller » Mon Oct 10, 2016 19:51

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.


Config files come to mind, if I knew how to use them. You've given me some ideas, thanks. I've mainly been using a copy of the player script, but I think overrides will be easier. I'll have to find a way to override the animation lengths since some of my anims had to be a bit longer for four legs.

Thanks.
([noun].. " tried to " ..[verb]..[noun].. " at protected position "..[noun].. " with a bucket")
 

Icalasari
Member
 
Posts: 17
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: Post your modding questions here

by Icalasari » Tue Oct 11, 2016 05:49

Thanks for all the advice there

taikedz 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
 

PlanetKiller
Member
 
Posts: 14
Joined: Mon Nov 23, 2015 22:50

Re: Post your modding questions here

by PlanetKiller » Tue Oct 11, 2016 22:21

Icalasari wrote:Thanks for all the advice there

taikedz 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


I'd check node at position for the torch node and drop item / kill self. I'm guessing you are using on_tick somewhere right?

Currently I'm making another hack tool; to get metadata. I'm trying to get the player via user, then get it's metadata, but I'm unsure how. Nodes are easy, and entities might pose a problem. I'd like to be able to extend node/world/player metadata so I can really start working on my game, but I'm unsure what it looks like or how to access it.

Before saying, use get/set meta, bear in mind I need to get the player/node/entity first. also, nvm, found it.

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
print(user.get_player_name(user))


It vas in mine nodes script zis entire time, ha-ha.

Well, enjoy the tips.
([noun].. " tried to " ..[verb]..[noun].. " at protected position "..[noun].. " with a bucket")
 

BirgitLachner
Member
 
Posts: 135
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Wed Oct 12, 2016 09:40

Okay ... may be an absolut beginner question ...

I tried examples from Rubenwardys Mooding handbook.

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
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)


This is okay and even the Output via Chat works. But I want this formspec to be shown when the player clicks with a special item (turtle_miner:remotecontrol) on a special node (turtle_miner:firstturtle).

I tried to do this in steps ... first make a punch on the node to open the fomspec but that causes the Minetest-Game to freeze/crash.

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
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
})


The error message is, that there is a problem when trying to concatenate "puncher".
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
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>


Thanks for any help! Birgit
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Wed Oct 12, 2016 16:23

Puncher is a player object, not a name. You need to do

local name = puncher:get_player_name()
 

BirgitLachner
Member
 
Posts: 135
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Wed Oct 12, 2016 18:08

Thanks @Rubenwardy ... *argh* ... really a bit fussy that all. Hopefully I'll remember that with the next problem.
 

AB49K
New member
 
Posts: 1
Joined: Thu Oct 13, 2016 03:24

Re: Post your modding questions here

by AB49K » Thu Oct 13, 2016 03:28

Hi, I'm creating a mod and I'm new to this, but I'm trying to create a recipe that uses a stack of items.

Is there a way I can use more than 9 items (I'm trying to make an economy mod that converts 100 coins into a higher value coin)

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
minetest.register_craft({
    output = 'cash:platinum',
    type = 'shapeless',
    recipe = {'cash:gold', count = 100, wear = 0, metadata = ''}
})


This runs, but I cannot craft the coins.

Is it possible to use stacks of an item in crafting?
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

by Hybrid Dog » Thu Oct 13, 2016 15:04

>Is it possible to use stacks of an item in crafting?

Using register_craft it's not possible, you can use register_on_craft to do it.
https://github.com/minetest/minetest/bl ... .txt#L2023
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: Post your modding questions here

by azekill_DIABLO » Thu Oct 13, 2016 16:43

Oh thank you! how awesome!
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
zm78
Member
 
Posts: 50
Joined: Thu Dec 17, 2015 22:34
GitHub: zander999
IRC: [none]
In-game: zm78

Re: Post your modding questions here

by zm78 » Thu Oct 13, 2016 21:42

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.
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Sat Oct 15, 2016 07:04

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)

fr1 is not initialized, so its nil. hud_get does not like to be called with 'nil', it expects a hud id.
your code should look like this:
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 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)

but remember that this will only work in single player, hud ids are player specific and you store only one at all.
better fr1 is a table.
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
fr1={}
...
if not fr1[player:get_player_name()] then
fr1[player:get_player_name()]=hud_add(...)
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Sat Oct 15, 2016 07:11

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.

while posting, scroll down to attachments. just 'add the file' and post
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

BirgitLachner
Member
 
Posts: 135
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Sat Oct 15, 2016 07:52

For the upcomming TurtleMiner ...

Okay ... as you can see in the added picture, I can now punch the turtle with the remote control and there is a fromspec that is shown. I want to create a formspec to move the turtle around with arrow for forward, backward and so on.
turtle1.png
turtle1.png (297.62 KiB) Viewed 5163 times

Creating the formspec will not be the big problem. The first will not be really cool but it's just the solve the next thing, to make the node (= the turtle) to move around

I found some ideas how to solve it, within Worldedit, as you can move areas around.

But, I'm not sure, if my idea can work at least ...

1.) Is it possible to have button on the formspec to move the turtle around = to manipulate a node. That means if there can be a direct action from the formspec (I ask, because for the simple shown formspec from the modding handbook the input is analyzed in an other part of the code that the call of the formspec)
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(?) ...
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(pos, node, puncher, pointed_thing)

... and want to use something like ...
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
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

(okay ... that's to move an area around ... there need to be changes!!)

Now ... can you give me some hint, what I need to change, where I can find more ides how to realize it?
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: Post your modding questions here

by Krock » Sat Oct 15, 2016 11:03

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(?) ...


1.) Yes
2.) Like this: (whole formspec code & all, untested, needs tweaking)
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
-- 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)

License for that is WTFPL/CC0, if you care.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron