Assaultsuit, jeep, and api changes
>Added assault suit and jeep >Fixed animation and jumping >added hovering >fixed eye offset >improved shooting, bullet spawn height can be setmaster
parent
e129064877
commit
a64b054b00
94
api.lua
94
api.lua
|
@ -52,13 +52,13 @@ function object_attach(entity, player, attach_at, visible, eye_offset)
|
|||
entity.driver = player
|
||||
entity.loaded = true
|
||||
player:set_attach(entity.object, "", attach_at, {x=0, y=0, z=0})
|
||||
--this is to hide the player when the attaching doesn't work properly
|
||||
-- this is to hide the player when the attaching doesn't work properly
|
||||
if not visible then
|
||||
player:set_properties({visual_size = {x=0, y=0}})
|
||||
else
|
||||
player:set_properties({visual_size = {x=1, y=1}})
|
||||
end
|
||||
player:set_eye_offset(eye_offset, {x=0, y=2, z=-40})
|
||||
player:set_eye_offset(eye_offset, {x=eye_offset.x, y=eye_offset.y+1, z=-40})
|
||||
default.player_attached[player:get_player_name()] = true
|
||||
minetest.after(0.2, function()
|
||||
default.player_set_animation(player, "sit" , 30)
|
||||
|
@ -109,8 +109,9 @@ end)
|
|||
timer = 0
|
||||
|
||||
--basic driving, use for basic vehicles/mounts, with optional weapons
|
||||
function object_drive(entity, dtime, speed, decell, shoots, arrow, reload, moving_anim, stand_anim, jumps)
|
||||
function object_drive(entity, dtime, speed, decell, shoots, arrow, reload, moving_anim, stand_anim, jump, jump_anim, shoot_anim, shoot_y)
|
||||
--variables
|
||||
local shoot_y = shoot_y or 1.5
|
||||
local ctrl = entity.driver:get_player_control()
|
||||
local velo = entity.object:getvelocity()
|
||||
local dir = entity.driver:get_look_dir();
|
||||
|
@ -128,6 +129,8 @@ function object_drive(entity, dtime, speed, decell, shoots, arrow, reload, movin
|
|||
end
|
||||
--timer dependant variables
|
||||
local vec_forward = {x=dir.x*speed/4*math.atan(0.5*timer-2)+8*dir.x,y=velo.y+1*-2,z=dir.z*speed/4*math.atan(0.5*timer-2)+8*dir.z}
|
||||
local vec_forward_hover = {x=dir.x*speed/4*math.atan(0.5*timer-2)+8*dir.x,y=1.5,z=dir.z*speed/4*math.atan(0.5*timer-2)+8*dir.z}
|
||||
local vec_forward_jump = {x=dir.x*speed/4*math.atan(0.5*timer-2)+8*dir.x,y=4,z=dir.z*speed/4*math.atan(0.5*timer-2)+8*dir.z}
|
||||
|
||||
--respond to controls
|
||||
--water effects
|
||||
|
@ -138,12 +141,27 @@ function object_drive(entity, dtime, speed, decell, shoots, arrow, reload, movin
|
|||
elseif ctrl.up then
|
||||
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||
entity.object:setvelocity(vec_forward)
|
||||
--lib_mount animation
|
||||
if moving_anim ~= nil and not entity.moving and not hovering then
|
||||
entity.object:set_animation(moving_anim, 20, 0)
|
||||
entity.moving = true
|
||||
end
|
||||
elseif ctrl.down then
|
||||
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||
entity.object:setvelocity(vec_backward)
|
||||
--lib_mount animation
|
||||
if moving_anim ~= nil and not entity.moving and not hovering then
|
||||
entity.object:set_animation(moving_anim, 20, 0)
|
||||
entity.moving = true
|
||||
end
|
||||
elseif not ctrl.down or ctrl.up then
|
||||
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||
entity.object:setvelocity(vec_stop)
|
||||
--lib_mount animation
|
||||
if moving_anim ~= nil and entity.moving and not hovering then
|
||||
entity.object:set_animation(stand_anim, 20, 0)
|
||||
entity.moving = false
|
||||
end
|
||||
end
|
||||
if ctrl.sneak and shoots and entity.loaded then
|
||||
local pname = entity.driver:get_player_name();
|
||||
|
@ -152,44 +170,64 @@ function object_drive(entity, dtime, speed, decell, shoots, arrow, reload, movin
|
|||
local remov = inv:remove_item("main", arrow.."_item")
|
||||
entity.loaded = false
|
||||
local pos = entity.object:getpos()
|
||||
local obj = minetest.env:add_entity({x=pos.x+0+dir.x*2,y=pos.y+1.5+dir.y,z=pos.z+0+dir.z*2}, arrow)
|
||||
local obj = minetest.env:add_entity({x=pos.x+0+dir.x*2,y=pos.y+shoot_y+dir.y,z=pos.z+0+dir.z*2}, arrow)
|
||||
local vec = {x=dir.x*9,y=dir.y*9,z=dir.z*9}
|
||||
local yaw = entity.driver:get_look_yaw();
|
||||
obj:setyaw(yaw+math.pi/2)
|
||||
obj:setvelocity(vec)
|
||||
local object = obj:get_luaentity()
|
||||
object.launcher = entity.driver
|
||||
if shoot_anim ~= nil and entity.object:get_animation().range ~= shoot_anim then
|
||||
entity.object:set_animation(shoot_anim, 20, 0)
|
||||
end
|
||||
minetest.after(reload, function()
|
||||
entity.loaded = true
|
||||
if stand_anim ~= nil and shoot_anim ~= nil then
|
||||
entity.object:set_animation(stand_anim, 20, 0)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
--lib_mount animation
|
||||
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
||||
if stand_anim and stand_anim ~= nil and mobs_redo == true then
|
||||
self.object:set_animation(entity, stand_anim)
|
||||
|
||||
if jump == "hover" and ctrl.jump and not entity.jumpcharge then
|
||||
if not ctrl.up then
|
||||
local vec_hover = {x=velo.x+0,y=1,z=velo.z+0}
|
||||
entity.object:setvelocity(vec_hover)
|
||||
else
|
||||
entity.object:setvelocity(vec_forward_hover)
|
||||
end
|
||||
return
|
||||
hovering = true
|
||||
if jump_anim ~= nil and entity.object:get_animation().range ~= jump_anim and hovering then
|
||||
entity.object:set_animation(jump_anim, 20, 0)
|
||||
end
|
||||
minetest.after(5, function()
|
||||
entity.jumpcharge = true
|
||||
end)
|
||||
minetest.after(10, function()
|
||||
entity.jumpcharge = false
|
||||
hovering = false
|
||||
end)
|
||||
end
|
||||
if moving_anim and moving_anim ~= nil then
|
||||
self.object:set_animation(entity, moving_anim)
|
||||
|
||||
if jump == "jump" and ctrl.jump and not entity.jumpcharge then
|
||||
if not ctrl.up then
|
||||
local vec_jump = {x=velo.x+0,y=4,z=velo.z+0}
|
||||
entity.object:setvelocity(vec_jump)
|
||||
else
|
||||
entity.object:setvelocity(vec_forward_hover)
|
||||
end
|
||||
hovering = true
|
||||
if jump_anim ~= nil and entity.object:get_animation().range ~= jump_anim and hovering then
|
||||
entity.object:set_animation(jump_anim, 20, 0)
|
||||
end
|
||||
minetest.after(0.5, function()
|
||||
entity.jumpcharge = true
|
||||
end)
|
||||
minetest.after(1, function()
|
||||
entity.jumpcharge = false
|
||||
hovering = false
|
||||
end)
|
||||
end
|
||||
--jumping not working
|
||||
-- local jumps = jumps or false
|
||||
-- if jumps == true and ctrl.jump then
|
||||
-- local xvel = entity.object:getvelocity().x
|
||||
-- local zvel = entity.object:getvelocity().z
|
||||
-- local yvel = entity.object:getvelocity().y
|
||||
-- local vel = {x=xvel,y=10,z=zvel}
|
||||
-- entity.object:setvelocity(vel)
|
||||
-- minetest.after(1.5, function()
|
||||
-- local xvel = entity.object:getvelocity().x
|
||||
-- local zvel = entity.object:getvelocity().z
|
||||
-- local yvel = entity.object:getvelocity().y
|
||||
-- local vel = {x=xvel,y=-10,z=zvel}
|
||||
-- entity.object:setvelocity(vel)
|
||||
-- end)
|
||||
-- end
|
||||
end
|
||||
|
||||
|
||||
|
@ -247,7 +285,9 @@ function object_drive_car(entity, dtime, speed, decell, nitro_duration)
|
|||
|
||||
--face the right way
|
||||
local yaw = entity.driver:get_look_yaw();
|
||||
--if ctrl.up or ctrl.down then
|
||||
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||
--end
|
||||
if not entity.nitro then
|
||||
minetest.after(4, function()
|
||||
entity.nitro = true
|
||||
|
|
123
init.lua
123
init.lua
|
@ -305,6 +305,55 @@ minetest.register_entity("vehicles:turret", {
|
|||
register_vehicle_spawner("vehicles:tank", "Tank", "vehicles_tank_inv.png")
|
||||
register_vehicle_spawner("vehicles:turret", "Gun turret", "vehicles_turret_inv.png")
|
||||
|
||||
minetest.register_entity("vehicles:assaultsuit", {
|
||||
visual = "mesh",
|
||||
mesh = "assaultsuit.b3d",
|
||||
textures = {"vehicles_assaultsuit.png"},
|
||||
velocity = 15,
|
||||
acceleration = -5,
|
||||
owner = "",
|
||||
stepheight = 1.5,
|
||||
hp_max = 200,
|
||||
physical = true,
|
||||
collisionbox = {-0.8, 0, -0.8, 0.8, 3, 0.8},
|
||||
on_rightclick = function(self, clicker)
|
||||
if self.driver and clicker == self.driver then
|
||||
object_detach(self, clicker, {x=1, y=0, z=1})
|
||||
elseif not self.driver then
|
||||
object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=20, z=8})
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, puncher)
|
||||
if not self.driver then
|
||||
local name = self.object:get_luaentity().name
|
||||
local pos = self.object:getpos()
|
||||
minetest.env:add_item(pos, name.."_spawner")
|
||||
self.object:remove()
|
||||
end
|
||||
if self.object:get_hp() == 0 then
|
||||
if self.driver then
|
||||
object_detach(self, self.driver, {x=1, y=0, z=1})
|
||||
end
|
||||
explode(self, 5)
|
||||
end
|
||||
end,
|
||||
on_step = function(self, dtime)
|
||||
if self.driver then
|
||||
object_drive(self, dtime, 6, 0.5, true, "vehicles:bullet", 0.2, {x=120, y=140}, {x=1, y=1}, "hover", {x=60, y=70}, {x=40, y=51}, 3.5)
|
||||
self.standing = false
|
||||
return false
|
||||
else
|
||||
if not standing then
|
||||
self.object:set_animation({x=1, y=1}, 20, 0)
|
||||
self.standing = true
|
||||
end
|
||||
end
|
||||
return true
|
||||
end,
|
||||
})
|
||||
|
||||
register_vehicle_spawner("vehicles:assaultsuit", "Assault Suit", "vehicles_assaultsuit_inv.png")
|
||||
|
||||
minetest.register_entity("vehicles:firetruck", {
|
||||
visual = "mesh",
|
||||
mesh = "firetruck.b3d",
|
||||
|
@ -347,6 +396,80 @@ minetest.register_entity("vehicles:firetruck", {
|
|||
|
||||
register_vehicle_spawner("vehicles:firetruck", "Fire truck", "vehicles_firetruck_inv.png")
|
||||
|
||||
minetest.register_entity("vehicles:jeep", {
|
||||
visual = "mesh",
|
||||
mesh = "jeep.b3d",
|
||||
textures = {"vehicles_jeep.png"},
|
||||
velocity = 15,
|
||||
acceleration = -5,
|
||||
stepheight = 1.5,
|
||||
hp_max = 200,
|
||||
physical = true,
|
||||
collisionbox = {-1.1, 0, -1.1, 1.1, 1, 1.1},
|
||||
on_rightclick = function(self, clicker)
|
||||
if self.driver and clicker == self.driver then
|
||||
object_detach(self, clicker, {x=1, y=0, z=1})
|
||||
elseif self.driver and clicker ~= self.driver and not self.rider then
|
||||
clicker:set_attach(self.object, "", {x=0, y=5, z=-5}, false, {x=0, y=0, z=-2})
|
||||
self.rider = true
|
||||
elseif self.driver and clicker ~=self.driver and self.rider then
|
||||
clicker:set_detach()
|
||||
self.rider = false
|
||||
elseif not self.driver then
|
||||
object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
|
||||
minetest.sound_play("engine_start",
|
||||
{gain = 6, max_hear_distance = 3, loop = false})
|
||||
self.sound_ready = false
|
||||
minetest.after(14, function()
|
||||
self.sound_ready = true
|
||||
end)
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, puncher)
|
||||
if not self.driver then
|
||||
local name = self.object:get_luaentity().name
|
||||
local pos = self.object:getpos()
|
||||
minetest.env:add_item(pos, name.."_spawner")
|
||||
self.object:remove()
|
||||
end
|
||||
if self.object:get_hp() == 0 then
|
||||
if self.driver then
|
||||
object_detach(self, self.driver, {x=1, y=0, z=1})
|
||||
end
|
||||
explode(self, 5)
|
||||
end
|
||||
end,
|
||||
on_activate = function(self)
|
||||
self.nitro = true
|
||||
end,
|
||||
on_step = function(self, dtime)
|
||||
if self.driver then
|
||||
object_drive_car(self, dtime, 14, 0.6, 6)
|
||||
local pos = self.object:getpos()
|
||||
minetest.add_particlespawner(
|
||||
15, --amount
|
||||
1, --time
|
||||
{x=pos.x, y=pos.y, z=pos.z}, --minpos
|
||||
{x=pos.x, y=pos.y, z=pos.z}, --maxpos
|
||||
{x=0, y=0, z=0}, --minvel
|
||||
{x=0, y=0, z=0}, --maxvel
|
||||
{x=-0,y=-0,z=-0}, --minacc
|
||||
{x=0,y=0,z=0}, --maxacc
|
||||
0.5, --minexptime
|
||||
1, --maxexptime
|
||||
10, --minsize
|
||||
15, --maxsize
|
||||
false, --collisiondetection
|
||||
"vehicles_dust.png" --texture
|
||||
)
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end,
|
||||
})
|
||||
|
||||
register_vehicle_spawner("vehicles:jeep", "Jeep", "vehicles_jeep_inv.png")
|
||||
|
||||
minetest.register_entity("vehicles:ute", {
|
||||
visual = "mesh",
|
||||
mesh = "ute.b3d",
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
Binary file not shown.
After Width: | Height: | Size: 512 B |
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
Binary file not shown.
After Width: | Height: | Size: 398 B |
Loading…
Reference in New Issue