Page 103 of 169

Re: Post your modding questions here

Posted: Mon Jan 25, 2016 15:13
by Glorfindel
Is there a tutorial for creating textures for mods? What program is used usually, gimp?

Re: Post your modding questions here

Posted: Mon Jan 25, 2016 16:06
by rubenwardy

Re: Post your modding questions here

Posted: Mon Jan 25, 2016 17:13
by Hybrid Dog
everamzah wrote: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.
the original furnace is bad, it doesn't work when the chunk isn't loaded, same for farming

Re: Post your modding questions here

Posted: Mon Jan 25, 2016 18:19
by Dragonop
Hybrid Dog: I will try but I don't think I want to do everything again.
Any suggestion when using timers? An example would help too, thanks btw.

Re: Post your modding questions here

Posted: Mon Jan 25, 2016 19:10
by Hybrid Dog
The conveyor_belt mod uses them: viewtopic.php?id=7350

Re: Post your modding questions here

Posted: Mon Jan 25, 2016 21:24
by Dragonop
Ah, I see, thanks Hybrid Dog. I'm in my way to rewrite my mod completely to make it "better", this will help.

Re: Post your modding questions here

Posted: Thu Jan 28, 2016 09:06
by Byakuren
Does hp_max in the object properties table have any effect on players?

Re: Post your modding questions here

Posted: Fri Jan 29, 2016 19:47
by Merlin
Hi,
I would like to add more animations to the animation table of PilzAdam's Simple Mobs (like the walk and stand animations).
I looked into the code of the API, but as it is not commented I have difficulties understanding what's going on.
Can anyone explain to me how I would go about adding new animations?

Re: Post your modding questions here

Posted: Fri Jan 29, 2016 20:12
by Hybrid Dog
as far as l know the animations are in the model file

Re: Post your modding questions here

Posted: Fri Jan 29, 2016 21:00
by qwertymine3
Merlin wrote:Hi,
I would like to add more animations to the animation table of PilzAdam's Simple Mobs (like the walk and stand animations).
I looked into the code of the API, but as it is not commented I have difficulties understanding what's going on.
Can anyone explain to me how I would go about adding new animations?
I'm not an expert on animation - but I've been playing around with the mob code for some time - so I think I can explain it:
Spoiler
When registering a mob, you fill in the animation table:

Code: Select all

mob.animation = {
    [animation_name]_start = [number],
    [animation_name]_end = [number],
    [animation_name]_speed = [number],
}
These are the {x=[start],y=[end]} frame_speed=[speed] from the Objectref method :set_animation()
Spoiler
Throughout the code Pilzadam uses a single function to set all of the animations. This is the set_animation() method which he adds to the mob def @ line 57.
This method is generally called in the code in this style (this is massively simplified though):

Code: Select all

if self.state == "walk" then
    --do walking stuff
    self:set_animation("walk")
elseif self.state == "running" then
    --do running stuff
    self:set_animation("running")
elseif self.state == "multiple_actions" then
    if [action 1 happening] then
        --do action 1 stuff
        self:set_animation("action1")
    elseif [action 2 happening] then
        --do action 2 stuff
        self:set_animation("action2")
    end
end
The method itself seems long - but this is just because it uses a set of hard-coded names for the possible animations. All it does is a check that the animation is not the currently playing one - and if this is a different animation, it finds the animation values defined by the user (it checks to see if the animation has been defined - to avoid errors).

Here is a generalised version

Code: Select all

self.set_animaition = function(self,type)
    --if no animations defined return
    if not self.animations then
        return
    end

    --if no current animation is set, this is probably an error - so set a place holder value
    if not self.animation.current then
      self.animation.current = ""
    end

    --set the animation
    --check the current animation is not the same
    if self.animation.current ~= type then
        --check that all values required to set animation exist
        if
            self.animation[ type .. "_start"]
            and self.animation[ type .. "_end"]
            and self.animation[ type .. "speed"]
        then
             --set the animation - this is the Minetest API Objectref method :set_animation
            self.object:set_animation(
                {x=self.animation[type .. "_start"] , y=self.animation[type .. "_end"]},
                self.animation[type .. "_speed"], 
                0 --animation blend value is hard-coded to 0 - IDK why, ask pilzadam
            )
            --set current animation tracking variable to this animation name
            self.animation.current = type
        end
    end
end
Spoiler
This all assumes you know how animations work in Minetest - they are all stored in the model file as time sections of the long single animation the model can have (AFAIK - I can't model so can't help you with this).
You can't really add meaningful animations without adding some new ones to the model - unless you wish to use a pre-defined animation and change the animation speed. e.g. run v walk

Currently every state or action a mob can take has an animation - if you want to add more animations to the code, you will need to add checks to make sure only one animation can be set at any given state.e.g.

Code: Select all

if self.state = [state] then
    --some boring default stuff
    if my_condition then
        --do my awesome stuff
        self:set_animation("awesome_animation")
    else
        --do more boring default stuff
        self:set_animation("walk")
    end
end
To add the animation to mob.set_animation() you can copy the code from any of the elseif statements - changing every instance of the type name to your new animation.
I hope this helps

Re: Post your modding questions here

Posted: Sat Jan 30, 2016 01:59
by Merlin
That sounds good, I'll try playing around with it and come back if any more questions occur.
I can model and already adapted my own chicken model to the code which is already there, I just wish for more diversity.

Re: Post your modding questions here

Posted: Sat Jan 30, 2016 05:06
by Byakuren
When attaching an entity to another, how is the rotation argument formatted? Is it something like roll/pitch/yaw, or is it a direction vector?

Re: Post your modding questions here

Posted: Sat Jan 30, 2016 22:25
by Merlin
Hey, I tried out what qwertymine3 had suggested, and it worked (thanks a bunch!), I just have one last bug:

The animation (pick) I added plays two times in a row instead of just one, the bug does not exist in the model and therefor must be caused by the code.
Here are the snippets I changed:

Code: Select all

elseif type == "pick" and self.animation.current ~= "pick"  then
				if
					self.animation.pick_start
					and self.animation.pick_end
					and self.animation.speed_normal
				then
					self.object:set_animation(
						{x=self.animation.pick_start,y=self.animation.pick_end},
						self.animation.speed_normal, 0
					)
					self.animation.current = "pick"
				end

Code: Select all


			if self.state == "stand" then
				if math.random(1, 4) == 1 then
					self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
				end
				self.set_velocity(self, 0)
				self.set_animation(self, "stand")
				if math.random(1, 100) <= 50 then
					self.set_velocity(self, self.walk_velocity)
					self.state = "walk"
					self.set_animation(self, "walk")
				elseif math.random(1, 100) >= 60 then
					self.set_velocity(self, 0)
					self.state = "pick"
					self.set_animation(self, "pick")
				end

Code: Select all

	elseif self.state == "pick" then
				if math.random(1, 100) <= 30 then
					self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
				end
				self:set_animation("pick")
				self.set_velocity(self, 0)
				if math.random(1, 100) >= 10 then
					self.set_velocity(self, 0)
					self.state = "stand"
					self:set_animation("stand")
				end
I know that it can happen that, due to the math.random in the code above, the animation is executed two times (or more), which is fine by me, problem is, even when I set it to math.random(1, 100) >= 0 (which is always true), the animation plays two times.

Code: Select all

animation = {
		speed_normal = 15,
		stand_start = 0,
		stand_end = 33,
		walk_start = 50,
		walk_end = 62,
		pick_start = 34,
		pick_end = 42,
	}

I have two questions.

Posted: Sun Jan 31, 2016 02:08
by BrunoMine
About method:

Code: Select all

minetest.setting_set("name", "value")
He did not keep the values set after a server shutdown.

What the correct way to remove an element HUD?

Code: Select all

waypoint = {
    hud_elem_type = "waypoint",
    name = "My pos",
    number = "0x000000",
    world_pos = {x=0,y=0,z=0}
}
player:hud_add(waypoint)
...
player:hud_remove(waypoint)
The above example does not remove the HUD of the waypoint.
Another question: how to know the id of an element of HUD?

Re: I have two questions.

Posted: Sun Jan 31, 2016 05:40
by Byakuren
BrunoMine wrote:About method:

Code: Select all

minetest.setting_set("name", "value")
He did not keep the values set after a server shutdown.

What the correct way to remove an element HUD?

Code: Select all

waypoint = {
    hud_elem_type = "waypoint",
    name = "My pos",
    number = "0x000000",
    world_pos = {x=0,y=0,z=0}
}
player:hud_add(waypoint)
...
player:hud_remove(waypoint)
The above example does not remove the HUD of the waypoint.
Another question: how to know the id of an element of HUD?
The hud_add method returns an HUD id. So you can do

Code: Select all

local id = player:hud_add(hud_def)
...
player:hud_remove(id)

Re: Post your modding questions here

Posted: Sun Jan 31, 2016 19:43
by Merlin
How do I make a mob randomly drop something (while the mob is still alive), or rather, how do I make a chicken lay an egg?

Re: Post your modding questions here

Posted: Sun Jan 31, 2016 19:57
by TenPlus1
Merlin: check out Mobs Redo mod, especially the chicken.lua code.

https://github.com/tenplus1/mobs

Re: Post your modding questions here

Posted: Sun Jan 31, 2016 20:47
by Merlin
I don't quite get what this chunk of code does:

Code: Select all

hit_node = function(self, pos, node)

		local num = math.random(1, 10)
		if num == 1 then
			pos.y = pos.y + 1
			local nod = minetest.get_node_or_nil(pos)
			if not nod
			or not minetest.registered_nodes[nod.name]
			or minetest.registered_nodes[nod.name].walkable == true then
				return
			end
			local mob = minetest.add_entity(pos, "mobs:chicken")
			local ent2 = mob:get_luaentity()
			mob:set_properties({
				textures = ent2.child_texture[1],
				visual_size = {
					x = ent2.base_size.x / 2,
					y = ent2.base_size.y / 2
				},
				collisionbox = {
					ent2.base_colbox[1] / 2,
					ent2.base_colbox[2] / 2,
					ent2.base_colbox[3] / 2,
					ent2.base_colbox[4] / 2,
					ent2.base_colbox[5] / 2,
					ent2.base_colbox[6] / 2
				},
			})
			ent2.child = true
			ent2.tamed = true
			ent2.owner = self.playername
		end

Re: Post your modding questions here

Posted: Mon Feb 01, 2016 08:57
by TenPlus1
That piece of code is for throwing eggs, it picks a number from 1 to 10, if it's 1 then it checks the node above to see if it's free (air, grass etc) and spawns a chicken, then sets it's texture to that of a baby chick and halves it's size, sets it to child, sets tamed and owner name.

Congratulations: you have a the proud owner of a baby chicken :)

Re: Post your modding questions here

Posted: Mon Feb 01, 2016 09:44
by Merlin
Looking through what mobs redo already offers, I think I'm going to base my mod on mobs redo rather than on simple mobs.

Save settings permanently

Posted: Mon Feb 01, 2016 11:31
by BrunoMine
About method:

Code: Select all

minetest.setting_set("name", "value")
He did not keep the values set after a server shutdown.
We can save permanently?

Re: Post your modding questions here

Posted: Mon Feb 01, 2016 12:37
by TenPlus1
using /set -n <name> <value> does the same sadly, would be handy to have a -f in there to FORCE the setting and save to minetest.conf

Re: Post your modding questions here

Posted: Tue Feb 02, 2016 17:01
by Hybrid Dog
TenPlus1 wrote:using /set -n <name> <value> does the same sadly, would be handy to have a -f in there to FORCE the setting and save to minetest.conf
l'd prefer a minetest.save_settings().
lt shouldn't be called forcing because force is too vague…
A -sd (save directly) option could mean saving it directly after the setting was set.
If you use lubuntu (or similar) and want to disable access to your disk, hit alt+print(+s)+u. l don't know if minetest crashes then, l only know that it doesn't start.

Re: Post your modding questions here

Posted: Fri Feb 05, 2016 05:25
by Azmarok
Topic: How do I make decorations appear underground (ex. in caves)
Why: I'm making a mod that tries to encourage exploration. There is one item, called a rock, which is very important for making some items.
More info:
My current code for spawning the rock is:

Code: Select all

minetest.register_decoration({
    deco_type = "simple",
    decoration = "huntandgather:rock",
    place_on = {
        "default:stone",
    },
    y_min = -32000,
    y_max = 32000
})
My other section of code for spawning sticks on the ground works just fine, however:

Code: Select all

minetest.register_decoration({
    deco_type = "simple",
    decoration = "default:stick",
    place_on = {
        "default:dirt",
        "default:dirt_with_grass",
        "default:dirt_with_grass_footsteps",
        "default:dirt_with_dry_grass",
        "default:dirt_with_snow",
    },
    biomes = {
        "coniferous_forest",
        "deciduous_forest",
        "rainforest",
        "rainforest_swamp",
        "savanna",
        "taiga"
    }
})
(i overrote the default stick to make it a node)

Basically, when I go into a cave, there are no rocks to be seen, and I dont know why.

Re: Post your modding questions here

Posted: Fri Feb 05, 2016 20:42
by TenPlus1
Cave generation doesn't work like biome generation with decorations like grass, flowers and trees... you have to use on_generate to place decoration underground, like this:

Code: Select all

minetest.register_on_generated(function(minp, maxp)

	-- place stones between -30 and -3000
	if minp.y > -30 or maxp.y < -3000 then
		return
	end

	-- place them on top of coal blocks
	local coal = minetest.find_nodes_in_area_under_air(minp, maxp, "default:stone_with_coal")
	local bpos

	for n = 1, #coal do

		bpos = {x = coal[n].x, y = coal[n].y + 1, z = coal[n].z }

		-- not on all coal blocks, only 1 in every 8
		if math.random(1, 8) == 1 then
			minetest.set_node(bpos, {name = "yourmod:stone"})
		end
	end
end)