Bouncer: side dash by right-clicking
parent
05978f0edc
commit
2959079b58
|
@ -1,3 +1,8 @@
|
|||
local function can_use() end
|
||||
local function dash() end
|
||||
|
||||
|
||||
|
||||
local function register_bouncer(name, desc, energy)
|
||||
|
||||
minetest.register_tool("block_league:" .. name, {
|
||||
|
@ -7,30 +12,16 @@ local function register_bouncer(name, desc, energy)
|
|||
jump_height = 5,
|
||||
groups = {oddly_breakable_by_hand = "2"},
|
||||
on_drop = function() end,
|
||||
on_place = function() end,
|
||||
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
----- gestione delay dell'arma -----
|
||||
local meta = user:get_meta()
|
||||
if meta:get_int("bl_bouncer_delay") == 1 or
|
||||
meta:get_int("bl_death_delay") == 1 or
|
||||
meta:get_int("bl_reloading") == 1 or
|
||||
meta:get_int("bl_is_speed_locked") == 1 then return end
|
||||
|
||||
user:get_meta():set_int("bl_bouncer_delay", 1)
|
||||
|
||||
minetest.after(0.3, function()
|
||||
if not user then return end
|
||||
user:get_meta():set_int("bl_bouncer_delay", 0)
|
||||
end)
|
||||
----- fine gestione delay -----
|
||||
|
||||
local p_name = user:get_player_name()
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
if not can_use(user) then return end
|
||||
|
||||
-- se non sta puntando un nodo, annullo
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
|
||||
local p_name = user:get_player_name()
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
if arena then
|
||||
-- se non ha abbastanza energia, annullo
|
||||
if not (arena.players[p_name].energy >= energy) then return end
|
||||
|
@ -40,12 +31,70 @@ local function register_bouncer(name, desc, energy)
|
|||
local dir = user:get_look_dir()
|
||||
local knockback = user:get_player_velocity().y < 1 and -15 or -10
|
||||
|
||||
user:add_player_velocity(vector.multiply(dir, knockback))
|
||||
user:add_velocity(vector.multiply(dir, knockback))
|
||||
block_league.sound_play("bl_bouncer", p_name)
|
||||
|
||||
end,
|
||||
|
||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||
dash(user, energy)
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
dash(user, energy)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
register_bouncer("bouncer", "Bouncer", 20)
|
||||
register_bouncer("bouncer_dm", "Deathmatch Bouncer", 50)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
---------------FUNZIONI LOCALI----------------
|
||||
----------------------------------------------
|
||||
|
||||
function dash(player, energy)
|
||||
if not can_use(player) then return end
|
||||
|
||||
local p_name = player:get_player_name()
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
if arena then
|
||||
-- se non ha abbastanza energia, annullo
|
||||
if not (arena.players[p_name].energy >= energy) then return end
|
||||
arena.players[p_name].energy = arena.players[p_name].energy - energy
|
||||
end
|
||||
|
||||
local dir = player:get_look_dir()
|
||||
local rotate_factor = player:get_player_control().left and 1.57 or -1.57
|
||||
local dash_dir = vector.rotate_around_axis(dir, {x=0,y=1,z=0}, rotate_factor)
|
||||
|
||||
dash_dir.y = 0
|
||||
|
||||
player:add_velocity(vector.multiply(dash_dir, 20))
|
||||
block_league.sound_play("bl_sword_dash", p_name)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function can_use(player, energy)
|
||||
local meta = player:get_meta()
|
||||
if meta:get_int("bl_bouncer_delay") == 1 or
|
||||
meta:get_int("bl_death_delay") == 1 or
|
||||
meta:get_int("bl_reloading") == 1 or
|
||||
meta:get_int("bl_is_speed_locked") == 1 then return end
|
||||
|
||||
meta:set_int("bl_bouncer_delay", 1)
|
||||
|
||||
minetest.after(0.3, function()
|
||||
if not player then return end
|
||||
player:get_meta():set_int("bl_bouncer_delay", 0)
|
||||
end)
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue