[Mod] Mobs Redo [1.61] [mobs]

User avatar
Walker
Member
Posts: 1838
Joined: Tue Oct 03, 2017 09:22
In-game: Walker
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by Walker » Post

aaand a new one -.-

Code: Select all

2020-07-20 17:39:36: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'mobs_monster' in callback luaentity_Step(): Invalid position (expected table got nil).
2020-07-20 17:39:36: ERROR[Main]: stack traceback:
2020-07-20 17:39:36: ERROR[Main]: 	[C]: in function 'find_node_near'
2020-07-20 17:39:36: ERROR[Main]: 	...a/sda3/Minetest/server3/.minetest/mods/mobs_redo/api.lua:2195: in function 'do_states'
2020-07-20 17:39:36: ERROR[Main]: 	...a/sda3/Minetest/server3/.minetest/mods/mobs_redo/api.lua:3444: in function <...a/sda3/Minetest/server3/.minetest/mods/mobs_redo/api.lua:3271>

User avatar
TenPlus1
Member
Posts: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by TenPlus1 » Post

@Walker - Your server seems to be having more issues than most, api updated but could you please list all of the mods you are using just incase something is affecting entities.

User avatar
thunderdog1138
Member
Posts: 68
Joined: Sun Dec 08, 2019 00:45
GitHub: thunderdog1138
In-game: thunderdog
Location: Venator-class Star Destroyer in the Xanadu System

Re: [Mod] Mobs Redo [1.52] [mobs]

by thunderdog1138 » Post

TenPlus1 wrote:
Mon Jul 20, 2020 06:35
api.txt updated, here is the mob definition for my npc's, they only attack when hit and will defend from monsters: https://notabug.org/TenPlus1/mobs_npc/s ... pc.lua#L11
It seems the passive function is not working. I tried it on 5.3.0 and 5.2.0 with the latest mobs_redo and mobs_npc versions. The NPC ran for me when I hit it but did not attack me.
My mistake, thanks for explaining the problem to me on the server.
Last edited by thunderdog1138 on Mon Jul 20, 2020 22:21, edited 1 time in total.
Check out my Star Wars subgame.

User avatar
TenPlus1
Member
Posts: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by TenPlus1 » Post

@thunderdog1138 - npc's work exactly as you want, wandering around and only attacking player once hit first, it does work.

User avatar
Walker
Member
Posts: 1838
Joined: Tue Oct 03, 2017 09:22
In-game: Walker
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by Walker » Post

TenPlus1 wrote:
Mon Jul 20, 2020 17:13
@Walker - Your server seems to be having more issues than most, api updated but could you please list all of the mods you are using just incase something is affecting entities.
Infos from my Forum-Thread:
> viewtopic.php?f=10&t=24204

Mods:
  • areas
  • gravelsieve
  • bonemeal
  • throwing
  • 3d_armor
  • shields
  • mtg_i18n
  • 3d_armor_stand
  • intllib
  • wieldview
  • invisible
  • invhack
  • unified_inventory
  • unified_inventory_plus
  • xban2
  • spawn_command
  • worldedit
  • worldedit_brush
  • worldedit_shortcommands
  • worldedit_commands
  • travelnet
  • 3d_armor_ui
  • 3d_armor_sfinv
  • 3d_armor_ip
  • markers
  • replacer
  • sokomine
  • xtraarmor
  • connected_chests
  • nyancat
  • awards
  • carpets
  • drawers
  • hudbars
  • hbhunger
  • hbarmor
  • mobs
  • mobs_npc
  • mob_horse
  • mobs_animal
  • mobs_monster
  • hbsprint
  • bows
  • mana
  • returnmirror
  • farming
  • smartshop
  • woodcutting
  • dirtcraft
  • protector
  • email
  • report
  • compost
  • coins
  • raz
  • admintools
  • external_cmd
  • advtrains
  • basic_materials
  • biome_lib
  • digilines
  • homedecor_modpack
  • laptop
  • laptop_pc1
  • laptop_pc2
  • lcd
  • mesecons
  • moreblocks
  • moreores
  • pipeworks
  • plantlife
  • technic
  • unifieddyes
  • xdecor
Walker wrote:
Wed Feb 12, 2020 12:41
Image
Adresse = ronnix.ddns.net
Port = 30003

A beautiful day,

this is a new server, which is designed to live out all needs ^^
"Creative" does not stand for the creative privilege but for the variety of mods (compared to my other servers, which are rather Vanilla)
A harmonic with each other is desired, you can fight against others on dedicated servers;)

All my Servers:

Code: Select all

  German-Carpathian-server  port:30000  // Vanilla-Minetest-Server with Carpathian-MapGen
  German-Ethereal-server    port:30001  // Vanilla-Minetest-Server with Carpathian-MapGen and Ethereal-Mod
  German-Vanilla-server     port:30002  // Vanilla-Minetest-Server
* German-Creative-server    port:30003  // Vanilla-Minetest-Server with Plantlife, Homedecor, X-Decor and other Mods
  German-MineClone2-server  port:30004  // MineClone2-Server for Minecraft-friends
All my IRC-Channels:
This server can be reached at #German-Creative-Server ... > IRC has been discontinued

