Compare commits
5 Commits
867cec6571
...
433eadf00a
Author | SHA1 | Date |
---|---|---|
|
433eadf00a | |
|
30e8cf4a12 | |
|
3ae9c9e963 | |
|
a2ae1e59b6 | |
|
1f8c30820d |
46
init.lua
46
init.lua
|
@ -1,16 +1,16 @@
|
||||||
-- NPC max walk speed
|
-- NPC max walk speed
|
||||||
walk_limit = 2
|
local walk_limit = 2
|
||||||
|
|
||||||
-- Player animation speed
|
-- Player animation speed
|
||||||
animation_speed = 30
|
local animation_speed = 30
|
||||||
|
|
||||||
-- Player animation blending
|
-- Player animation blending
|
||||||
-- Note: This is currently broken due to a bug in Irrlicht, leave at 0
|
-- Note: This is currently broken due to a bug in Irrlicht, leave at 0
|
||||||
animation_blend = 0
|
local animation_blend = 0
|
||||||
|
|
||||||
-- Default player appearance
|
-- Default player appearance
|
||||||
default_model = "character.x"
|
local default_model = "character.x"
|
||||||
available_npc_textures = {
|
local available_npc_textures = {
|
||||||
texture_1 = {"jordan4ibanez.png", },
|
texture_1 = {"jordan4ibanez.png", },
|
||||||
texture_2 = {"zombie.png", },
|
texture_2 = {"zombie.png", },
|
||||||
texture_3 = {"celeron55.png", },
|
texture_3 = {"celeron55.png", },
|
||||||
|
@ -19,7 +19,7 @@ available_npc_textures = {
|
||||||
|
|
||||||
|
|
||||||
-- Frame ranges for each player model
|
-- Frame ranges for each player model
|
||||||
function player_get_animations(model)
|
local function player_get_animations(model)
|
||||||
if model == "character.x" then
|
if model == "character.x" then
|
||||||
return {
|
return {
|
||||||
stand_START = 0,
|
stand_START = 0,
|
||||||
|
@ -51,19 +51,17 @@ local ANIM_MINE = 6
|
||||||
function player_update_visuals(self)
|
function player_update_visuals(self)
|
||||||
--local name = get_player_name()
|
--local name = get_player_name()
|
||||||
|
|
||||||
visual = default_model
|
|
||||||
player_anim = 0 -- Animation will be set further below immediately
|
player_anim = 0 -- Animation will be set further below immediately
|
||||||
--player_sneak[name] = false
|
--player_sneak[name] = false
|
||||||
prop = {
|
local prop = {
|
||||||
mesh = default_model,
|
mesh = default_model,
|
||||||
textures = default_textures,
|
|
||||||
textures = available_npc_textures["texture_"..math.random(1,4)],
|
textures = available_npc_textures["texture_"..math.random(1,4)],
|
||||||
visual_size = {x=1, y=1},
|
visual_size = {x=1, y=1},
|
||||||
}
|
}
|
||||||
self.object:set_properties(prop)
|
self.object:set_properties(prop)
|
||||||
end
|
end
|
||||||
|
|
||||||
NPC_ENTITY = {
|
local NPC_ENTITY = {
|
||||||
physical = true,
|
physical = true,
|
||||||
collisionbox = {-0.3,-1.0,-0.3, 0.3,0.8,0.3},
|
collisionbox = {-0.3,-1.0,-0.3, 0.3,0.8,0.3},
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
|
@ -84,7 +82,7 @@ NPC_ENTITY = {
|
||||||
|
|
||||||
NPC_ENTITY.on_activate = function(self)
|
NPC_ENTITY.on_activate = function(self)
|
||||||
player_update_visuals(self)
|
player_update_visuals(self)
|
||||||
self.anim = player_get_animations(visual)
|
self.anim = player_get_animations(default_model)
|
||||||
self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, animation_speed_mod, animation_blend)
|
self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, animation_speed_mod, animation_blend)
|
||||||
self.player_anim = ANIM_STAND
|
self.player_anim = ANIM_STAND
|
||||||
self.object:setacceleration({x=0,y=-10,z=0})
|
self.object:setacceleration({x=0,y=-10,z=0})
|
||||||
|
@ -94,7 +92,7 @@ end
|
||||||
NPC_ENTITY.on_punch = function(self, puncher)
|
NPC_ENTITY.on_punch = function(self, puncher)
|
||||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(self.object:getpos(), 5)) do
|
for _,object in ipairs(minetest.env:get_objects_inside_radius(self.object:getpos(), 5)) do
|
||||||
if not object:is_player() then
|
if not object:is_player() then
|
||||||
if object:get_luaentity().name == "npc:npc" then
|
if object:get_luaentity().name == "herobrine:npc" then
|
||||||
object:get_luaentity().state = 3
|
object:get_luaentity().state = 3
|
||||||
object:get_luaentity().attacker = puncher:get_player_name()
|
object:get_luaentity().attacker = puncher:get_player_name()
|
||||||
end
|
end
|
||||||
|
@ -125,7 +123,7 @@ NPC_ENTITY.on_step = function(self, dtime)
|
||||||
print(newz)
|
print(newz)
|
||||||
self.object:setacceleration({x=newx,y=self.object:getacceleration().y,z=newz})
|
self.object:setacceleration({x=newx,y=self.object:getacceleration().y,z=newz})
|
||||||
elseif not object:is_player() then
|
elseif not object:is_player() then
|
||||||
if object:get_luaentity().name == "npc:npc" then
|
if object:get_luaentity().name == "herobrine:npc" then
|
||||||
print("moo")
|
print("moo")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -150,8 +148,8 @@ NPC_ENTITY.on_step = function(self, dtime)
|
||||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(self.object:getpos(), 3)) do
|
for _,object in ipairs(minetest.env:get_objects_inside_radius(self.object:getpos(), 3)) do
|
||||||
if object:is_player() then
|
if object:is_player() then
|
||||||
self.yawwer = false
|
self.yawwer = false
|
||||||
NPC = self.object:getpos()
|
local NPC = self.object:getpos()
|
||||||
PLAYER = object:getpos()
|
local PLAYER = object:getpos()
|
||||||
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
|
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
|
||||||
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
|
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
|
||||||
if PLAYER.x > NPC.x then
|
if PLAYER.x > NPC.x then
|
||||||
|
@ -169,7 +167,7 @@ NPC_ENTITY.on_step = function(self, dtime)
|
||||||
end
|
end
|
||||||
self.object:setvelocity({x=0,y=self.object:getvelocity().y,z=0})
|
self.object:setvelocity({x=0,y=self.object:getvelocity().y,z=0})
|
||||||
if self.player_anim ~= ANIM_STAND then
|
if self.player_anim ~= ANIM_STAND then
|
||||||
self.anim = player_get_animations(visual)
|
self.anim = player_get_animations(default_model)
|
||||||
self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, animation_speed_mod, animation_blend)
|
self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, animation_speed_mod, animation_blend)
|
||||||
self.player_anim = ANIM_STAND
|
self.player_anim = ANIM_STAND
|
||||||
end
|
end
|
||||||
|
@ -188,7 +186,7 @@ NPC_ENTITY.on_step = function(self, dtime)
|
||||||
--self.object:setacceleration(self.direction)
|
--self.object:setacceleration(self.direction)
|
||||||
end
|
end
|
||||||
if self.player_anim ~= ANIM_WALK then
|
if self.player_anim ~= ANIM_WALK then
|
||||||
self.anim = player_get_animations(visual)
|
self.anim = player_get_animations(default_model)
|
||||||
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
|
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
|
||||||
self.player_anim = ANIM_WALK
|
self.player_anim = ANIM_WALK
|
||||||
end
|
end
|
||||||
|
@ -243,7 +241,7 @@ NPC_ENTITY.on_step = function(self, dtime)
|
||||||
if object:is_player() then
|
if object:is_player() then
|
||||||
if object:get_player_name() == self.attacker then
|
if object:get_player_name() == self.attacker then
|
||||||
if self.player_anim ~= ANIM_WALK then
|
if self.player_anim ~= ANIM_WALK then
|
||||||
self.anim = player_get_animations(visual)
|
self.anim = player_get_animations(default_model)
|
||||||
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
|
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
|
||||||
self.player_anim = ANIM_WALK
|
self.player_anim = ANIM_WALK
|
||||||
end
|
end
|
||||||
|
@ -295,7 +293,7 @@ NPC_ENTITY.on_step = function(self, dtime)
|
||||||
--WANDERING CONSTANTLY AT NIGHT
|
--WANDERING CONSTANTLY AT NIGHT
|
||||||
if self.state == 4 then
|
if self.state == 4 then
|
||||||
if self.player_anim ~= ANIM_WALK then
|
if self.player_anim ~= ANIM_WALK then
|
||||||
self.anim = player_get_animations(visual)
|
self.anim = player_get_animations(default_model)
|
||||||
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
|
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
|
||||||
self.player_anim = ANIM_WALK
|
self.player_anim = ANIM_WALK
|
||||||
end
|
end
|
||||||
|
@ -371,7 +369,7 @@ NPC_ENTITY.on_step = function(self, dtime)
|
||||||
self.direction = {x = math.sin(self.yaw)*-1, y = -10, z = math.cos(self.yaw)}
|
self.direction = {x = math.sin(self.yaw)*-1, y = -10, z = math.cos(self.yaw)}
|
||||||
end
|
end
|
||||||
if self.player_anim ~= ANIM_WALK then
|
if self.player_anim ~= ANIM_WALK then
|
||||||
self.anim = player_get_animations(visual)
|
self.anim = player_get_animations(default_model)
|
||||||
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
|
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
|
||||||
self.player_anim = ANIM_WALK
|
self.player_anim = ANIM_WALK
|
||||||
end
|
end
|
||||||
|
@ -404,9 +402,9 @@ NPC_ENTITY.on_step = function(self, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_entity("npc:npc", NPC_ENTITY)
|
minetest.register_entity("herobrine:npc", NPC_ENTITY)
|
||||||
|
|
||||||
minetest.register_node("npc:spawnegg", {
|
minetest.register_node("herobrine:spawnegg", {
|
||||||
description = "spawnegg",
|
description = "spawnegg",
|
||||||
image = "mobspawnegg.png",
|
image = "mobspawnegg.png",
|
||||||
inventory_image = "mobspawnegg.png",
|
inventory_image = "mobspawnegg.png",
|
||||||
|
@ -424,7 +422,7 @@ minetest.register_node("npc:spawnegg", {
|
||||||
on_place = function(itemstack, placer, pointed)
|
on_place = function(itemstack, placer, pointed)
|
||||||
pos = pointed.above
|
pos = pointed.above
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
minetest.env:add_entity(pointed.above,"npc:npc")
|
minetest.env:add_entity(pointed.above,"herobrine:npc")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
--[[
|
--[[
|
||||||
|
@ -484,5 +482,5 @@ npcs.spawning_mobs = {}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
npcs:register_spawn("npc:npc", {"default:dirt_with_grass"}, 16, -1, 500, 10, 31000)
|
npcs:register_spawn("herobrine:npc", {"default:dirt_with_grass"}, 16, -1, 500, 10, 31000)
|
||||||
]]--
|
]]--
|
||||||
|
|
Loading…
Reference in New Issue