Page 1 of 2

Again? Yep, again... More questions.

PostPosted: Wed Mar 13, 2013 02:11
by Tedypig
1. What is max_drop_level=# (tool)
2. What is max_level=# (also tool)
3. How (if possible) do you make a chat_send_all when a player digs a certain node?
4.How do you make a tool light up while you wield it? (like the mese pickaxe in the walking light mod)

PostPosted: Wed Mar 13, 2013 03:06
by Tedypig
I figured most of it out on my own. However, I did get 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
23:00:46: ERROR[main]: ========== ERROR FROM LUA ===========
23:00:46: ERROR[main]: Failed to load and run script from
23:00:46: ERROR[main]: C:\Users\Matt and Betty\Downloads\minetest-0.4.5\minetest-0.4.5\bin\..\worlds\test\worldmods\sits\init.lua:
23:00:46: ERROR[main]: ....4.5\minetest-0.4.5\bin\..\builtin/misc_register.lua:170: attempt to index local 'tooldef' (a nil value)
23:00:46: ERROR[main]: stack traceback:
23:00:46: ERROR[main]:     ....4.5\minetest-0.4.5\bin\..\builtin/misc_register.lua:170: in function 'register_tool'
23:00:46: ERROR[main]:     ...est-0.4.5\bin\..\worlds\test\worldmods\sits\init.lua:6: in main chunk
23:00:46: ERROR[main]: =======END OF ERROR FROM LUA ========
23:00:46: ERROR[main]: Server: Failed to load and run C:\Users\Matt and Betty\Downloads\minetest-0.4.5\minetest-0.4.5\bin\..\worlds\test\worldmods\sits\init.lua
23:00:46: ERROR[main]: ModError: Failed to load and run C:\Users\Matt and Betty\Downloads\minetest-0.4.5\minetest-0.4.5\bin\..\worlds\test\worldmods\sits\init.lua


Here is 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
--Sword In The Stone Mod By Tedypig.  --Licence: Not sure, You can use/modify/redistribute how you want,
--but please give me credit for the original mod in the supplied readme.

-- Sword in the stone - SWORD

minetest.register_tool("sits:sword_of_ultimate_power"){
description "Adds a sword that can cut/chop/dig/kill anything in one hit, and lights up like the sun.",
inventory_image="sword_of_ultimate_power.png",
light_source='LIGHT_MAX',
tool_capabilities={
    full_punch_interval=0.1,
    max_drop_level=1,
    groupcaps={
            fleshy={times={[1]=100.00}, uses=0, maxlevel=2},
            snappy={times={[1]=100.00}, uses=0, maxlevel=1},
            choppy={times={[1]=100.00}, uses=0, maxlevel=0},
                }
    }
}


--Crafting

--No crafting. You must find the "Sword In The Stone" to obtain this sword.

--Sword in the stone - NODE

minetest.register_node ("sits:swordinthestone"){
    description "The stone you must find to get the sword of ultimate power.",
    drawtype = 'draw',
    tiles = 'swordinthestone.png',
    inventory_image = 'swordinthestone.png',
    paramtype = 'light',
    walkable = false,
    sunlight_propagates = true,
    drop = 'sits:sword_of_ultimate_power',
        groups ={
        {crumbly=10}
        }
}

--Crafting
--No crafting, Must be placed by the server owner in creative mode.

PostPosted: Wed Mar 13, 2013 03:12
by prestidigitator
For max_drop_level and max_level I suggest reading the documentation for the groups and damage in the lua_api.txt file that comes with the game download. For chat_send_all you'll probably want to set a custom after_dig_node callback on the node type. For a SPECIFIC node (as in one at a particular location) where you aren't in control of the node type you might not have that option, and might have to use the global minetest.register_on_dignode() instead (but avoid this if possible).

For making a tool light up, you really can't. The walking light mod is a really dirty hack that replaces nodes around a moving character with invisible lit up nodes (basically invisible torches). This doesn't work very well in water or if the player is moving past a real torch or something; the mod will actually replace other nodes as you move past them. That's not a dig at the mod creator; it's just unfortunately the only way to fudge a moving light in the game right now.