About my:
Ronny Barthmann,
Programmer,
System Professional,
ATMEL controller hobbyists,
Open source activist (: D),
Anime (and anime music) fan,
Class and Co. student representative on the OSZimt.

About Servers:
Server: Minetest 5.3.0 > https://github.com/minetest/minetest/releases
Game: Minetest_game 5.3.0 > https://github.com/minetest/minetest_game/releases

Mods:
  • areas
  • gravelsieve
  • bonemeal
  • throwing
  • 3d_armor
  • shields
  • mtg_i18n
  • 3d_armor_stand
  • intllib
  • wieldview
  • invisible
  • invhack
  • unified_inventory
  • unified_inventory_plus
  • xban2
  • spawn_command
  • worldedit
  • worldedit_brush
  • worldedit_shortcommands
  • worldedit_commands
  • travelnet
  • 3d_armor_ui
  • 3d_armor_sfinv
  • 3d_armor_ip
  • markers
  • replacer
  • sokomine
  • xtraarmor
  • connected_chests
  • nyancat
  • awards
  • carpets
  • drawers
  • hudbars
  • hbhunger
  • hbarmor
  • mobs
  • mobs_npc
  • mob_horse
  • mobs_animal
  • mobs_monster
  • hbsprint
  • bows
  • mana
  • returnmirror
  • farming
  • smartshop
  • woodcutting
  • dirtcraft
  • protector
  • email
  • report
  • compost
  • coins
  • raz
  • admintools
  • external_cmd
  • advtrains
  • basic_materials
  • biome_lib
  • digilines
  • homedecor_modpack
  • laptop
  • laptop_pc1
  • laptop_pc2
  • lcd
  • mesecons
  • moreblocks
  • moreores
  • pipeworks
  • plantlife
  • technic
  • unifieddyes
  • xdecor
About the Accounts:
Walker: That´s me ... the termina ... ähh Administrator
Walker-mobile: That´s me ... at mobile phone
Walker-Console: That´s my again ... over the Terminal
stalker: That´s my Test-Account ... for testing and stuff ...
RONNIX: This is my let's play account for my recordings

My recordings are at > https://www.youtube.com/user/WinSysCompany/videos

moderators:
jjk1

ATTENTION: My name is Walker in IRC chat, but unfortunately there is no guarantee that I will ALWAYS be
Therefore: There is no guarantee that the "Walker" on IRC is me !!!/b]
therefore do not trust him BLIND !!!, only the Walker ON MY SERVER, I am always;)
( unless I was hacked ... whereby ... I use Linux ^^ )
> IRC has been discontinued

The minetest.conf from my Server

Code: Select all

world_start_time = 12000
time_speed = 0
max_users = 64
menu_last_game = MineClone2
enable_server = true
mainmenu_last_selected_world = 1
enable_damage = true
maintab_LAST = local
creative_mode = false
wieldview_node_tiles = false
wieldview_update_time = 2
name = Walker-Console
selected_world_path = /media/sda3/Minetest/server3/.minetest/worlds/Creative
enable_shaders = false
port = 30000
viewing_range = 200
noclip = true
fast_move = false
free_move = true
mg_name = v7
fixed_map_seed = 
world_config_selected_mod = 18
sound_volume = 0
mcl_imitation_mode = pc_edition
fsaa = 0
mip_map = false
bilinear_filter = false
leaves_style = fancy
trilinear_filter = false
node_highlighting = box
anisotropic_filter = false
server_announce = true
server_name = German-Creative-server
server_url = 
strict_protocol_version_checking = false
address = 192.168.0.4
screenH = 718
screenW = 1154
remote_port = 30003
active_block_range = 1
active_object_send_range_blocks = 2
server_map_save_interval = 15
disable_fire = true
enable_fire = false
default_privs = interact, shout, home
max_simultaneous_block_sends_per_client = 8
max_packets_per_iteration = 64
max_block_generate_distance = 32
max_block_send_distance = 32
max_forceloaded_blocks = 1
block_send_optimize_distance = 4
max_simultaneous_block_sends_server_total = 16
areas.self_protection = true
server_description = Deutscher MineTest-5.2.0-dev Server auf dem das akuelle Minetest (5.2.0-dev) Subgame läuft ; Walker = Administrator ; Walker-Console = Admin per Terminal ; Walker-mobile = Admin per Handy ; stalker = Testkonto vom Admin
motd = Deutscher MineTest-5.2.0-dev Server auf dem das akuelle Minetest (5.2.0-dev) Subgame mit vielen Mods läuft ; Walker = Administrator ; Walker-Console = Admin per Terminal ; Walker-mobile = Admin per Handy ; stalker = Testkonto vom Admin
static_spawnpoint = (0,13,0)
enable_rollback = true
enable_rollback_recording = true
debug_log_level = 2
give_initial_stuff = true
initial_stuff = default:pick_steel,default:axe_steel,default:torch 10,default:dirt 20,default:apple 20
share_bones_time = 30
share_bones_time_early = 30
enable_remote_media_server = true
remote_media = https://minetestmedia.foo-projects.org/
bones_mode = bones
deprecated_lua_api_handling = legacy
max_objects_per_block = 16384
secure.http_mods = monitoring
monitoring.prometheus_push_url = https://monitoring.minetest.land/push/metrics/job/minetest/instance/German-Creative-server
armor_fire_protect = false
player_model_version = default_character_v2
playeranim.model_version = MTG_4_Nov_2017
playeranim.body_rotation_delay = 1
secure.trusted_mods = irc
irc.server = irc.freenode.net
irc.channel = #German-Creative-server
irc.nick = Creative
irc.send_join_part = false
multihome.max = 1024
compost_duration_seconds = 10
compost_garden_soil = false
random_messages_interval = 300
debug_log_size_max = -1
unlimited_player_transfer_distance = false
player_transfer_distance = 16
server_address = ronnix.ddns.net

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [Mod] Mobs Redo [1.52] [mobs]

by MisterE » Post

Hi, I need help, and I am not asking for help without trying hard to solve this myself.

I am making a mod that adds bugs. I need the bugs to follow a set path. That means that each ant will have a list of positions which they should walk to in order, then return to the first position. I added self variables to the mob definition to hold the instruction table, so self.ant_instructions is a table of positions. self.ant_goal_number holds the index of the position on that list which is the current goal of the ant

I need a do_custom function that will check if the bug is at its goal, and if it isn't, use pathfinding to move there. (then, of course, it updates self.goal).

I saw where on the bottom of pg 80 of this topic you posted the code for a pathfinding do_custom function. I tried to use that method, but I kept getting errors because self:smart_mobs() uses self.attack to know where its going, and has multiple other references to attack. Since each ant is *not* attacking, these lines cause errors from within the api when called from do_custom.

So then I spent several hours pouring through the smart_mobs function, trying to understand it, and I copied it and several helper functions to my mod as a local function, and tried to edit it. I finally got it so it didn't throw any errors when it ran, but my ants were going every which way, not reaching their goals, not returning home, and I don't know what is wrong.

There should be a simple solution: I just have no idea what it is, and my code is getting more and more complicated, and I am spending more and more time trying to understand it and the changes I am making. HELP!

here is where I am atm:

Code: Select all


--SETTINGS---
local max_obj = 50 -- what is the maxium number of objects after which no more ants will spawn
local stuck_timeout = 1 -- how long before stuck mod starts searching
local stuck_path_timeout = 10 -- how long will mob follow path before giving up
local enable_pathfinding = true


-- functions --
local get_horizantal_dist_sq = function(pos1,pos2)
  local x1 = pos1.x
  local z1 = pos1.z
  local x2 = pos2.x
  local z2 = pos2.z
  return ((x2-x1)^2) + ((z2 - z1)^2)
end
---------------------------------------------------------Here lie copied codes--------------------------------------------------------
local get_distance = function(a, b)

	local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z

	return (x * x + y * y + z * z)*(x * x + y * y + z * z)
end



--##############################################################
-- turn mob to face position
local yaw_to_pos = function(self, target, rot)

	rot = rot or 0

	local pos = self.object:get_pos()
	local vec = {x = target.x - pos.x, z = target.z - pos.z}
	local yaw = (atan(vec.z / vec.x) + rot + pi / 2) - self.rotate

	if target.x > pos.x then
		yaw = yaw + pi
	end

	yaw = self:set_yaw(yaw, 6)

	return yaw
end


--############################################################

