Page 85 of 125

Re: Post your modding questions here

PostPosted: Mon Jan 18, 2016 18:54
by Hybrid Dog
moveto makes it look like object is grabbed and put to pos very fast, whereas
setpos makes it look like object is suddenly at pos

Re: Post your modding questions here

PostPosted: Mon Jan 18, 2016 19:06
by iangp
@Hybrid Dog
it would be cool if this function uses "velocity" as a parameter ...
because this way there's no real reason for use that function... I can't see one...

Re: Post your modding questions here

PostPosted: Mon Jan 18, 2016 19:17
by rubenwardy
iangp wrote:@Hybrid Dog
it would be cool if this function uses "velocity" as a parameter ...
because this way there's no real reason for use that function... I can't see one...


It's for interpolation, to minimise the appearence of lag. When a player walks, you don't want them to suddenly disappear then reappear in a new place, you want the to slide across. Velocity results in extrapolation, if the player is moving/turning fast then it will be unpredictable, so you'd end up with this:

Image

^--- note the player starts here, at the bottom left.

Re: Post your modding questions here

PostPosted: Mon Jan 18, 2016 20:36
by iangp
When a player walks, you don't want them to suddenly disappear then reappear in a new place, you want the to slide across.

Of course
It's for interpolation, to minimise the appearence of lag.

it's for: given a set of positions, if you want the player run through these points... you should use this function to the path seems more smooth...
Right?

Re: Post your modding questions here

PostPosted: Tue Jan 19, 2016 04:52
by OmniStudent
Hello! Can anyone help me with this?

Topic: Need example code that "locks" doors when an object is rightpunched.
Reason: I want to make an "airlock" for entering dungeons.
More Info: I've only done the initial lua tutorial yet, but I am savvy in other languages.

Re: Post your modding questions here

PostPosted: Tue Jan 19, 2016 18:02
by Hybrid Dog
iangp, player movement is predicted in minetest, else constantly the position of the player would need to be sent. l tried to make a spin bot, but it doesn't work because the player's yaw is sent less than every 0.2 seconds.

