parent
c5e2f9b2cb
commit
2255cdd34b
133
api.lua
133
api.lua
@ -47,7 +47,7 @@ local function force_detach(player)
|
|||||||
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
||||||
end
|
end
|
||||||
|
|
||||||
function object_attach(entity, player, attach_at, eye_offset)
|
function mobs_doomed.object_attach(entity, player, attach_at, eye_offset)
|
||||||
eye_offset = eye_offset or {x=0, y=0, z=0}
|
eye_offset = eye_offset or {x=0, y=0, z=0}
|
||||||
force_detach(player)
|
force_detach(player)
|
||||||
entity.driver = player
|
entity.driver = player
|
||||||
@ -64,7 +64,7 @@ function object_attach(entity, player, attach_at, eye_offset)
|
|||||||
entity.object:set_yaw(player:get_look_horizontal() - (math.pi/2))
|
entity.object:set_yaw(player:get_look_horizontal() - (math.pi/2))
|
||||||
end
|
end
|
||||||
|
|
||||||
function object_detach(entity, player, offset)
|
function mobs_doomed.object_detach(entity, player, offset)
|
||||||
entity.driver = nil
|
entity.driver = nil
|
||||||
player:set_detach()
|
player:set_detach()
|
||||||
default.player_attached[player:get_player_name()] = false
|
default.player_attached[player:get_player_name()] = false
|
||||||
@ -110,7 +110,7 @@ end)
|
|||||||
--mixed code(from this mod and lib_mount)
|
--mixed code(from this mod and lib_mount)
|
||||||
local rotview = math.pi / 2
|
local rotview = math.pi / 2
|
||||||
|
|
||||||
function object_drive(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim, jumps)
|
function mobs_doomed.object_drive(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim, jumps)
|
||||||
local ctrl = entity.driver:get_player_control()
|
local ctrl = entity.driver:get_player_control()
|
||||||
local dir = entity.driver:get_look_dir();
|
local dir = entity.driver:get_look_dir();
|
||||||
local vec_forward = {x=dir.x*speed,y=-2,z=dir.z*speed}
|
local vec_forward = {x=dir.x*speed,y=-2,z=dir.z*speed}
|
||||||
@ -162,7 +162,7 @@ function object_drive(entity, dtime, speed, shoots, arrow, moving_anim, stand_an
|
|||||||
-- end
|
-- end
|
||||||
end
|
end
|
||||||
|
|
||||||
function object_fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
|
function mobs_doomed.object_fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
|
||||||
|
|
||||||
if entity and not entity.driver:get_look_dir() then return end
|
if entity and not entity.driver:get_look_dir() then return end
|
||||||
|
|
||||||
@ -249,128 +249,3 @@ local function get_v(v)
|
|||||||
return math.sqrt(v.x ^ 2 + v.z ^ 2)
|
return math.sqrt(v.x ^ 2 + v.z ^ 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
lib_mount = {}
|
|
||||||
|
|
||||||
function lib_mount.attach(entity, player, attach_at, eye_offset)
|
|
||||||
eye_offset = eye_offset or {x=0, y=0, z=0}
|
|
||||||
force_detach(player)
|
|
||||||
entity.driver = player
|
|
||||||
player:set_attach(entity.object, "", attach_at, {x=0, y=0, z=0})
|
|
||||||
|
|
||||||
player:set_properties({visual_size = {x=1, y=1}})
|
|
||||||
|
|
||||||
player:set_eye_offset(eye_offset, {x=0, y=0, z=0})
|
|
||||||
default.player_attached[player:get_player_name()] = true
|
|
||||||
minetest.after(0.2, function()
|
|
||||||
default.player_set_animation(player, "sit" , 30)
|
|
||||||
end)
|
|
||||||
entity.object:set_look_horizontal(player:get_look_horizontal() - (math.pi/2))
|
|
||||||
end
|
|
||||||
|
|
||||||
function lib_mount.detach(entity, player, offset)
|
|
||||||
if entity ~= nil then entity.driver = nil end
|
|
||||||
player:set_detach()
|
|
||||||
default.player_attached[player:get_player_name()] = false
|
|
||||||
default.player_set_animation(player, "stand" , 30)
|
|
||||||
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
|
||||||
local pos = player:get_pos()
|
|
||||||
pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
|
|
||||||
minetest.after(0.1, function()
|
|
||||||
player:set_pos(pos)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function lib_mount.drive(entity, dtime, moving_anim, stand_anim, can_fly)
|
|
||||||
entity.v = get_v(entity.object:get_velocity()) * get_sign(entity.v)
|
|
||||||
|
|
||||||
local ctrl = entity.driver:get_player_control()
|
|
||||||
local yaw = entity.object:get_yaw()
|
|
||||||
if ctrl.up then
|
|
||||||
entity.v = entity.v + 0.1
|
|
||||||
elseif ctrl.down then
|
|
||||||
entity.v = entity.v - 0.1
|
|
||||||
end
|
|
||||||
if ctrl.left then
|
|
||||||
if entity.v < 0 then
|
|
||||||
entity.object:set_yaw(yaw - (1 + dtime) * 0.03)
|
|
||||||
else
|
|
||||||
entity.object:set_yaw(yaw + (1 + dtime) * 0.03)
|
|
||||||
end
|
|
||||||
elseif ctrl.right then
|
|
||||||
if entity.v < 0 then
|
|
||||||
entity.object:set_yaw(yaw + (1 + dtime) * 0.03)
|
|
||||||
else
|
|
||||||
entity.object:set_yaw(yaw - (1 + dtime) * 0.03)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local velo = entity.object:get_velocity()
|
|
||||||
if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
|
||||||
if stand_anim and stand_anim ~= nil and mobs_redo == true then
|
|
||||||
mobs:set_animation(entity, stand_anim)
|
|
||||||
end
|
|
||||||
entity.object:set_pos(entity.object:get_pos())
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if moving_anim and moving_anim ~= nil and mobs_redo == true then
|
|
||||||
mobs:set_animation(entity, moving_anim)
|
|
||||||
end
|
|
||||||
local s = get_sign(entity.v)
|
|
||||||
entity.v = entity.v - 0.02 * s
|
|
||||||
if s ~= get_sign(entity.v) then
|
|
||||||
entity.object:set_velocity({x = 0, y = 0, z = 0})
|
|
||||||
entity.v = 0
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if math.abs(entity.v) > 5 then
|
|
||||||
entity.v = 5 * get_sign(entity.v)
|
|
||||||
end
|
|
||||||
|
|
||||||
local p = entity.object:get_pos()
|
|
||||||
p.y = p.y - 0.5
|
|
||||||
local new_velo = {x = 0, y = 0, z = 0}
|
|
||||||
local new_acce = {x = 0, y = 0, z = 0}
|
|
||||||
if not is_group(p, "crumbly") then
|
|
||||||
local nodedef = minetest.registered_nodes[minetest.get_node(p).name]
|
|
||||||
if (not nodedef) or nodedef.walkable then
|
|
||||||
entity.v = 0
|
|
||||||
new_acce = {x = 0, y = 1, z = 0}
|
|
||||||
else
|
|
||||||
new_acce = {x = 0, y = -9.8, z = 0}
|
|
||||||
end
|
|
||||||
new_velo = get_velocity(entity.v, entity.object:get_yaw(),
|
|
||||||
entity.object:get_velocity().y)
|
|
||||||
entity.object:set_pos(entity.object:get_pos())
|
|
||||||
else
|
|
||||||
p.y = p.y + 1
|
|
||||||
if is_group(p, "crumbly") then
|
|
||||||
local y = entity.object:get_velocity().y
|
|
||||||
if y >= 5 then
|
|
||||||
y = 5
|
|
||||||
elseif y < 0 then
|
|
||||||
new_acce = {x = 0, y = 20, z = 0}
|
|
||||||
else
|
|
||||||
new_acce = {x = 0, y = 5, z = 0}
|
|
||||||
end
|
|
||||||
new_velo = get_velocity(entity.v, entity.object:get_yaw(), y)
|
|
||||||
entity.object:set_pos(entity.object:get_pos())
|
|
||||||
else
|
|
||||||
new_acce = {x = 0, y = 0, z = 0}
|
|
||||||
if math.abs(entity.object:get_velocity().y) < 1 then
|
|
||||||
local pos = entity.object:get_pos()
|
|
||||||
pos.y = math.floor(pos.y) + 0.5
|
|
||||||
entity.object:set_pos(pos)
|
|
||||||
new_velo = get_velocity(entity.v, entity.object:get_yaw(), 0)
|
|
||||||
else
|
|
||||||
new_velo = get_velocity(entity.v, entity.object:get_yaw(),
|
|
||||||
entity.object:get_velocity().y)
|
|
||||||
entity.object:set_pos(entity.object:get_pos())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if can_fly and can_fly == true and ctrl.jump then
|
|
||||||
new_velo.y = new_velo.y + 0.75
|
|
||||||
end
|
|
||||||
entity.object:set_velocity(new_velo)
|
|
||||||
entity.object:set_acceleration(new_acce)
|
|
||||||
end
|
|
||||||
|
@ -5,7 +5,7 @@ end
|
|||||||
|
|
||||||
mobs_doomed.dragon.step_custom = function(self, dtime)
|
mobs_doomed.dragon.step_custom = function(self, dtime)
|
||||||
if self.driver then
|
if self.driver then
|
||||||
object_fly(self, dtime, 10, true, "mobs_doomed:fire_plyr", "walk", "stand")
|
mobs_doomed.object_fly(self, dtime, 10, true, "mobs_doomed:fire_plyr", "walk", "stand")
|
||||||
if self.state == "attack" then
|
if self.state == "attack" then
|
||||||
self.state = nil
|
self.state = nil
|
||||||
end
|
end
|
||||||
@ -19,7 +19,7 @@ mobs_doomed.dragon.ride = function(self, clicker)
|
|||||||
local inv = clicker:get_inventory()
|
local inv = clicker:get_inventory()
|
||||||
|
|
||||||
if self.driver and clicker == self.driver then
|
if self.driver and clicker == self.driver then
|
||||||
object_detach(self, clicker, {x=1, y=0, z=1})
|
mobs_doomed.object_detach(self, clicker, {x=1, y=0, z=1})
|
||||||
|
|
||||||
if inv:room_for_item("main", "mobs:saddle") then
|
if inv:room_for_item("main", "mobs:saddle") then
|
||||||
inv:add_item("main", "mobs:saddle")
|
inv:add_item("main", "mobs:saddle")
|
||||||
@ -29,7 +29,7 @@ mobs_doomed.dragon.ride = function(self, clicker)
|
|||||||
|
|
||||||
elseif not self.driver then
|
elseif not self.driver then
|
||||||
if clicker:get_wielded_item():get_name() == "mobs:saddle" then
|
if clicker:get_wielded_item():get_name() == "mobs:saddle" then
|
||||||
object_attach(self, clicker, {x=0, y=12, z=4}, {x=0, y=0, z=4})
|
mobs_doomed.object_attach(self, clicker, {x=0, y=12, z=4}, {x=0, y=0, z=4})
|
||||||
inv:remove_item("main", "mobs:saddle")
|
inv:remove_item("main", "mobs:saddle")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -49,7 +49,7 @@ end
|
|||||||
|
|
||||||
mobs_doomed.dragon.do_custom = function(self, dtime)
|
mobs_doomed.dragon.do_custom = function(self, dtime)
|
||||||
if self.driver then
|
if self.driver then
|
||||||
object_fly(self, dtime, 10, true, "mobs_doomed:fire_plyr", "walk", "stand")
|
mobs_doomed.object_fly(self, dtime, 10, true, "mobs_doomed:fire_plyr", "walk", "stand")
|
||||||
|
|
||||||
if self.state == "attack" then
|
if self.state == "attack" then
|
||||||
self.state = "idle"
|
self.state = "idle"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user