-- path finding and smart mob routine by rnd,
-- line_of_sight and other edits by Elkien3
-- edited to be a generic move_towards command by MisterE
function mob_pathfind_towards(self,s, p, dist, dtime)  -- self is the mob's self object. s is the pos of the mob, p is the pos of the target. dist is the distance between the two, and pass dtime from the custom function

	local s1 = self.path.lastpos -- this gets the last postion on the path for sticky situation detect
	local target_pos = p



	-- is it becoming stuck?
	if math.abs(s1.x - s.x) + math.abs(s1.z - s.z) < .5 then
		self.path.stuck_timer = self.path.stuck_timer + dtime
	else
		self.path.stuck_timer = 0
	end
  -- update last pos for next iter
	self.path.lastpos = {x = s.x, y = s.y, z = s.z}

	local use_pathfind = true  --in case we dont?
	local has_lineofsight = minetest.line_of_sight(
		{x = s.x, y = (s.y) + .5, z = s.z},
		{x = target_pos.x, y = (target_pos.y) + 1.5, z = target_pos.z}, .2)

	-- im stuck, search for path
  --if we dont have line of sight, and we used to, then turn on pathfinding
	if not has_lineofsight then -- if we don't have line of sight to target, then

		if self.los_switcher == true then
			use_pathfind = true
			self.los_switcher = false
		end -- cannot see target!
	else -- if has line_of_sight
		if self.los_switcher == false then

			self.los_switcher = true
			use_pathfind = false

			minetest.after(1, function(self) -- I think this can be translated to: after 1 sec, if the mob is still there,

				if self.object:get_luaentity() then

					if has_lineofsight then
						self.path.following = false
					end
				end
			end, self)
		end -- can see target!
	end

	if (self.path.stuck_timer > stuck_timeout and not self.path.following) then --if we are stuck for too long and we are not already following a path

		use_pathfind = true
		self.path.stuck_timer = 0

		minetest.after(1, function(self)

			if self.object:get_luaentity() then

				if has_lineofsight then
					self.path.following = false
				end
			end
		end, self)
	end

	if (self.path.stuck_timer > stuck_path_timeout and self.path.following) then

		use_pathfind = true -- to use pathfind means to try to get a path
		self.path.stuck_timer = 0

		minetest.after(1, function(self)

			if not self.object:get_luaentity() then
				return
			end

			if self.object:get_luaentity() then

				if has_lineofsight then
					self.path.following = false
				end
			end
		end, self)
	end

	if math.abs(vector.subtract(s,target_pos).y) > self.stepheight then

		if self.height_switcher then
			use_pathfind = true
			self.height_switcher = false
		end
	else
		if not self.height_switcher then
			use_pathfind = false
			height_switcher = true
		end
	end

	-- lets try find a path, first take care of positions
	-- since pathfinder is very sensitive
	if use_pathfind then

		-- round position to center of node to avoid stuck in walls
		-- also adjust height for player models!
		s.x = math.floor(s.x + 0.5)
		s.z = math.floor(s.z + 0.5)

		local ssight, sground = minetest.line_of_sight(s, {
			x = s.x, y = s.y - 4, z = s.z}, 1)

		-- determine node above ground
		if not ssight then
			s.y = sground.y + 1
		end

		local p1 = p

		p1.x = math.floor(p1.x + 0.5)
		p1.y = math.floor(p1.y + 0.5)
		p1.z = math.floor(p1.z + 0.5)

		local dropheight = 6

		if self.fear_height ~= 0 then dropheight = self.fear_height end

		local jumpheight = 0

		if self.jump and self.jump_height >= 4 then
			jumpheight = min(ceil(self.jump_height / 4), 4)

		elseif self.stepheight > 0.5 then
			jumpheight = 1
		end

		self.path.way = minetest.find_path(s, p1, 16, jumpheight,
				dropheight, "Dijkstra")

    --[[
		-- show path using particles
		if self.path.way and #self.path.way > 0 then
			print("-- path length:" .. tonumber(#self.path.way))
			for _,pos in pairs(self.path.way) do
				minetest.add_particle({
				pos = pos,
				velocity = {x=0, y=0, z=0},
				acceleration = {x=0, y=0, z=0},
				expirationtime = 1,
				size = 4,
				collisiondetection = false,
				vertical = false,
				texture = "heart.png",
				})
			end
		end
    --]]



		-- no path found, try something else
		if not self.path.way then

			self.path.following = false

      --try something else here

			-- will try again in 2 second
			self.path.stuck_timer = stuck_timeout - 2

	elseif s.y < p1.y and (not self.fly) then
			self:do_jump() --add jump to pathfinding
			self.path.following = true
		else
			-- yay i found path

			self:set_velocity(self.walk_velocity)

			-- follow path now that it has it
			self.path.following = true
		end
	end
end

--------------------------------------------------------here end copied codes --------------------------------------------------------

-- helper function for initializing worker ant destinations in connection with an ant nest
local find_destinations = function(pos) -- pos is that of the nest
  local instructions = {pos,} -- will need to return this, if it exists... the first pos in instructions is always the home node
  local facing = math.random(1,4) --choose one of 4 directions to start writing the path in
  local steps = math.random(5,7) --how many insturctions are we going to have past the first
  for i = 1, steps do --we will have 5 to 7 more locations after the first one
    --- the order here is: move dist in facing direction, log an instruction point, turn left or right and update facing
    local start_pos = instructions[i]

    local dist = math.random(3,10) -- choose random distance to travel to the next point
    local new_pos = {}
    --find the new pos based on dist and facing direction;   1= +x, 2 = +z, 3 = -x, 4= -z
    if facing == 1 then
      new_pos = {x=start_pos.x + dist, y=start_pos.y, z=start_pos.z}
    end
    if facing == 2 then
      new_pos = {x=start_pos.x, y=start_pos.y, z=start_pos.z + dist}
    end
    if facing == 3 then
      new_pos = {x=start_pos.x - dist, y=start_pos.y, z=start_pos.z}
    end
    if facing == 4 then
      new_pos = {x=start_pos.x, y=start_pos.y, z=start_pos.z - dist}
    end
    instructions[i+1] = new_pos -- add a new position to the instructions list

    -- choose a new direction, by turing left or right
    facing = facing + math.random(-1,1)
    if facing == 5 then
      facing = 1
    end
    if facing == 0 then
      facing = 4
    end
  end -- this finishes the for loop, and will make a list of positions that form a path.
  return instructions -- this returns the list of position instructions
end








mobs:register_mob("bugs_ant:ant_worker", {
	type = "animal",
	visual = "mesh",
  jump = false,
	visual_size = {x = 7, y = 7},
	mesh = "bugs_ant.b3d",
	collisionbox = {-0.07, -0.01, -0.07, 0.07, 0.07, 0.07},
	animation = {
		speed_normal = 1,
		speed_run = 1,
		stand_start = 1,
		stand_end = 10,
		walk_start = 20,
		walk_end = 24,
		run_start = 20,
		run_end = 24,
    jump_start = 28,
    jump_end = 32,
	},
	textures = {
		{"bugs_ant.png"},
	},
	fear_height = 3,
	runaway = false,
	fly = false,
	walk_chance = 99,
  stand_chance = 1,
  walk_velocity = 1,
  run_velocity = 1,
	view_range = 5,
	passive = true,
	hp_min = 1,
	hp_max = 2,
	armor = 200,
	lava_damage = 5,
	fall_damage = 0,
	water_damage = 2,
	makes_footstep_sound = false,
	drops = {},
	sounds = {},
  ant_instructions = {},
  ant_goal_number = nil,
  time_on_goal = 0,
  los_switcher = false,
  height_switcher = false,
  reach = .2,
  ant_debug = false,


  on_rightclick = function(self, clicker)
    self.ant_debug = true
  end,

  do_custom = function(self, dtime) -- this allows for the custom movement
    if self.ant_debug then
      if get_horizantal_dist_sq(self.object:get_pos(), self.ant_instructions[self.ant_goal_number]) < 1 then
        minetest.chat_send_all("your ant reached goal #"..dump(self.ant_goal_number))
      end
    end

    local time_on_goal = self.time_on_goal
    --minetest.chat_send_all(dump(dtime).. time_on_goal)
    local goal_timeout = 10 -- # of seconds the ant should take to try to get to the next goal. If it fails to reach it before that time, It will move on to the next goal or go home.

    local ant_instructions = nil -- if there aren't any instructions then it will use nil for the value
    if self.ant_instructions then -- what if there are
      ant_instructions = self.ant_instructions
      self.pathfinding = 1
    end

    if not ant_instructions then -- if the ant doesnt have any instructions, then use regular api for movement

      return true
    end

    if not self.ant_goal_number then -- if for some reason we dont have a goal, then set it to the home position
      self.ant_goal_number = 1
    end



    local goal_pos = ant_instructions[self.ant_goal_number] --where are we going?
    self.time_on_goal = time_on_goal + dtime -- keep track of how long we have been on the current goal

    --so now move towards our goal, if we can
    --###############################################################
  	-- set positions
  	local pos1 = self.object:get_pos() -- ant's current position
  	local pos2 = goal_pos

  	-- if no path set then setup mob
  	if not self.path or not self.path.way then
  		self.pathfinding = 1 -- just incase it's not set in mobdef
  	end

  	-- call pathfinding function to control player movement
  	if self.pathfinding then
  		local horiz_dist = get_horizantal_dist_sq(pos1, pos2) -- if we have not reached our goal yet then we will call the smart mobs func to move us towards the goal
  		if horiz_dist > 1 then
        local dist = get_distance(pos1, pos2)
  			mob_pathfind_towards(self,pos1, pos2, dist, dtime)
  		else --if we have reached our goal, then we need to get our next goal, and reset the goal timer
        self.ant_goal_number = self.ant_goal_number + 1
        self.time_on_goal = 0 -- reset the time
        if self.ant_goal_number > #self.ant_instructions then -- if we advance the goal number beyond the nuber of goals, go home
          self.ant_goal_number = 1
        end
   		end
  	end
    --#################################################################
    --ok we have moved, so now we need to double-check our goals. We need to recognize if we are stuck, because there are no paths to the goal. that will be determined by how long we have had the same goal.
    if self.time_on_goal > 10 then --if we have been trying to get to the same goal for more than 10 sec, move on to the next one and reset the goal timer. Hopefully it wont take more than 10 sec to reach the next goal
      self.ant_goal_number = self.ant_goal_number + 1
      self.time_on_goal = 0 -- reset the time
      if self.ant_goal_number > #self.ant_instructions then -- if we advance the goal number beyond the nuber of goals, go home
        self.ant_goal_number = 1
      end
    end

  end
})








minetest.register_node("bugs_ant:ant_nest",{
  description = "Ant Nest",
  tiles = {"default_dirt.png"},
  drawtype = "normal",
  groups = {crumbly=1},
  after_place_node = function(pos, placer, itemstack, pointed_thing)
    local destination_table = find_destinations(pos) -- gets the instruction list for the ants to follow.
    --debug
    minetest.chat_send_all(dump(destination_table))
    local timer = minetest.get_node_timer(pos) --start a timer to make the node keep producing ants
    timer:start(1)
    if destination_table then -- just to make sure
    --place the destination table in the node's meta here. After this, the destination table is stored in metadata as a string. Use something like data = minetest.deserialize(minetest:get_string("foo")) to de-strigify it.
      local meta = minetest.get_meta(pos)
      meta:set_string("instruction", minetest.serialize(destination_table))
      -- show goals using add_particlespawner
      for posi in ipairs(destination_table) do
        minetest.add_particle({
        pos = posi,
        velocity = {x=0, y=0, z=0},
        acceleration = {x=0, y=0, z=0},
        expirationtime = 4000,
        size = 4,
        collisiondetection = false,
        vertical = false,
        texture = "heart.png",
        })
      end


    end
  end,
  on_timer = function(pos)

    local timer = minetest.get_node_timer(pos)
    local meta = minetest.get_meta(pos)
    local next_timer = 1 -- how long until this function runs again, init at 1

    local objs = minetest.get_objects_inside_radius(pos, 30) --checking for ants and other objs within 30 nodes
    if #objs < max_obj then -- only spawn more ants if the max objects in the area is low enough
      local worker_ant_obj = minetest.add_entity(pos, "bugs_ant:ant_worker", nil) --spawn a worker ant, and, below, try to give it instructions. This returns the object
      local worker_ant_ent = worker_ant_obj:get_luaentity() -- this gets the entity from the object
      local destination_table = minetest.deserialize(meta:get_string("instruction")) --retrieve the destination table from the metadata
      if destination_table then -- just to make sure it exists and not cause crashes
        worker_ant_ent.ant_instructions = destination_table --give this ant instructions
        worker_ant_ent.ant_goal_number = 2 -- set the goal for the second position in the instruction list (the fisrt is the home position)
        worker_ant_ent.time_on_goal = 0 --init goal timer
      end
    end
    timer:start(next_timer) -- restart the timer
  end,

})


I am probably doing this all wrong... maybe I can use smart_mobs after all.

My goals are simple, the coding not so much:
1) the ant nest makes a list of instructions when it is placed. The list contains positions that are near each other and can be reached by walking in straight lines. Either: Only the x and z values matter, or the position has to be on the surface.

2) when a worker ant is spawned from its nest, the node timer function that spawns it sets the variables such as self.ant_instructions, self.ant_goal_number, etc so that all ants from the same nest have the same instructions