OmniStudent, in minetest an object is a spawned entity, e.g. a dropped item (http://dev.minetest.net/ObjectRef)
What exactly should locking doors do (or how are they locked)?

Re: Post your modding questions here

PostPosted: Tue Jan 19, 2016 19:37
by Byakuren
I want to write a spell that will dig a 3x3x3 area of nodes when used, and I want this to check protection and add entries to the rollback log, so it can be rolled-back if necessary. I could write a function that does everything other than the rollback, but I don't know if there is a way to add things to the rollback log this way. Is there? Or maybe there is a better way to do this.

Re: Post your modding questions here

PostPosted: Tue Jan 19, 2016 22:18
by mahmutelmas06
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
if wieldname == (
                    "default:gold_lump" or
                    "currency:minegeld" or
                    "currency:minegeld_5" or
                    "currency:minegeld_10" or
                    "bitchange:minecoin" or
                    "bitchange:mineninth" or
                    "homedecor:coin" )
                   
 then
      wielditem:take_item()


I want to drop an item from my vending machine mod if any of thoose above inserted.
But only the first one "default:gold_lump" works others not. So what punctuation to use for that ?

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 00:33
by kaeza
The code:
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
wieldname == (a or b or c)

Does not do what you expect. What it does is evaluate `a`, and if it results in a "true" value (anything other than `false` or `nil`), it uses that value. Otherwise, it evaluates `b`, and if it results on a "true" value, it uses that value. Same for `c`.

Since `a` in your case is the string "default:gold_lump", `a` is not "false", so the expression (a or b or c) results in "default:gold_lump". Then Lua compares `wieldname` to the result of the expression. The expression `("default:gold_lump" or ...)` always result in "default:gold_lump".

You have two approaches. You can explicitly test for the strings:
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
if wieldname == "foo" or wieldname == "bar" or wieldname == "baz" or ...

Or you can use a table mapping accepted values to `true`:
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 valid = {
  ["default:foo"] = true,
  ["default:bar"] = true,
  -- ...
}
-- Then in your check
if valid[wieldname] then
  print("I am doing something.")
end


Which one is better is up to you. I'd use the former if the list of valid options is short, but use the latter if you need lots of items.

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 05:32
by OmniStudent
[quote=
OmniStudent, in minetest an object is a spawned entity, e.g. a dropped item (http://dev.minetest.net/ObjectRef)
What exactly should locking doors do (or how are they locked)?[/quote]

Ah, I suppose I should have written "node" instead of object.
The purpose of the locked door is to prevent players from exiting or entering (new players) a dungeon until they've completed some sort of objective.

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 08:36
by Byakuren
Byakuren wrote:I want to write a spell that will dig a 3x3x3 area of nodes when used, and I want this to check protection and add entries to the rollback log, so it can be rolled-back if necessary. I could write a function that does everything other than the rollback, but I don't know if there is a way to add things to the rollback log this way. Is there? Or maybe there is a better way to do this.

To answer my own question, it looks like minetest.node_dig will do the job of checking protection and digging for some player, though it's not clear if it adds to the rollback log. I will try it out when I have time.

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 09:24
by mahmutelmas06
Thank you Kaeza for help.
I will use the list one

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 14:30
by bark
Would it be possible to create an NPC as a node, and not as an object?

The reason I would like to do this: I want to place talking NPC's that add a backstory to the world. You know, with interactive dialogue. I don't want to replace them everytime I run /clearobjects.

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 15:39
by Dragonop
How you do get the number of items in a stack that is inside an inventory slot in a formspec to display in the infotext of a node?

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 16:14
by jp
Dragonop wrote:How you do get the number of items in a stack that is inside an inventory slot in a formspec to display in the infotext of a node?

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 meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("infotext", tostring(inv:get_stack("listname", index):get_count()))

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 16:46
by Hybrid Dog
OmniStudent wrote:Ah, I suppose I should have written "node" instead of object.
The purpose of the locked door is to prevent players from exiting or entering (new players) a dungeon until they've completed some sort of objective.

You could set a locked steel door and then set its owner to some string which can't be a playername, e.g. "§singleplayer", and if you completed the objective, the steel door's owner is changed to your name.
The owner is stored in meta: https://github.com/HybridDog/minetest_g ... it.lua#L87

bark wrote:Would it be possible to create an NPC as a node, and not as an object?

The reason I would like to do this: I want to place talking NPC's that add a backstory to the world. You know, with interactive dialogue. I don't want to replace them everytime I run /clearobjects.

it's possible but it would be fairly immobile (compare with a chest which looks like a player and talks to you via changing its infotext)

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 17:00
by qwertymine3
bark wrote:Would it be possible to create an NPC as a node, and not as an object?

The reason I would like to do this: I want to place talking NPC's that add a backstory to the world. You know, with interactive dialogue. I don't want to replace them everytime I run /clearobjects.


If you want to have object NPCS, you may want to look at the item frame mod.
These mods have a node which recovers the object used to display the item after a /clearobjects.

Looking at the code, it looks like the npcs wouldn't be able to move - but they would still have the
advantage of being animate-able.

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 17:22
by Dragonop
jp wrote:-snip-

Thanks jp!

Re: Post your modding questions here

PostPosted: Wed Jan 20, 2016 18:44
by bark
Thanks for the great input! Will look further into this.

Re: Post your modding questions here

PostPosted: Thu Jan 21, 2016 05:39
by OmniStudent
Hybrid Dog wrote:
OmniStudent wrote:Ah, I suppose I should have written "node" instead of object.
The purpose of the locked door is to prevent players from exiting or entering (new players) a dungeon until they've completed some sort of objective.

You could set a locked steel door and then set its owner to some string which can't be a playername, e.g. "§singleplayer", and if you completed the objective, the steel door's owner is changed to your name.
The owner is stored in meta: https://github.com/HybridDog/minetest_g ... it.lua#L87



Thanks for the suggestion! I didn't know about the default locked steel door. In that case, can I just replace a real steel door with a steel door-skinned regular door when its supposed to be open. Or just delete the steel door.

Re: Post your modding questions here

PostPosted: Sun Jan 24, 2016 00:00
by swordpaint12
Hi guys,
I am learning to make mods and recently I created a simple mud mod. I was unable to create a crafting recipe which I wanted to be a water bucket and block of dirt shapeless. I don't remember what I wrote but I was following the outline found on rubenwardy's tutorial. Could someone show me what the proper recipe would look like?

(PS: Here is the code for the mud block.
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("mud:mud", {
   description = "Mud",
   tiles = {"mud_v.1.png"},
   groups = {crumbly=1,soil=3,oddly_breakable_by_hand=10},
})

Re: Post your modding questions here

PostPosted: Sun Jan 24, 2016 01:12
by Dragonop
swordpaint12 wrote:Hi guys,
I am learning to make mods and recently I created a simple mud mod. I was unable to create a crafting recipe which I wanted to be a water bucket and block of dirt shapeless. I don't remember what I wrote but I was following the outline found on rubenwardy's tutorial. Could someone show me what the proper recipe would look 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
minetest.register_node("mud:mud", {
   description = "Mud",
   tiles = {"mud_v.1.png"},
   groups = {crumbly = 1, soil = 3, oddly_breakable_by_hand = 10}
})

minetest.register_craft({
type = "shapeless",
output = "mud:mud",
recipe = {"bucket:bucket_water", "default:dirt"},
replacements = {
         {"bucket:bucket_water", "bucket:bucket_empty"},
         }
})

Added replacements, so you get the bucket back after using the water.
I also recommend putting spaces when doing stuff like "group = 1".
"type" specifies if your craft is shapeless, shaped, etc. It is shaped by default, if you don't specify anything.
Check lua_api.txt it should be on your docs folder. It has useful info.
BTW: you can't break by hand a node that is oddly_breakable_by_hand = 10 ...

Re: Post your modding questions here

PostPosted: Sun Jan 24, 2016 15:07
by isaiah658
I have a question about using minetest.after to call a function. Is it possible to use a variable time for minetest.after or does it have to be a static time? I wanted to try and use minetest.after vs a global step timer but I'm getting errors when using variables for the time. I wasn't sure if there was some way to make it see the variable as a number rather than a variable so it would work.

Re: Post your modding questions here

PostPosted: Sun Jan 24, 2016 15:57
by Dragonop
I'm making a mod, it adds a way to create clay with a machine, its formspec is mostly based in furnace.lua from default, but when there is no more room but there is still fuel (in this case called water) and an item (it uses compressed dirt), it stays active and won't change back into the inactive node (claycrafter:claycrafter_active to claycrafter:claycrafter), so far I have managed to make it change, but then it immediatly goes back to the active node (it flickers from active to inactive).

https://github.com/Dragonop/claycrafter ... rafter.lua

Also, feel free to make suggestions about the mod.

Re: Post your modding questions here

PostPosted: Sun Jan 24, 2016 16:55
by Hybrid Dog
Dragonop wrote:Also, feel free to make suggestions about the mod.

use node timer instead of abm

Re: Post your modding questions here

PostPosted: Sun Jan 24, 2016 17:38
by everamzah
The original furnace does not use a node timer, so why should Dragonop's claycrafter? I'd like to also point out that in minetest_game there are only two nodes which use node timers: Bones, and TNT. In my experience they are not always reliable.

Re: Post your modding questions here

PostPosted: Sun Jan 24, 2016 18:55
by Byakuren
isaiah658 wrote:I have a question about using minetest.after to call a function. Is it possible to use a variable time for minetest.after or does it have to be a static time? I wanted to try and use minetest.after vs a global step timer but I'm getting errors when using variables for the time. I wasn't sure if there was some way to make it see the variable as a number rather than a variable so it would work.

There's no reason you can't use a variable for the time argument. Mind posting your error (including stack trace) and the relevant mod code? (In a spoiler, or a paste site like lpaste.net)

Re: Post your modding questions here

PostPosted: Mon Jan 25, 2016 01:39
by isaiah658
There's no reason you can't use a variable for the time argument. Mind posting your error (including stack trace) and the relevant mod code? (In a spoiler, or a paste site like lpaste.net)


I got it figured out now! What was happening is that when I changed my code over from using global step timers to minetest.after timers I overlooked something. I had a minetest.after with a 0 second delay and inside that there was something that was trying to get the time of day. Because the delay was 0 the world apparently doesn't load yet (did not know that) so the value was null/not a number. I was then trying to pass that bad value to another minetest.after as the time. Thank you for letting me know it was possible though! I would have given up thinking it just didn't want variables.

Re: Post your modding questions here

PostPosted: Mon Jan 25, 2016 03:35
by Byakuren
I want an item that's not used for digging to display wear. If I register it as a tool and override on_use, will it still dig?

Or maybe there is a better way to achieve this?

EDIT: Tried it, overriding on_use prevents it from digging.

Re: Post your modding questions here

PostPosted: Mon Jan 25, 2016 04:39
by Byakuren
Does it matter if I put a non-number as the value for a custom group? E.g.
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
groups = { favorite_color = "red" }