[Mod] Mobs Redo [1.50] [mobs]

untiltoday
Member
 
Posts: 19
Joined: Wed Aug 07, 2019 22:50
In-game: ParalyzeEntertain

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

by untiltoday » Tue Nov 05, 2019 13:34

davidthecreator wrote:
untiltoday wrote:Is it possible to add the ability to make saddles from something else (like plastic or whatever they are made from), to get saddles without killing mobs? Previously mentioned by Sokomine for Petz.

Why not wool?


Then some wood or plastic for the tree, and wool, plastic or leather for the other big parts?
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

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

by Hamlet » Wed Nov 06, 2019 18:16

I've been trying to fix the issue with the mobiles being stuck against obstacles, but I haven't been able to apply the following solution; I don't know where to look in your API for the correct places where to add this code.
In other words I don't know where to put my hands, else I would have tried myself.

Thus I'm posting it here, hoping that it will be useful to improve Mobs Redo.

The solution's underlying idea is simple: if the given mob is not in the "stand" state, its velocity should be > than 0; if velocity == 0 then the mob is moonwalking against something.

If you have ever seen one of those old toys that when bump against a wall turn back, you've got the general idea. It is less than optimal - not Artificial Intelligence - but it works.

Of course this requires a timer which performs the check - I have used 5secs - to prevent letting the mobile moonwalking against a wall for more than e.g. 5secs.

If the check is not passed - state ~= "standing" AND velocity == 0 - then apply a random direction "try going somewhere else" AND lower the stuck-check-timer to an half: if the newly chosen direction is blocked, it will take 2.5secs to choose a different one, and so on.

If the check is passed, it's all right. If the timer's value was set to 2.5 then reset it to 5.0.


All of the following (pseudo)code is CC0, i.e. Public Domain

Main API routine on step:

-- Check whether if the mobile is stuck.
Code: Select all
TimerStuckCheck(self, dtime)



Movement management - If Action == "moving" AND Speed == 0 then Stuck == True

Code: Select all
-- Returns TRUE if stuck, FALSE if not.
CheckIfStuck = function(self)
   if (self.state == "moving")
   or (self.state == "attacking")
   or (self.state ~= "standing")
   or etc.
   or etc.
   then

      local velocity = self.object:get_velocity()

      if (velocity.x == 0)
      and (velocity.y == 0)
      and (velocity.z == 0)
      then
         --print("I am stuck.")
         return true

      else
         -- print("I am not stuck.")
         return false

      end
   end
end



Timer management - If timer == 0 then do check, etc.
Code: Select all
-- Used to check if mobiles are stuck.
TimerStuckCheck = function(self, dtime)
   if (self.counter_stuck_check <= 0) then
      local mobile_is_stuck = CheckIfStuck(self)

      if (mobile_is_stuck ~= nil)
      and (mobile_is_stuck ~= false)
      then
         ApplyRandomDirection() -- I.e. try moving somewhere else.
         self.counter_change_direction = 2.5
      end

      -- If the mob isn't stuck apply the default value.
      self.counter_stuck_check = 5.0

   else
      -- Let the countdown work
      self.counter_stuck_check = (self.counter_stuck_check - dtime)

   end
end


I hope this somewhat helps, I've spawned a dozen of dwarves in a cave and they all ended up moonwalking against the walls while being slain by Dungeon Masters' fireballs... lol.
 

User avatar
TenPlus1
Member
 
Posts: 2628
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

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

by TenPlus1 » Thu Nov 07, 2019 15:12

Hamlet - I've done something a little similar where if the mob is stuck against a wall, it will turn 90 degrees if it cannot jump up or move forward.

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

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

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

by Hamlet » Thu Nov 07, 2019 19:04

TenPlus1 wrote:Hamlet - I've done something a little similar where if the mob is stuck against a wall, it will turn 90 degrees if it cannot jump up or move forward.

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


I see, never mind then.
 

Ender3Guy
New member
 
Posts: 7
Joined: Fri May 31, 2019 21:32
GitHub: MisterPrintf

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

by Ender3Guy » Tue Nov 12, 2019 18:15

Can someone direct me to a wiki or tutorial for using Mobs redo? I've done a little magpen modding and I'd like to get into mobs if possible.
 

User avatar
TenPlus1
Member
 
Posts: 2628
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

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

by TenPlus1 » Tue Nov 12, 2019 21:04

Ender3Guy: the git page has the mods itself and the readme and api.txt files for usage: https://notabug.org/tenplus1/mobs_redo
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

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

by Hamlet » Fri Nov 15, 2019 14:52

Mobs ignore fear_height if walk_speed > than 1.

Steps to reproduce:
- Build a pile of dirt 5 nodes tall.
- Spawn a test mob on it.
test_mob.zip
(4.28 KiB) Not downloaded yet

The mob stays there until you add another node, then it jumps down even if fear_height = 3 (see code below).

Screenshots:
Image

Image

Test code used:
Code: Select all
--[[
   Test Mob - Registers a test mob.
   Licensed under the CC0, Version 1.0 or later.
   This sofware is distributed on an 'AS IS' basis,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   implied.

--]]


--
-- Mob entity
--

mobs:register_mob('test_mob:test', {
   nametag = 'Test Mob',
   type =    'npc',
   hp_min = 20,
   hp_max = 20,
   armor = 100,
   walk_velocity = 4,
   run_velocity = 4,
   stand_chance = 50,
   walk_chance = 50,
   jump = true,
   jump_height = 1.1,
   stepheight = 1.1,
   pushable = false,
   view_range = 14,
   damage = 1,
   knock_back = true,
   fear_height = 3,
   fall_damage = true,
   suffocation = true,
   floats = true,
   reach = 4,
   attack_monsters = true,
   group_attack = true,
   attack_type = 'dogfight',
   makes_footstep_sound = true,
   visual = 'mesh',
   visual_size = {x = 1, y = 1},
   collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
   selectionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
   textures = {'character.png'},
   mesh = 'character.b3d',
   animation = {
      stand_start = 0,
      stand_end = 79,
      stand_speed = 30,
      walk_start = 168,
      walk_end = 187,
      walk_speed = 30,
      run_start = 168,
      run_end = 187,
      run_speed = 30,
      punch_start = 189,
      punch_end = 198,
      punch_speed = 30,
      die_start = 162,
      die_end = 166,
      die_speed = 0.8
   }
})


--
-- Mobile spawner
--

mobs:spawn({
   name = 'test_mob:test',
   nodes = {
      'group:cracky',
      'group:stone',
      'group:crumbly',
      'group:sand',
      'group:snowy'
   },
   neighbors = {'air'},
   interval = 60,
   chance = 7500,
   active_object_count = 2,
   min_height = -30912,
   max_height = 31000
})


-- Spawn Egg

mobs:register_egg('test_mob:test', 'Test Mob', 'default_grass.png', 1)


--
-- Alias for '/spawnentity' command
--

mobs:alias_mob('mobs:test', 'test_mob:test')


--
-- Minetest engine debug logging
--

local log_level = minetest.settings:get('debug_log_level')

if (log_level == nil)
or (log_level == 'action')
or (log_level == 'info')
or (log_level == 'verbose')
then
   log_level = nil
   minetest.log('action', '[Mod] Test Mob [v0.1.0] loaded.')
end

Attachments
test2.png
(467.18 KiB) Not downloaded yet
test1.png
(533.17 KiB) Not downloaded yet
 

User avatar
TenPlus1
Member
 
Posts: 2628
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

Update:

by TenPlus1 » Sat Nov 16, 2019 08:23

The mob core works on a 1 second delay so by the time it walks to the end of the placed node it hasn't checked for fear height just yet... I'll look into this and reduce the delay :) Sadly server lag also affects these checks.

- Changed fear height check to every 1/4 second instead of 1 second, should help.
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Update:

by Hamlet » Sat Nov 16, 2019 17:59

TenPlus1 wrote:The mob core works on a 1 second delay so by the time it walks to the end of the placed node it hasn't checked for fear height just yet... I'll look into this and reduce the delay :) Sadly server lag also affects these checks.

- Changed fear height check to every 1/4 second instead of 1 second, should help.


I've just tested it: passed! :)
Only a couple of issues:
- the walking animation doesn't stop, making it looking weird.
- the mob sticks where it stopped, doesn't move elsewhere - since 40 minutes and counting.

While we are at it, it could be worth adding to the drop-check also lava/water checks if the mob has those flaws.
Keeping lag and memory saving in mind, it could be Off by default - to be toggled via Settings.
This way servers would not be affected, while Local Game players could easily turn it on.

Quick (pseudo)code examples (License: CC-0 v1.0 or later.)

Lava check
Code: Select all
-- Checks if the node is lava.
local b_LavaDangerCheck = function(pos)
   local s_NodeName = minetest.get_node(pos).name
   local b_DangerousNode = false
   local t_LavaNodes = {
      'default:lava_source',
      'default:lava_flowing'
   }

   for i = 1, 2 do
      if (b_DangerousNode == false) then
         if (s_NodeName == t_LavaNodes[i]) then
            b_DangerousNode == true
         end
      end
   end

   return b_DangerousNode
end


Water check
Code: Select all
-- Checks if the node is water.
local b_WaterDangerCheck = function(pos)
   local s_NodeName = minetest.get_node(pos).name
   local b_DangerousNode = false
   local t_WaterNodes = {
      'default:water_source',
      'default:water_flowing',
      'default:river_water_source',
      'default:river_water_flowing'
   }

   for i = 1, 4 do
      if (b_DangerousNode == false) then
         if (s_NodeName == t_WaterNodes[i]) then
            b_DangerousNode == true
         end
      end
   end

   return b_DangerousNode
end


Implementation
Code: Select all
local b_CheckForDangerousNodes =  minetest.settings:get_bool("mobs_dangerous_nodes_check")
local i_WaterDamage = self.water_damage -- Fetch the value just once, outside the cycle.
local i_LavaDamage = self.lava_damage

-- To be used when scanning the surrounding nodes.
if (b_CheckForDangerousNodes == true) then
   if (i_LavaDamage ~= nil) then
      if (b_LavaDangerCheck(pos) == true) then
         <function_that_stops_the_mob>
         <function_that_tries_another_direction>
      end
   end

   if (i_WaterDamage ~= nil) then
      if (b_WaterDangerCheck(pos) == true) then
         <function_that_stops_the_mob>
         <function_that_tries_another_direction>
      end
   end
end
 

User avatar
TenPlus1
Member
 
Posts: 2628
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

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

by TenPlus1 » Sun Nov 17, 2019 08:45

@Hamlet - The node that the mob is standing in is within the 1/4 second loop (self.standing_in) and the water/lava check is part of the walk cycle of checks and if found the mob usually turns around or if they fall in, escapes onto the closest land block.

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

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

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

by Hamlet » Sun Nov 17, 2019 19:14

TenPlus1 wrote:@Hamlet - The node that the mob is standing in is within the 1/4 second loop (self.standing_in) and the water/lava check is part of the walk cycle of checks and if found the mob usually turns around or if they fall in, escapes onto the closest land block.

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


Good to know, thank you.
 

Previous

Return to Mod Releases



Who is online

Users browsing this forum: No registered users and 4 guests