3) the do custom function behaves as follows:
a) if there are no instructions, release control of the mob back to the api (return true)
b) if the ant has reached its goal, increment to goal index value, or if the current goal index value is the same as the length of the instruction list, then set the goal to #1 (which is the location of the nest)
c) move the ant towards its goal. Use pathfinding. Also, keep track of how long the ant has been trying to get to its goal, and if it exceeds a certain time , change the goal to the next one on the list or home, so that if the goal is unreachable, it will be skipped.


----
hopefully this will make ants march mostly in a line, taking a path that zigzags, mostly staying together, and then returning home, where they then start it up again. Another possibility is to kill them when they get home, and let the nest spawn more, possibly with different instructions. (that would be better)

anyhow, I have tried to make this work, and have gotten pretty stuck. I would really appreciate some help, ppl who help me will be mentioned on the readme. I am intending to release this under the MIT license, because much of the code is copied from mobs.

extra info: An instruction list is made by choosing a cardinal direction, and traveling a short distance in that direction from the nest. make a waypoint. Then turn left or right, and travel another short distance. Place another waypoint in the list. Repeat several times.


I think I need a function like:

mob.goto(pos,range)

that moves the mob towards the pos and returns true when it is within "range" of "pos", and false if it isn't yet.

User avatar
TenPlus1
Member
Posts: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by TenPlus1 » Post