PostPosted: Wed Mar 13, 2013 04:45
by Menche
It looks like you forgot the equals sign for "description" in the tool definition.

PostPosted: Wed Mar 13, 2013 08:05
by prestidigitator
Menche wrote:It looks like you forgot the equals sign for "description" in the tool definition.

Good catch. This should by all rights be a syntax error, but unfortunately the designers of the Lua language decided you should be able to call a function with a single string literal parameter without using parentheses. This is a thorn in everyone's side at some point or another.

There's another problem that is causing the actual error message though. The table with the tool definitions actually must be a parameter to the minetest.register_tool() call, but there is a closing parenthesis that terminates the function call before it. Compare the following:

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
-- This is what you have:
minetest.register_tool("sits:sword_of_ultimate_power") { ... }

-- This is what you need:
minetest.register_tool("sits:sword_of_ultimate_power", { ... })


(The same goes for the call to minetest.register_node() farther down.)

PostPosted: Wed Mar 13, 2013 10:35
by rarkenin
prestidigitator wrote:For making a tool light up, you really can't. The walking light mod is a really dirty hack that replaces nodes around a moving character with invisible lit up nodes (basically invisible torches). This doesn't work very well in water or if the player is moving past a real torch or something; the mod will actually replace other nodes as you move past them. That's not a dig at the mod creator; it's just unfortunately the only way to fudge a moving light in the game right now.


Is there a way to make an entity light up? Or to make it so the player is bound to an entity, but the player moves the entity(not the entity moves the player)?

PostPosted: Wed Mar 13, 2013 12:32
by Tedypig
Ok, I figured this out. The sword is effing awesome. One problem though, Mese and Trees will NOT cut for some reason. I hack away at them forever and they don't break. Also for some reason my node that drops the sword is not showing the image, instead it's showing the unknown block image. Any ideas? I would like to release this today if possible.

Here is 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
--Sword In The Stone Mod By Tedypig.  --Licence: Not sure, You can use/modify/redistribute how you want,
--but please give me credit for the original mod in the supplied readme.

-- Sword in the stone - SWORD

minetest.register_tool("sits:sword_of_ultimate_power", {
description = "Adds a sword that can cut/chop/dig/kill anything in one hit.",
inventory_image="sword_of_ultimate_power.png",
tool_capabilities={
    full_punch_interval=0,
    max_drop_level=1,
    groupcaps={
            fleshy={times={[1]=100.00}, uses=0, maxlevel=1},
            snappy={times={[1]=100.00}, uses=0, maxlevel=1},
            choppy={times={[1]=100.00}, uses=0, maxlevel=1},
            crumbly={times={[1]=100.00}, uses=0, maxlevel=1},
            cracky={times={[1]=100.00}, uses=0, maxlevel=1},
                }
    }
})


--Crafting

--No crafting. You must find the "Sword In The Stone" to obtain this sword.

--Sword in the stone - NODE

minetest.register_node ("sits:swordinthestone", {
    description = "The stone you must find to get the sword of ultimate power.",
    drawtype = 'draw',
    tiles = 'swordinthestone.png',
    inventory_image = 'swordinthestone.png',
    paramtype = 'light',
    walkable = false,
    sunlight_propagates = true,
    drop = 'sits:sword_of_ultimate_power',
        groups ={crumbly=1},
    }
)

--Crafting
--No crafting, Must be placed by the server owner in creative mode.


Edit: The inventory image work, but not when I place it.
Edit2: My new node wont break with the sword either.

PostPosted: Wed Mar 13, 2013 14:06
by Tedypig
Fixed the image not displaying. (I forgot the {} brackets)

Made a TODO list.
1. Make it break; my new node, mese, and trees.
2. Write a callback to chat_send_all when my node is dug.
3. RELEASE!

Those are not in order. It's actually 1,3,2.

PostPosted: Wed Mar 13, 2013 14:14
by Tedypig
---Screenshots---
Sword on the ground.
Image
Sword in hand.
Image
Node (drops the sword)
Image

