Working on weapons
This commit is contained in:
parent
cc05f37d18
commit
557b9925a9
2
init.lua
2
init.lua
@ -57,4 +57,4 @@ dofile(path.."/kienzan.lua")
|
||||
--dofile(path.."/kamehameha.lua")
|
||||
dofile(path.."/nssm_spears.lua")
|
||||
dofile(path.."/nssm_api.lua")
|
||||
--dofile(path.."/nssm_weapons.lua")
|
||||
dofile(path.."/nssm_weapons.lua")
|
||||
|
12
nssm_api.lua
12
nssm_api.lua
@ -27,7 +27,7 @@ function nssm:round(n)
|
||||
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
|
||||
end
|
||||
|
||||
function nssm:explosion_particles(exp_radius)
|
||||
function nssm:explosion_particles(pos, exp_radius)
|
||||
minetest.add_particlespawner(
|
||||
100*exp_radius, --amount
|
||||
0.1, --time
|
||||
@ -61,7 +61,7 @@ function nssm:explosion(pos, exp_radius, fire)
|
||||
})
|
||||
|
||||
--particles:
|
||||
nssm:explosion_particles(exp_radius)
|
||||
nssm:explosion_particles(pos, exp_radius)
|
||||
|
||||
--Damages entities around (not the player)
|
||||
local objects = minetest.env:get_objects_inside_radius(pos, exp_radius)
|
||||
@ -93,11 +93,11 @@ function nssm:explosion(pos, exp_radius, fire)
|
||||
--remove everything near the center of the explosion
|
||||
for dz=-radius,radius do
|
||||
for dy=-radius,radius do
|
||||
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
|
||||
local vi = a:index(pos.x + (-radius), pos.y + dy, pos.z + dz)
|
||||
for dx=-radius,radius do
|
||||
local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
|
||||
|
||||
if (x * x) + (y * y) + (z * z) <= (radius * radius) + pr:next(-radius, radius)
|
||||
if (dx * dx) + (dy * dy) + (dz * dz) <= (radius * radius) + pr:next(-radius, radius)
|
||||
and data[vi] ~= c_air
|
||||
and data[vi] ~= c_ignore
|
||||
and data[vi] ~= c_obsidian
|
||||
@ -140,11 +140,11 @@ function nssm:explosion(pos, exp_radius, fire)
|
||||
-- after effects
|
||||
if fire > 0
|
||||
and (minetest.registered_nodes[n].groups.flammable
|
||||
or math.random(1, 100) <= 10) then
|
||||
or math.random(1, 100) <= 3) then
|
||||
minetest.set_node(p, {name = "fire:basic_flame"})
|
||||
else
|
||||
local dist = nssm:round(((pos.x-p.x)^2 + (pos.y-p.y)^2 + (pos.z-p.z)^2)^1/2)
|
||||
local prob = 1/dist
|
||||
local prob = 2/dist
|
||||
if math.random(1,100)<=prob*100 then
|
||||
minetest.env:remove_node(p)
|
||||
end
|
||||
|
@ -4,6 +4,23 @@ local default_dir = {
|
||||
z = 1,
|
||||
}
|
||||
|
||||
local function node_ok(pos, fallback)
|
||||
|
||||
fallback = fallback or "default:dirt"
|
||||
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
|
||||
if not node then
|
||||
return minetest.registered_nodes[fallback]
|
||||
end
|
||||
|
||||
if minetest.registered_nodes[node.name] then
|
||||
return node
|
||||
end
|
||||
|
||||
return minetest.registered_nodes[fallback]
|
||||
end
|
||||
|
||||
function weapons_shot(itemstack, placer, pointed_thing, velocity, name)
|
||||
local dir = placer:get_look_dir();
|
||||
local playerpos = placer:getpos();
|
||||
@ -13,9 +30,9 @@ function weapons_shot(itemstack, placer, pointed_thing, velocity, name)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function default_on_step(self, pos, node, name, max_time, damage, dir, not_transparent, vel, dtime)
|
||||
function default_on_step(self, dtime, name, max_time, damage, dir, not_transparent, vel)
|
||||
local timer = 0
|
||||
print ("Dentro on_step\n")
|
||||
local pos = self.object:getpos()
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
if (timer>max_time) then
|
||||
@ -23,10 +40,8 @@ function default_on_step(self, pos, node, name, max_time, damage, dir, not_trans
|
||||
end
|
||||
end)
|
||||
|
||||
print ("Fin qui\n")
|
||||
--while going around it damages entities
|
||||
local objects = minetest.env:get_objects_inside_radius(pos, 2)
|
||||
print ("Fin qua\n")
|
||||
for _,obj in ipairs(objects) do
|
||||
if (obj:is_player()) then
|
||||
elseif (obj:get_luaentity() and obj:get_luaentity().name ~= "__builtin:item") then
|
||||
@ -39,13 +54,10 @@ function default_on_step(self, pos, node, name, max_time, damage, dir, not_trans
|
||||
end
|
||||
end
|
||||
|
||||
print ("Fino qui\n")
|
||||
|
||||
local n = minetest.env:get_node(pos).name
|
||||
|
||||
if n ~=not_transparent then
|
||||
minetest.env:set_node(pos, {name="air"})
|
||||
print ("Fino qua\n")
|
||||
local vec = self.object:getvelocity()
|
||||
local c=3
|
||||
--calculate how many blocks around need to be removed
|
||||
@ -62,6 +74,7 @@ function default_on_step(self, pos, node, name, max_time, damage, dir, not_trans
|
||||
end
|
||||
end
|
||||
else
|
||||
local node = node_ok(pos).name
|
||||
self.hit_node(self, pos, node)
|
||||
self.object:remove()
|
||||
return
|
||||
@ -72,8 +85,12 @@ end
|
||||
function nssm_register_weapon(name, def)
|
||||
minetest.register_entity("nssm:"..name, {
|
||||
textures = {name..".png"},
|
||||
on_step = def.on_step,
|
||||
hit_node = def.hit_node,
|
||||
on_step = function(self, dtime)
|
||||
def.on_step(self, dtime)
|
||||
end,
|
||||
hit_node = function(self, pos, node)
|
||||
def.hit_node(self, pos, node)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_tool("nssm:"..name.."_hand", {
|
||||
@ -81,7 +98,6 @@ function nssm_register_weapon(name, def)
|
||||
inventory_image = name.."_hand.png",
|
||||
on_use = function(itemstack, placer, pointed_thing)
|
||||
weapons_shot(itemstack, placer, pointed_thing, def.velocity, name)
|
||||
minetest.chat_send_all("Description: "..def.description)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
@ -101,13 +117,13 @@ function nssm_register_weapon(name, def)
|
||||
end
|
||||
|
||||
--function default_on_step(self, pos, node, name, max_time, damage, dir, not_transparent, vel, dtime)
|
||||
--function default_on_step(self, dtime, name, max_time, damage, dir, not_transparent, vel)
|
||||
nssm_register_weapon("kamehameha", {
|
||||
on_step = function(self, pos, node, dtime)
|
||||
print ("Prima di chiamare on_step\n")
|
||||
default_on_step(self, pos, node, "kamehameha", 10, 20, default_dir, "default:stone", 30, dtime)
|
||||
on_step = function(self, dtime)
|
||||
default_on_step(self, dtime, "kamehameha", 10, 20, default_dir, "default:stone", 30)
|
||||
end,
|
||||
hit_node = function(self, pos, node)
|
||||
nssm:explosion(self, pos, 4, 1)
|
||||
nssm:explosion(pos, 8, 1)
|
||||
end,
|
||||
material = "default:stick",
|
||||
description = "Kamehameha from DragonBall",
|
||||
|
Loading…
x
Reference in New Issue
Block a user