Serious update
parent
cae8dd0c07
commit
ae0d4f9fa7
79
init.lua
79
init.lua
|
@ -1,4 +1,4 @@
|
|||
local rocket_radius = tonumber(core.settings:get("rocket_launcher_radius")) or 3
|
||||
local default_radius = tonumber(core.settings:get("rocket_launcher_radius")) or 3
|
||||
local ballistic = core.settings:get("rocket_launcher_ballistic") or true
|
||||
local reloading = {}
|
||||
local function reload(name)
|
||||
|
@ -11,15 +11,24 @@ local function reload(name)
|
|||
end
|
||||
|
||||
core.register_chatcommand("rocket-radius", {
|
||||
description = "Set rocket explosion radius",
|
||||
description = "Set rocket explosion radius for wielded rauncher",
|
||||
params = "<number>",
|
||||
privs = {server=true},
|
||||
func = function(name, param)
|
||||
if not tonumber(param) then return false, 'Invalid value'
|
||||
else
|
||||
rocket_radius = tonumber(param)
|
||||
return true, 'Radius set to '..param
|
||||
end
|
||||
local radius = tonumber(param)
|
||||
if not radius then return false, "Invalid radius" end
|
||||
local player = core.get_player_by_name(name)
|
||||
if not player then return end
|
||||
local witem = player:get_wielded_item()
|
||||
if not witem then return end
|
||||
if witem:get_name() ~= "rocket_launcher:launcher" then return false, "Keep rocket launcher in hand!" end
|
||||
local meta = witem:get_meta()
|
||||
if meta then
|
||||
meta:set_int("radius",radius)
|
||||
meta:set_string("count_meta","R"..param)
|
||||
player:set_wielded_item(witem)
|
||||
return true, "Radius set to "..param
|
||||
end
|
||||
end})
|
||||
core.register_craftitem("rocket_launcher:rocket", {
|
||||
wield_scale = {x=1,y=1,z=1.5},
|
||||
|
@ -27,7 +36,7 @@ core.register_craftitem("rocket_launcher:rocket", {
|
|||
description = "Rocket",
|
||||
inventory_image = "rocket.png",
|
||||
})
|
||||
local owner
|
||||
|
||||
core.register_tool("rocket_launcher:launcher", {
|
||||
wield_scale = {x=1,y=1,z=2},
|
||||
description = "Rocket Launcher",
|
||||
|
@ -45,12 +54,14 @@ core.register_tool("rocket_launcher:launcher", {
|
|||
reload(name)
|
||||
inv:remove_item("main", "rocket_launcher:rocket 1")
|
||||
end
|
||||
local meta = itemstack:get_meta()
|
||||
local radius = meta:get("radius") or default_radius
|
||||
local pos = user:get_pos()
|
||||
local dir = user:get_look_dir()
|
||||
local yaw = user:get_look_horizontal()
|
||||
if pos and dir then
|
||||
pos.y = pos.y + 1.5
|
||||
local obj = core.add_entity(pos, "rocket_launcher:rocket")
|
||||
local obj = core.add_entity(pos, "rocket_launcher:rocket",radius)
|
||||
if obj then
|
||||
obj:set_velocity({x=dir.x * 30, y=dir.y * 30, z=dir.z * 30})
|
||||
user:add_velocity({x=dir.x * -4, y=dir.y * -4, z=dir.z * -4})
|
||||
|
@ -58,7 +69,7 @@ core.register_tool("rocket_launcher:launcher", {
|
|||
obj:set_acceleration({x=0,z=0,y=-1})
|
||||
end
|
||||
obj:set_yaw(yaw)
|
||||
owner = user
|
||||
obj:set_attribute("owner",name)
|
||||
end
|
||||
end
|
||||
core.sound_play('rocket_launch',{to_player = name, gain=0.5})
|
||||
|
@ -81,48 +92,46 @@ local rocket = {
|
|||
collide_with_objects = false,
|
||||
automatic_face_movement_dir = 270
|
||||
}
|
||||
rocket.on_step = function(self, dtime)
|
||||
|
||||
rocket.on_activate = function(self, staticdata)
|
||||
self["radius"] = staticdata or 3
|
||||
end
|
||||
|
||||
rocket.on_step = function(self, dtime, moveresult)
|
||||
self.timer = self.timer + dtime
|
||||
local pos = self.object:get_pos()
|
||||
local node = core.get_node(pos)
|
||||
local rnd = math.random()
|
||||
core.after(0.1,function()
|
||||
core.add_particle({
|
||||
pos = pos,
|
||||
velocity = {x=rnd,y=rnd,z=rnd},
|
||||
--acceleration = {x=rnd,y=rnd,z=rnd},
|
||||
expirationtime = 0.7,
|
||||
size = 10,
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = "tnt_smoke.png",
|
||||
glow = 15,})end)
|
||||
core.add_particle({
|
||||
pos = pos,
|
||||
velocity = {x=rnd,y=rnd,z=rnd},
|
||||
--acceleration = {x=rnd,y=rnd,z=rnd},
|
||||
expirationtime = 0.7,
|
||||
size = 6,
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = "tnt_smoke.png",
|
||||
glow = 15})
|
||||
end)
|
||||
if self.timer >= 60 then
|
||||
self.object:remove()
|
||||
end
|
||||
if self.timer > 0.2 then
|
||||
local objs = core.get_objects_inside_radius({x = pos.x, y = pos.y-1, z = pos.z}, 1)
|
||||
for k, obj in pairs(objs) do
|
||||
if not obj then goto nodes end
|
||||
local prop = obj:get_properties()
|
||||
if not prop then goto nodes end
|
||||
if not obj then goto nodes end
|
||||
local prop = obj:get_properties()
|
||||
if not prop then goto nodes end
|
||||
if obj:is_player() or prop.collide_with_objects == true then
|
||||
obj:punch(self.object, 1.0, {
|
||||
full_punch_interval = 1.0,
|
||||
damage_groups= {fleshy = 20},
|
||||
}, nil)
|
||||
if not core.is_protected(self.lastpos,"") then
|
||||
tnt.boom(pos,{radius=rocket_radius})
|
||||
end
|
||||
tnt.boom(pos,{radius=self["radius"]})
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
::nodes::
|
||||
local velo = self.object:get_velocity()
|
||||
if not velo then return end
|
||||
if vector.length(velo) < 28 then
|
||||
tnt.boom(pos,{radius=rocket_radius})
|
||||
if moveresult.collides then
|
||||
tnt.boom(pos,{radius=self["radius"]})
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue