From 8df420796abc08b70da923f4949c39d48d22fe1c Mon Sep 17 00:00:00 2001 From: Looki2000 Date: Mon, 30 Jan 2023 16:53:03 +0100 Subject: [PATCH] now sussy mini crewmates can be hit and they run away. --- .../entities/mini_crewmate_entity.lua | 25 ++++++++++++++++++- mods/player_api/init.lua | 9 +++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/mods/amogus_entities/entities/mini_crewmate_entity.lua b/mods/amogus_entities/entities/mini_crewmate_entity.lua index 2de3905..890215b 100644 --- a/mods/amogus_entities/entities/mini_crewmate_entity.lua +++ b/mods/amogus_entities/entities/mini_crewmate_entity.lua @@ -1,3 +1,4 @@ + local entity = { physical = true, collisionbox = {-0.25, 0, -0.25, 0.25, 0.5, 0.25}, @@ -38,6 +39,8 @@ local entity = { smallest_distance_to_lost_player = 10, -- smallest distance to lost player largest_distance_to_stand_still = 3, -- largest distance to stand still next to the player + + smallest_distance_to_stop_run_away = 30, -- smallest distance to stop run away from player -------------------------- block_lastly_in_front = false, @@ -55,6 +58,10 @@ local entity = { self.rotation_direction = math.random(-1, 1) end, + on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir) + self.mode = 3 + end, + on_step = function(self, dtime) -- play amogus sound randomly with different pitch depending on situation @@ -106,7 +113,6 @@ local entity = { -- I will write it later. --end - -- if mode is 0 or 1 (stand still or walk) and distance is smaller or equal to largest_distance_to_find_player, set mode to 2 (chase) if (self.mode == 0 or self.mode == 1) and distance <= self.largest_distance_to_find_player then @@ -123,8 +129,25 @@ local entity = { -- if mode is 4 (rest mode) and distance is greater than largest_distance_to_stand_still, set mode to 2 (chase) elseif self.mode == 4 and distance > self.largest_distance_to_stand_still then self.mode = 2 + -- running away mode + elseif self.mode == 3 then + -- if distance is greater than smallest_distance_to_lost_player, set mode to 0 (stand still) + if distance > self.smallest_distance_to_stop_run_away then + self.mode = 1 + else + -- jump if on ground + local pos = self.object:get_pos() + pos.y = pos.y - 0.2 + local bnode = minetest.get_node(pos) + if bnode.name ~= "air" then + local vel = self.object:get_velocity() + vel.y = vel.y + self.jump_force + self.object:set_velocity(vel) + end + end end + -- if if not performing an action related to the player if (self.mode == 0 or self.mode == 1) then diff --git a/mods/player_api/init.lua b/mods/player_api/init.lua index 550864e..99e3135 100644 --- a/mods/player_api/init.lua +++ b/mods/player_api/init.lua @@ -1,5 +1,6 @@ dofile(minetest.get_modpath("player_api") .. "/api.lua") + -- Default player appearance player_api.register_model("amogus_entity.obj", { animation_speed = 30, @@ -15,13 +16,11 @@ player_api.register_model("amogus_entity.obj", { sit = {x = 81, y = 160, eye_height = 0.8, override_local = true, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.0, 0.3}} }, - --collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, stepheight = 0.6, - eye_height = 1.47,collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, - - --visual = "mesh", + eye_height = 1.47, + + collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, - rotation = 0, visual = "mesh", visual_size = {x=10, y=10, z=10},