PostPosted: Wed Mar 13, 2013 17:17
by prestidigitator
rarkenin wrote:Is there a way to make an entity light up? Or to make it so the player is bound to an entity, but the player moves the entity(not the entity moves the player)?

At this time, no. Only nodes can generate light, not entities. Frustrating.

PostPosted: Thu Mar 14, 2013 02:52
by Tedypig
I hate to be a bug, but can someone help me with the sword not digging those blocks.
Also, could someone write the callback for when someone digs the node.

I would like it to say "<player> just found the Sword In The Stone and received the Sword Of Ultimate Power at <position>. Congratulations!"

If I can get help with these two things I can release by midnight. YOU WILL GET CREDIT FOR YOUR HELP!!!

Thanks in advance. ----Tedypig

PostPosted: Thu Mar 14, 2013 03:12
by Tedypig
Figured out the not digging, not it wont hurt other players. Help?

PostPosted: Thu Mar 14, 2013 08:48
by prestidigitator
To hurt players you need the "fleshy" group in the tool capabilities.

The callback should be relatively simple. Just call minetest.chat_send_player() or minetest.chat_send_all() in the after_dig_node() callback on the node.

PostPosted: Thu Mar 14, 2013 15:16
by Tedypig
prestidigitator wrote:To hurt players you need the "fleshy" group in the tool capabilities.

The callback should be relatively simple. Just call minetest.chat_send_player() or minetest.chat_send_all() in the after_dig_node() callback on the node.


I have fleshy as the same setting as all the other groups, I just can't get it to hurt people. I have it as a one hit dig/chop/cut/kill.

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
 fleshy={times={[1]=0, [2]=0, [3]=0}, uses=0, maxlevel=1},
            snappy={times={[1]=0, [2]=0, [3]=0}, uses=0, maxlevel=1},
            choppy={times={[1]=0, [2]=0, [3]=0}, uses=0, maxlevel=1},
            crumbly={times={[1]=0, [2]=0, [3]=0}, uses=0, maxlevel=1},
            cracky={times={[1]=0, [2]=0, [3]=0}, uses=0, maxlevel=1},

PostPosted: Thu Mar 14, 2013 16:52
by prestidigitator
Huh. And PVP is enabled? Do other weapons hurt other players?

PostPosted: Thu Mar 14, 2013 20:07
by Tedypig
prestidigitator wrote:Huh. And PVP is enabled? Do other weapons hurt other players?

If by PvP you mean damage enabled, then yes I do. Also, yes the other weapons hurt. I don't friggen get it. Lol.

PostPosted: Thu Mar 14, 2013 20:54
by Calinou
This is how the damage system works:
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_tool("default:sword_steel", {
    description = "Steel Sword",
    inventory_image = "default_tool_steelsword.png",
    tool_capabilities = {
        full_punch_interval = 0.8,
        max_drop_level=1,
        groupcaps={
            fleshy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=10, maxlevel=2},
            snappy={times={[2]=0.70, [3]=0.30}, uses=40, maxlevel=1},
            choppy={times={[3]=0.65}, uses=40, maxlevel=0}
        }
    }
})


You can have up to 0.8 of "punch time" (silly self-invented term). You'll deal 2 damage (= 1 heart) to entities with fleshy=3, 1 damage to entities with fleshy=2 and no damage to entities with fleshy=1.

PostPosted: Thu Mar 14, 2013 21:34
by Likwid H-Craft
Q:How Many Players can be on one server?

PostPosted: Thu Mar 14, 2013 22:05
by Calinou
Likwid H-Craft wrote:Q:How Many Players can be on one server?


Probably thousands. :P
If you want to ask a question, you should create a new topic instead.

PostPosted: Thu Mar 14, 2013 22:24
by Tedypig
Calinou wrote:This is how the damage system works:
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_tool("default:sword_steel", {
    description = "Steel Sword",
    inventory_image = "default_tool_steelsword.png",
    tool_capabilities = {
        full_punch_interval = 0.8,
        max_drop_level=1,
        groupcaps={
            fleshy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=10, maxlevel=2},
            snappy={times={[2]=0.70, [3]=0.30}, uses=40, maxlevel=1},
            choppy={times={[3]=0.65}, uses=40, maxlevel=0}
        }
    }
})