@MisterE - I've updated the mob api so it wont freak out when calling smart_mobs function when self.attack isn't there, it'll use the positions provided...

What I will have to do though is separate the smart_mobs movement code from inside the attack section of the api and either make a new function or have it called when the mob is in motion either from walking or attacking, this will make set paths work properly :)

https://notabug.org/TenPlus1/mobs_redo/ ... .lua#L2491

Sokomine
Member
Posts: 4290
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: [Mod] Mobs Redo [1.52] [mobs]

by Sokomine » Post

@MisterE: I'm not entirely certain if a mobs mod is the right solution for what you aim for. After all ants are pretty tiny insects. And it sounds as if you want many of them.

How about adding "road" nodes instead of real mobs? Such a road node could be a tiny overlay that's put on the ground and has some carefully designed animation that make it look like as if it's an ant road with high traffic. The individual ant is almost invisible, but the road as a whole can be seen. It could even lead "up" the actual anthill (if meshes can now have animated textures?). The other end would be in a food source for the ants (also placed by your mod). The road would be static but could react to players digging or placing nodes where the road is - leading to a recalculation of the road with the changed surface. "Attacking" the nest by trying to dig it could still spawn huge mutated or symbolic guard ants that protect their nest.
A list of my mods can be found here.

User avatar
TenPlus1
Member
Posts: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by TenPlus1 » Post

@Sokomine - connected nodes like glass or rails that animate moving ants around it :) nice idea

Bastrabun
Member
Posts: 212
Joined: Mon Nov 04, 2019 19:48

Re: [Mod] Mobs Redo [1.52] [mobs]

by Bastrabun » Post

Is there a simple method of changing things like spawns and drops from the outside?

Use case is that I usually update early and often. If I wanted to change the drops and spawns on every mobs_redo mob I'd everytime need to change files on the freshly downloaded mob. I'd like to keep the mods as default as possible and rather make a mod that changes those values from outside.
Whatever I say is CC0

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [Mod] Mobs Redo [1.52] [mobs]

by MisterE » Post

@ Tenplus1...

Thank you for updating the api, I will try it out soon. (maybe tomorow, maybe not for the next week... I am going to be busy IRL.) With the updates, I assume I can use the smart_mobs api as indicated two pages back?

@ Sokomine That is definitely something to consider... However, I am still leaning towards using mobs, because I want the player to be able to squish individual ants, and besides, I will spawn only as many ants at a time as the server owner wants, based on the get_objects_in_area function. Its ok for there to be few ants, as (if the code works) the ants will walk their path and then return home. Also, if each ant has a state that can be altered that allows it to attack player, nest defense can me more instantaneous.

Your idea does have the pro that there would be a lot fewer entities, reducing lag, and that the line of ants would look more realistic (mobs just hop up a node jump instantly). It has the con that ants can't get lost or captured, etc.

I want there to be honey ants that you can catch and eat, and I want there to be fire ants that just attack, if you get within half a node.

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [Mod] Mobs Redo [1.52] [mobs]

by MisterE » Post

ok, so I started work on the ants again...

I have:

Code: Select all

  	-- set positions
  	local pos1 = self.object:get_pos() -- ant's current position
  	local pos2 = goal_pos

  	-- if no path set then setup mob
  	if not self.path or not self.path.way then
  		self.pathfinding = 1 -- just incase it's not set in mobdef
  	end

  	-- call pathfinding function to control player movement
  	if self.pathfinding then
  		local horiz_dist = get_horizantal_dist_sq(pos1, pos2) -- if we have not reached our goal yet then we will call the smart mobs func to move us towards the goal
  		if horiz_dist > 1 then
        local dist = get_distance(pos1, pos2)
  			self.smart_mobs(pos1, pos2, dist, dtime)
  		else --if we have reached our goal, then we need to get our next goal, and reset the goal timer
        self.ant_goal_number = self.ant_goal_number + 1
        self.time_on_goal = 0 -- reset the time
        if self.ant_goal_number > #self.ant_instructions then -- if we advance the goal number beyond the nuber of goals, go home
          self.ant_goal_number = 1
        end
   		end
  	end

So that gives this error:

Code: Select all


2020-07-30 14:33:00: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'bugs_ant' in callback luaentity_Step(): ...etest\minetest-5.3.0-win64\bin\..\mods\mobs_redo/api.lua:1545: attempt to index field 'path' (a nil value)
2020-07-30 14:33:00: ERROR[Main]: stack traceback:
2020-07-30 14:33:00: ERROR[Main]: 	...etest\minetest-5.3.0-win64\bin\..\mods\mobs_redo/api.lua:1545: in function 'smart_mobs'
2020-07-30 14:33:00: ERROR[Main]: 	...etest\minetest-5.3.0-win64\bin\..\mods\bugs_ant\init.lua:193: in function 'do_custom'
2020-07-30 14:33:00: ERROR[Main]: 	...etest\minetest-5.3.0-win64\bin\..\mods\mobs_redo/api.lua:3367: in function <...etest\minetest-5.3.0-win64\bin\..\mods\mobs_redo/api.lua:3242>
2020-07-30 14:33:01: ACTION[Main]: Server: Shutting down
Do you know whats going wrong? It seems to be something in the api?

*edit*
It seems that the smart_mobs function assumes that self.path exists (line 1545). If it doesnt, it crashes. How do I set up the self.path? That was not in the pathfinding example code 2 pages back

*I tried setting up self.path in my code before calling smart_mobs, and then ran into a whole sequence of errors from the smart_mobs function in the api. I tried fixing the check for self.path in the smart_mobs, but I can't figure it out.

*Also, I noticed that there is still a reference to attack within the smart_mobs function (in your current github version), and the velocity will not be set unless self.attack is true. So, the problem is still not fixed.

It my opinion that smart_mobs won't work for custom functions without a lot of work. Perhaps a new function should be made and included. I may work on it myself, but Im not a great programmer (yet), so if you can help, that would be great.

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [Mod] Mobs Redo [1.52] [mobs]

by MisterE » Post

So I made some headway... But would appreciate some help still.

I mostly copied the smart_mobs function over to a function that is for my bugs mod (its in bugs_functions.lua), but
I got it so that all undeclared global errors were addressed, and all attack references were removed and patched. and It seems to run without crashing.
Now, I call bugs:mob_move_toward(self,pos,dtime) instead of self.smart_mobs, and so far it doesnt crash. (that doesnt mean it wont though.

However, the ants are not going where they are supposed to still, thats likely a problem with MY code in init, but Im not sure. I would appreciate some help with this if anyone has time.

Here's the code:
https://github.com/MisterE123/bugs-unfinished

thanks

Sokomine
Member
Posts: 4290
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: [Mod] Mobs Redo [1.52] [mobs]

by Sokomine » Post

MisterE wrote: I want there to be honey ants that you can catch and eat, and I want there to be fire ants that just attack, if you get within half a node.
You could still do that with non-entity-ants. "Digging" an ant path with the right tool could give you the ant - or call a huge defender into action :-)

Even though I don't like mobs stealing from players in general, ants might be able to sneak into even locked chests. From time to time, your prescious bread might then be seen wandering down the side of your locked chest, along the ant path and up the anthill...could be some challenge to keep them out :-)

Pathfinding is just relatively expensive...and ants aren't really lone individuals...
A list of my mods can be found here.

User avatar
TenPlus1
Member
Posts: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by TenPlus1 » Post

