Paste Code
Paste Blends
Paste Images
--This file is used for the ABM based "Hunter" included in this mod.

local function get_sign(i)
if i == 0 then
return 0
else
return i/math.abs(i)
end
end

local function get_velocity(v, yaw, y)
local x = math.cos(yaw)*v
local z = math.sin(yaw)*v
return {x=x, y=y, z=z}
end

local function get_v(v)
return math.sqrt(v.x^2+v.z^2)
end
--[[
minetest.register_abm({
nodenames = {"air"},
interval = 10,
chance = 0.1,
action = function(pos, timer)
minetest.env:clear_objects()
end,
})
]]

local hunter = {
hp_max = 100,
physical = true,
collisionbox = {-2.5,-7,-2.5, 2.5,4,2.5},
visual = "mesh",
mesh = "patrouilleur.x",
textures = {"patrouilleur.png"},
automatic_rotate = true,
makes_footstep_sound = true,
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,

driver = nil,
v = 0,
z = 0,
}

function hunter:on_rightclick(clicker)
if not clicker or not clicker:is_player() then
return
end
if self.driver and clicker == self.driver then
self.driver = nil
self.object:set_animation({x=50, y=55}, 15, 1)
local p = get_velocity(3, self.object:getyaw(), 3)
local pos = self.object:getpos()
pos.x = pos.x-p.x
pos.y = pos.y-p.y
pos.z = pos.z-p.z
clicker:set_detach()
clicker:setpos(pos)
self.object:setvelocity({x=0, y=0, z=0})
elseif not self.driver then
self.driver = clicker
clicker:set_attach(self.object, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
self.object:set_animation({x=55, y=60}, 15, 1)
end
end

function hunter:on_activate(staticdata, dtime_s)
self.object:set_armor_groups({immortal=1})
if staticdata then
self.v = tonumber(staticdata)
end
end

function hunter:get_staticdata()
return tostring(v)
end

function hunter:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
self.object:remove()
if puncher and puncher:is_player() then
puncher:get_inventory():add_item("main", "technology:hunter")
end
end

minetest.register_craft({
output = 'technology:hunter',
recipe = {
{' ', 'homedecor:plastic_sheeting', ' '},
{'homedecor:plastic_sheeting', 'homedecor:power_crystal', 'homedecor:plastic_sheeting'},
{'homedecor:plastic_sheeting', 'homedecor:power_crystal', 'homedecor:plastic_sheeting'},
}
})

function hunter:on_step(dtime)
-- make fire if damages are over 50%
if self.object:get_hp() < 50 then
print("hunter is burning")
local pos = self.object:getpos()
pos.x = pos.x + math.random(-2,2)
pos.y = pos.y + math.random(-2,2)
pos.z = pos.z + math.random(-2,2)
minetest.env:set_node(pos, {name="fire:basic_flame"})
self.z = self.z - 0.1
end
-- explode when hp is under 5
if self.object:get_hp() < 5 then
explosion(self.object:getpos(), 30)
end
local velocity = self.object:getvelocity()
-- have user commands
self.v = get_v(velocity)*get_sign(self.v)
if self.driver then
local ctrl = self.driver:get_player_control()
if ctrl.up then
self.v = self.v+0.4
end
if ctrl.down then
self.v = self.v-0.4
end
if ctrl.left then
self.object:setyaw(self.object:getyaw()+math.pi/120+dtime*math.pi/120)
--self.object:set_animation({x=5, y=5}, 1, 0)
end
if ctrl.right then
self.object:setyaw(self.object:getyaw()-math.pi/120-dtime*math.pi/120)
--self.object:set_animation({x=15, y=15}, 1, 0)
end
if ctrl.jump then
self.z = self.z+0.15
end
if ctrl.sneak then
self.z = self.z-0.15
end
end
local z = get_sign(self.z)
self.z = self.z - 0.02*z
if z ~= get_sign(self.z) then
self.object:setvelocity({x=0,y=0,z=0})
self.z = 0
return
end
if math.abs(self.z) > 4.5 then
self.z = 4.5*get_sign(self.z)
end

local s = get_sign(self.v)
self.v = self.v - 0.02*s
if s ~= get_sign(self.v) then
self.object:setvelocity({x=0, y=0, z=0})
self.v = 0
return
end
if math.abs(self.v) > 6 then
self.v = 6*get_sign(self.v)
end

self.object:setacceleration({x=0, y=0, z=0})
if math.abs(self.object:getvelocity().y) < 0.01 then
local pos = self.object:getpos()
pos.y = math.floor(pos.y)+0
self.object:setpos(pos)
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.z))
else
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.z))
end
end