You can have up to 0.8 of "punch time" (silly self-invented term). You'll deal 2 damage (= 1 heart) to entities with fleshy=3, 1 damage to entities with fleshy=2 and no damage to entities with fleshy=1.


Right, I know. I read the ones for the wood,stone, and steel swords, but I wanted a "one hitter quitter". Is there a way to do that? Right now everything else is one click destroy, I don't see why this can't be set to fleshy also.

PostPosted: Fri Mar 15, 2013 04:13
by prestidigitator
(I meant PVP as in there is a server option that can be used to turn off PVP damage. This is separate from whether damage is enabled at all, I believe. Anyway, this isn't the issue if other weapons are working.)

I really don't know what the behavior will be if the times are set to zero. You could try a really small value (e.g. 0.001) instead, maybe. As Calinou said, you might try defining full_punch_interval too. This could be a small value too. Basically I think the ratio of full_punch_interval/times[...] it going to be the maximum damage the weapon does, and it will do this much damage on the first swing and if you wait pull_punch_interval between swings.

More about entity damage can be found in lua_api.txt, and I've added a synopsis to the LuaEntitySAO article on the dev wiki.

Of course, if you want a really, really sure way to kill a player with a weapon in one hit, forget the built-in damage and do something 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_tool(
   "...",
   {
      ...,

      on_use = function(stack, player, pointedThing)
         local pos = pointedThing.under
         local obj = pointedThing.ref
         if pointedThing.type == "object" and obj then
            obj:set_hp(0)
            if not obj:get_player_name() then
               -- Non-player entities have to be removed explicitly
               obj:remove()
            end
         elseif pointedThing.type == "node" and pos then
            minetest.node_dig(pos, minetest.env:get_node(pos), player)
         end
      end
   })


That should do a one-swing kill on literally anything. The code is untested, so there might need to be a small change or two.

PostPosted: Fri Mar 15, 2013 17:08
by Tedypig
Everything is still the same, but now it takes two hits to remove a node instead of one. No damage to other players or mobs.

PostPosted: Fri Mar 15, 2013 17:31
by prestidigitator
With THAT code? Erm.... Maybe throw some debug statements in then and see what branches of the code you are reaching with various uses. I don't know what else to tell you.

PostPosted: Fri Mar 15, 2013 17:49
by Tedypig
prestidigitator wrote:With THAT code? Erm.... Maybe throw some debug statements in then and see what branches of the code you are reaching with various uses. I don't know what else to tell you.


I hit a vombie.

13:45:24: ACTION[ServerThread]: LuaEntitySAO at (266.17,11.7,-260.087) punched by player Teddypig, damage 0 hp, health now 8 hp

This is how I did the code. Is it right?
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_tool("sits:sword_of_ultimate_power", {
description = "Sword Of Ultimate Power",
inventory_image="sword_of_ultimate_power.png",
tool_capabilities={
    full_punch_interval=0,
    max_drop_level=1,
on_use = function(stack, player, pointedThing)
         local pos = pointedThing.under
         local obj = pointedThing.ref
         if pointedThing.type == "object" and obj then
            obj:set_hp(0)
            if not obj:get_player_name() then
               -- Non-player entities have to be removed explicitly
               obj:remove()
            end
         elseif pointedThing.type == "node" and pos then
            minetest.node_dig(pos, minetest.env:get_node(pos), player)
         end
      end
      }
   })
       

PostPosted: Fri Mar 15, 2013 17:54
by prestidigitator
Oh. No, it's not. "on_use" should come before or after "tool_capabilities", not inside it. Actually you could probably just REPLACE tool_capabilities with it, since I don't think the tool capabilities will be used if you have an explicit on_use handler.

PostPosted: Fri Mar 15, 2013 18:00
by Tedypig
NOW, still no damage (doesn't even register that I swung it), and no continuous hitting. It DOES however remove a block with one hit. I apologize if I'm being a bother.

PostPosted: Fri Mar 15, 2013 21:39
by prestidigitator
No bother at all. Try putting this statement just before the if-statement in on_use:
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("DEBUG sword.on_use: pointedThing.type = "..(pointedThing.type or "nil")..", pos = "..(pos and minetest.pos_to_string(pos) or "nil")..", obj = "..(obj and (obj:get_player_name() or "(NP entity)") or "nil"))

That should tell us what the weapon thinks you are swinging at, and if the "pointed_thing" is behaving the way we're told is does.

PostPosted: Fri Mar 15, 2013 22:33
by Tedypig
Well I feel like it.

Debug info.
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
18:29:30: ACTION[ServerThread]: Teddypig joins game. List of players: Teddypig
Font size: 8 17
18:29:39: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [node under=36,19,-192 above=36,20,-192]
DEBUG sword.on_use: pointedThing.type = node, pos = (36,19,-192), obj = nil
node_dig
18:29:39: ACTION[ServerThread]: Teddypig digs default:dirt_with_grass at (36,19,-192)
18:29:40: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [node under=36,19,-191 above=36,20,-191]
DEBUG sword.on_use: pointedThing.type = node, pos = (36,19,-191), obj = nil
node_dig
18:29:40: ACTION[ServerThread]: Teddypig digs default:dirt_with_grass at (36,19,-191)
18:29:44: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [object 5]
DEBUG sword.on_use: pointedThing.type = object, pos = nil, obj =
18:29:45: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [object 5]
DEBUG sword.on_use: pointedThing.type = object, pos = nil, obj =
18:29:46: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [object 5]
DEBUG sword.on_use: pointedThing.type = object, pos = nil, obj =
18:29:50: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [object 5]
DEBUG sword.on_use: pointedThing.type = object, pos = nil, obj =
18:29:59: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [node under=22,23,-185 above=23,23,-185]
DEBUG sword.on_use: pointedThing.type = node, pos = (22,23,-185), obj = nil
node_dig
18:29:59: ACTION[ServerThread]: Teddypig digs default:stone at (22,23,-185)
18:30:00: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [node under=22,23,-186 above=23,23,-186]
DEBUG sword.on_use: pointedThing.type = node, pos = (22,23,-186), obj = nil
node_dig
18:30:00: ACTION[ServerThread]: Teddypig digs default:stone at (22,23,-186)
18:30:00: ACTION[ServerThread]: Teddypig uses sits:sword_of_ultimate_power, pointing at [node under=22,23,-187 above=23,23,-187]
DEBUG sword.on_use: pointedThing.type = node, pos = (22,23,-187), obj = nil
node_dig
18:30:00: ACTION[ServerThread]: Teddypig digs default:stone at (22,23,-187)
18:30:41: ACTION[ServerThread]: MOBF: Your mob table: 20871680 dropt into water moving to (2.4217445850372,3.2999999523163,-162.2046661377) state: drop
18:30:43: ERROR[main]: ServerEnvironment::deactivateFarObjects(): id=5 m_static_exists=true but static data doesn't actually exist in (4,0,-12)
WARNING: StaticObjectList::remove(): id=5 not found

I dug two dirt_with_grass, swung at a sheep a few times and the dug two/three stone.

PostPosted: Fri Mar 15, 2013 22:41
by prestidigitator
Oh! Sorry. I guess ObjectRef:get_player_name() returns an empty string for non-players, not nil. Change the conditional to read:

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 pName = obj:get_player_name()
if not pName or pName == "" then ....


That should fix it for non-player entities. You tested it on a player also?

PostPosted: Fri Mar 15, 2013 23:47
by Tedypig
OK, this is what I have right now.
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_tool("sits:sword_of_ultimate_power", {
description = "Sword Of Ultimate Power",
inventory_image="sword_of_ultimate_power.png",
on_use = function(stack, player, pointedThing)
         local pos = pointedThing.under
         local obj = pointedThing.ref
         if pointedThing.type == "object" and obj then
            obj:set_hp(0)
            if not obj:get_player_name() then
               -- Non-player entities have to be removed explicitly
               obj:remove()
            end
         elseif pointedThing.type == "node" and pos then
            minetest.node_dig(pos, minetest.env:get_node(pos), player)
         end
      end
     
   })


Where do I put what you said?