@MisterE - So much has been going on right now and I haven't had time to look at the pathfinding function within the API, will tinker soon and see what can be done for your ants.

Merak
Member
Posts: 116
Joined: Sat Nov 05, 2016 20:34

[mobs] Elimination

by Merak » Post

Could the framework be made to remove any mobs objects which are no longer defined?

If not, it would be good practice for module makers to let you disable spawning of the mob but let it continue to exist or to remove instances of the mob.

User avatar
TenPlus1
Member
Posts: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by TenPlus1 » Post

@Merak - Please explain a use case for this feature ?

Merak
Member
Posts: 116
Joined: Sat Nov 05, 2016 20:34

Re: [Mod] Mobs Redo [1.52] [mobs]

by Merak » Post

Current situation, a user:
Installs a mod which spawns mobs.
Decides he no longer wants the mobs and configures the mod not to spawn them or uninstalls the mod.
The player sees warnings about unknown mobs.

Future situation. A user:
Installs a mod which spawns mobs.
Decides he no longer wants the mobs and uninstalls the mod.
When the player encounters an already spawned mob which is no longer defined, Mobs Redo deletes it.

User avatar
sorcerykid
Member
Posts: 1847
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: [Mod] Mobs Redo [1.52] [mobs]

by sorcerykid » Post

When the player encounters an already spawned mob which is no longer defined, Mobs Redo deletes it.
I think that is highly impractical, since the engine does not report to mods when entities are unregistered. I actually developed a command-line Lua script as part of my Rocketlib Toolkit that searches the map database for unknown entities, and then removes them from the world in-batch once the server is brought online.

User avatar
Festus1965
Member
Posts: 4181
Joined: Sun Jan 03, 2016 11:58
GitHub: Festus1965
In-game: Festus1965 Thomas Thailand Explorer
Location: Thailand ChiangMai
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by Festus1965 » Post

Merak wrote:
Tue Aug 11, 2020 17:07
Decides he no longer wants the mobs and uninstalls the mod.
This is possible, when every time at a shutdown the mobs are deleted also.

Or using minetest-remover to detect them also and delete, like i use for unknown nodes, where I know what they have been (vines, roots) and automatic during recognize ...
Human has no future (climate change)
If urgend, you find me in Roblox (as CNXThomas)

Merak
Member
Posts: 116
Joined: Sat Nov 05, 2016 20:34

Re: [Mod] Mobs Redo [1.52] [mobs]

by Merak » Post

Deleting mobs at shut-down would achieve the same effect. It sounds good to me.

User avatar
TenPlus1
Member
Posts: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by TenPlus1 » Post

The mobs:alias_mob(old_mob_name, new_mob_name) could be used in that case, and any instance of the old mob would be switched to use the new.

Merak
Member
Posts: 116
Joined: Sat Nov 05, 2016 20:34

Re: [Mod] Mobs Redo [1.52] [mobs]

by Merak » Post

If that was addressed to me, @TenPlus1 , I think that you misunderstood me. I have only been interested with enabling or disabling mobs or spawning of mobs -- not different versions and changes of name.

User avatar
TenPlus1
Member
Posts: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Mobs Redo [1.52] [mobs]

by TenPlus1 » Post

@Merak - If you remove a mob from a server it will show unknown objects around the map, using mobs:alias_mob() can take these objects and switch it from one entity to another so the unknown objects do not appear, e.g. say you disabled cows:

mobs:alias_mob("mobs_animal:cow", "mobs_animal:sheep") -- turn unknowns into sheep instead

User avatar
freshreplicant
Member
Posts: 228
Joined: Sun Aug 09, 2020 10:37
In-game: freshreplicant

Re: [Mod] Mobs Redo [1.52] [mobs]

by freshreplicant » Post

Hi TenPlus1, just wondering if you might consider adding a damage sound to your mobs (such as those in mobs_animals) by default. I note that mobs_redo offers this feature, but it doesn't seem to be implemented.

As an experiment I changed the chicken mob as such:

Code: Select all

makes_footstep_sound = true,
        sounds = {
                random = "mobs_chicken",
                damage = "mobs_chicken",
And I found that it gives a lot more feedback when interacting (read: slaughtering) the mob. Otherwise it just has the default punch sound effect and the mob doesn't seem to notice it's being attacked. Feels very wooden and un-immersive.

For some mobs you could make it more specific, like with the warthog:

Code: Select all

makes_footstep_sound = true,
        sounds = {
                random = "mobs_pig",
                attack = "mobs_pig_angry",
                damage = "mobs_pig_angry",
This doesn't necessitate extra sound effects, as for most mobs even just the default sound they make normally make also works for the damage sound.

If there are concerns for people who want to farm these mobs in bulk, and thus don't want all the squawking, then maybe it could be toggled off in settings. Just my suggestion.

On a slightly related note, I noted the -- weapon sounds section in api.lua of the mobs mod. I was trying to figure out how weapon sounds could be defined, so for example, that when you attack via sword, it makes a 'swish' sound rather than the default 'punch' sound? This may be out of scope of the api, of course but I thought I would ask.

Post Reply

Who is online

Users browsing this forum: No registered users and 78 guests