minetest.register_entity("technology:hunter", hunter)


minetest.register_craftitem("technology:hunter", {
description = "hunter flying",
inventory_image = "hunter_inv.png",
wield_image = "hunter_inv.png",
wield_scale = {x=2, y=2, z=1},
liquids_pointable = true,

on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
print("hunter added !!!")
pointed_thing.under.y = pointed_thing.under.y+2
minetest.env:add_entity(pointed_thing.under, "technology:hunter")
itemstack:take_item()
return itemstack
end,
})
  1. --This file is used for the ABM based "Hunter" included in this mod.
  2.  
  3. local function get_sign(i)
  4.         if i == 0 then
  5.                 return 0
  6.         else
  7.                 return i/math.abs(i)
  8.         end
  9. end
  10.  
  11. local function get_velocity(v, yaw, y)
  12.         local x = math.cos(yaw)*v
  13.         local z = math.sin(yaw)*v
  14.         return {x=x, y=y, z=z}
  15. end
  16.  
  17. local function get_v(v)
  18.         return math.sqrt(v.x^2+v.z^2)
  19. end
  20. --[[
  21. minetest.register_abm({
  22.         nodenames = {"air"},
  23.         interval = 10,
  24.         chance  = 0.1,
  25.         action = function(pos, timer)
  26.                 minetest.env:clear_objects()
  27.         end,
  28. })
  29. ]]
  30.  
  31. local hunter = {
  32.         hp_max = 100,
  33.         physical = true,
  34.         collisionbox = {-2.5,-7,-2.5, 2.5,4,2.5},
  35.         visual = "mesh",
  36.         mesh = "patrouilleur.x",
  37.         textures = {"patrouilleur.png"},
  38.         automatic_rotate = true,
  39.         makes_footstep_sound = true,
  40.         spritediv = {x=1, y=1},
  41.         initial_sprite_basepos = {x=0, y=0},
  42.         is_visible = true,
  43.        
  44.         driver = nil,
  45.         v = 0,
  46.         z = 0,
  47. }
  48.  
  49. function hunter:on_rightclick(clicker)
  50.         if not clicker or not clicker:is_player() then
  51.                 return
  52.         end
  53.         if self.driver and clicker == self.driver then
  54.                 self.driver = nil
  55.                 self.object:set_animation({x=50, y=55}, 15, 1)
  56.                 local p = get_velocity(3, self.object:getyaw(), 3)
  57.                 local pos = self.object:getpos()
  58.                 pos.x = pos.x-p.x
  59.                 pos.y = pos.y-p.y
  60.                 pos.z = pos.z-p.z
  61.                 clicker:set_detach()
  62.                 clicker:setpos(pos)
  63.                 self.object:setvelocity({x=0, y=0, z=0})
  64.         elseif not self.driver then
  65.                 self.driver = clicker
  66.                 clicker:set_attach(self.object, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
  67.                 self.object:set_animation({x=55, y=60}, 15, 1)
  68.         end
  69. end
  70.  
  71. function hunter:on_activate(staticdata, dtime_s)
  72.         self.object:set_armor_groups({immortal=1})
  73.         if staticdata then
  74.                 self.v = tonumber(staticdata)
  75.         end
  76. end
  77.  
  78. function hunter:get_staticdata()
  79.         return tostring(v)
  80. end
  81.  
  82. function hunter:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
  83.         self.object:remove()
  84.         if puncher and puncher:is_player() then
  85.                 puncher:get_inventory():add_item("main", "technology:hunter")
  86.         end
  87. end
  88.  
  89. minetest.register_craft({
  90.         output = 'technology:hunter',
  91.         recipe = {
  92.                 {' ', 'homedecor:plastic_sheeting', ' '},
  93.                 {'homedecor:plastic_sheeting', 'homedecor:power_crystal', 'homedecor:plastic_sheeting'},
  94.                 {'homedecor:plastic_sheeting', 'homedecor:power_crystal', 'homedecor:plastic_sheeting'},
  95.         }
  96. })
  97.  
  98. function hunter:on_step(dtime)
  99.         -- make fire if damages are over 50%
  100.         if self.object:get_hp() < 50 then
  101.                 print("hunter is burning")
  102.                 local pos = self.object:getpos()
  103.                 pos.x = pos.x + math.random(-2,2)
  104.                 pos.y = pos.y + math.random(-2,2)
  105.                 pos.z = pos.z + math.random(-2,2)
  106.                 minetest.env:set_node(pos, {name="fire:basic_flame"})
  107.                 self.z = self.z - 0.1
  108.         end
  109.         -- explode when hp is under 5
  110.         if self.object:get_hp() < 5 then
  111.                 explosion(self.object:getpos(), 30)
  112.         end
  113.         local velocity = self.object:getvelocity()
  114.         -- have user commands
  115.         self.v = get_v(velocity)*get_sign(self.v)
  116.         if self.driver then
  117.                 local ctrl = self.driver:get_player_control()
  118.                 if ctrl.up then
  119.                         self.v = self.v+0.4
  120.                 end
  121.                 if ctrl.down then
  122.                         self.v = self.v-0.4
  123.                 end
  124.                 if ctrl.left then
  125.                         self.object:setyaw(self.object:getyaw()+math.pi/120+dtime*math.pi/120)
  126.                         --self.object:set_animation({x=5, y=5}, 1, 0)
  127.                 end
  128.                 if ctrl.right then
  129.                         self.object:setyaw(self.object:getyaw()-math.pi/120-dtime*math.pi/120)
  130.                         --self.object:set_animation({x=15, y=15}, 1, 0)
  131.                 end
  132.                 if ctrl.jump then
  133.                         self.z = self.z+0.15
  134.                 end
  135.                 if ctrl.sneak then
  136.                         self.z = self.z-0.15
  137.                 end
  138.         end
  139.         local z = get_sign(self.z)
  140.         self.z = self.z - 0.02*z
  141.         if z ~= get_sign(self.z) then
  142.                 self.object:setvelocity({x=0,y=0,z=0})
  143.                 self.z = 0
  144.                 return
  145.         end
  146.         if math.abs(self.z) > 4.5 then
  147.                 self.z = 4.5*get_sign(self.z)
  148.         end
  149.        
  150.         local s = get_sign(self.v)
  151.         self.v = self.v - 0.02*s
  152.         if s ~= get_sign(self.v) then
  153.                 self.object:setvelocity({x=0, y=0, z=0})
  154.                 self.v = 0
  155.                 return
  156.         end
  157.         if math.abs(self.v) > 6 then
  158.                 self.v = 6*get_sign(self.v)
  159.         end
  160.  
  161.         self.object:setacceleration({x=0, y=0, z=0})
  162.         if math.abs(self.object:getvelocity().y) < 0.01 then
  163.                 local pos = self.object:getpos()
  164.                 pos.y = math.floor(pos.y)+0
  165.                 self.object:setpos(pos)
  166.                 self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.z))
  167.         else
  168.                 self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.z))
  169.         end
  170. end
  171.  
  172. minetest.register_entity("technology:hunter", hunter)
  173.  
  174.  
  175. minetest.register_craftitem("technology:hunter", {
  176.         description = "hunter flying",
  177.         inventory_image = "hunter_inv.png",
  178.         wield_image = "hunter_inv.png",
  179.         wield_scale = {x=2, y=2, z=1},
  180.         liquids_pointable = true,
  181.        
  182.         on_place = function(itemstack, placer, pointed_thing)
  183.                 if pointed_thing.type ~= "node" then
  184.                         return
  185.                 end
  186.                 print("hunter added !!!")
  187.                 pointed_thing.under.y = pointed_thing.under.y+2
  188.                 minetest.env:add_entity(pointed_thing.under, "technology:hunter")
  189.                 itemstack:take_item()
  190.                 return itemstack
  191.         end,
  192. })
go to heaven