+ Auto equip system now supports the drop picking
+ Fixed drops reset system not working if the entity was unloaded + Preventing disabling the arena if it is resettingmaster
parent
bbeb109091
commit
fe07f4243e
|
@ -33,6 +33,7 @@ end)
|
|||
|
||||
arena_lib.on_start("skywars", function(arena)
|
||||
arena.players_original_amount = arena.players_amount
|
||||
arena.match_id = math.random(1, 9999999999)
|
||||
|
||||
skywars.place_chests(arena)
|
||||
|
||||
|
@ -173,6 +174,17 @@ end)
|
|||
|
||||
|
||||
|
||||
arena_lib.on_disable("skywars", function(arena, pl_name)
|
||||
if arena.is_resetting then
|
||||
skywars.print_error(pl_name, skywars.T("@1 is being reset!", arena.name))
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end)
|
||||
|
||||
|
||||
|
||||
arena_lib.on_time_tick("skywars", function(arena)
|
||||
skywars.kill_players_out_map(arena)
|
||||
skywars.update_timer_hud(arena)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
local function get_armor_importance() end
|
||||
local on_punch = minetest.registered_entities["__builtin:item"].on_punch
|
||||
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
|
@ -17,42 +18,77 @@ end
|
|||
|
||||
|
||||
|
||||
function skywars.auto_equip(player, armor_itemstack)
|
||||
local armor_name = armor_itemstack:get_name()
|
||||
local armor_element = armor:get_element(armor_name)
|
||||
-- A table containing pairs of [armor_element : string] = armor_name : string.
|
||||
local player_armor_elements = armor:get_weared_armor_elements(player)
|
||||
local equipped_armor = player_armor_elements[armor_element]
|
||||
local inventory = player:get_inventory()
|
||||
|
||||
if equipped_armor then
|
||||
local armor_importance = get_armor_importance(armor_name)
|
||||
local weared_armor_importance = get_armor_importance(equipped_armor)
|
||||
|
||||
if not armor_importance or not weared_armor_importance then return false end
|
||||
|
||||
-- Returning if the just taken armor is worse or as good as the equipped one.
|
||||
if armor_importance <= weared_armor_importance then return end
|
||||
end
|
||||
|
||||
armor:equip(player, armor_itemstack)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info)
|
||||
local pl_name = player:get_player_name()
|
||||
|
||||
if minetest.get_modpath("3d_armor") and arena_lib.is_player_in_arena(pl_name, "skywars") then
|
||||
-- The armor that the player's taking.
|
||||
local armor_itemstack = inventory_info.stack
|
||||
if not armor_itemstack then return end
|
||||
local armor_name = armor_itemstack:get_name()
|
||||
if not armor_itemstack then return end
|
||||
-- The body part that the armor's assigned to, returns nil if it's not an armor.
|
||||
local armor_element = armor:get_element(armor_name)
|
||||
local is_an_armor = armor:get_element(armor_name)
|
||||
|
||||
if action == "put" and armor_element then
|
||||
-- A table containing pairs of [armor_element : string] = armor_name : string.
|
||||
local player_armor_elements = armor:get_weared_armor_elements(player)
|
||||
local equipped_armor = player_armor_elements[armor_element]
|
||||
|
||||
if equipped_armor then
|
||||
local armor_importance = get_armor_importance(armor_name)
|
||||
local weared_armor_importance = get_armor_importance(equipped_armor)
|
||||
|
||||
if not armor_importance or not weared_armor_importance then return end
|
||||
|
||||
-- Returning if the just taken armor is worse or as good as the equipped one.
|
||||
if armor_importance <= weared_armor_importance then return end
|
||||
if action == "put" and is_an_armor then
|
||||
if skywars.auto_equip(player, armor_itemstack) then
|
||||
minetest.after(0, function()
|
||||
inventory:remove_item("main", ItemStack(armor_name))
|
||||
end)
|
||||
end
|
||||
|
||||
armor:equip(player, armor_itemstack)
|
||||
minetest.after(0, function()
|
||||
inventory:remove_item("main", ItemStack(armor_name))
|
||||
end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
-- Applying the auto equip system when somenone punches on a drop.
|
||||
minetest.registered_entities["__builtin:item"].on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||
local pos = self.object:get_pos()
|
||||
local pl_name = puncher:get_player_name()
|
||||
local arena = skywars.get_arena_by_pos(pos)
|
||||
|
||||
if minetest.get_modpath("3d_armor") and arena_lib.is_player_in_arena(pl_name, "skywars") then
|
||||
local item = ItemStack(self.itemstring)
|
||||
local is_an_armor = armor:get_element(self.itemstring)
|
||||
|
||||
if is_an_armor then
|
||||
if skywars.auto_equip(puncher, item) then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function get_armor_importance(armor_name)
|
||||
for material, importance in pairs(skywars_settings.armors_importances) do
|
||||
if armor_name:match(material) then
|
||||
|
|
|
@ -1,36 +1,37 @@
|
|||
local function delete_drops() end
|
||||
local function async_reset_map() end
|
||||
local function reset_node_inventory() end
|
||||
local on_step = minetest.registered_entities["__builtin:item"].on_step
|
||||
minetest.registered_entities["__builtin:item"].match_id = -2
|
||||
|
||||
|
||||
function skywars.reset_map(arena, debug, debug_data)
|
||||
if not arena.enabled or arena.is_resetting then return end
|
||||
|
||||
skywars.load_mapblocks(arena)
|
||||
delete_drops(arena)
|
||||
async_reset_map(arena, debug, debug_data)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function delete_drops(arena)
|
||||
local min_pos, max_pos = skywars.reorder_positions(arena.min_pos, arena.max_pos)
|
||||
local distance_from_center = vector.distance(min_pos, max_pos) / 2
|
||||
local map_center = {
|
||||
x = (min_pos.x + max_pos.x) / 2,
|
||||
y = (min_pos.y + max_pos.y) / 2,
|
||||
z = (min_pos.z + max_pos.z) / 2
|
||||
}
|
||||
|
||||
for i, obj in pairs(minetest.get_objects_inside_radius(map_center, distance_from_center)) do
|
||||
if not obj:is_player() then
|
||||
local props = obj:get_properties()
|
||||
local entity_texture = props.textures[1]
|
||||
if props.automatic_rotate > 0 and ItemStack(entity_texture):is_known() then
|
||||
obj:remove()
|
||||
end
|
||||
-- Removing drops based on the match_id.
|
||||
minetest.registered_entities["__builtin:item"].on_step = function(self, dtime, moveresult)
|
||||
local pos = self.object:get_pos()
|
||||
local arena = skywars.get_arena_by_pos(pos)
|
||||
|
||||
if arena and arena.match_id then
|
||||
if self.match_id == -2 then
|
||||
self.match_id = arena.match_id
|
||||
elseif self.match_id ~= arena.match_id then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
elseif arena then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
on_step(self, dtime, moveresult)
|
||||
end
|
||||
|
||||
|
||||
|
|
1
init.lua
1
init.lua
|
@ -15,6 +15,7 @@ arena_lib.register_minigame("skywars", {
|
|||
load_time = skywars_settings.loading_time,
|
||||
temp_properties = {
|
||||
players_original_amount = 0,
|
||||
match_id = -1,
|
||||
},
|
||||
properties = {
|
||||
chests = {},
|
||||
|
|
|
@ -50,7 +50,8 @@ Kits list:=Lista dei kit:
|
|||
@1 items:=Oggetti di @1:
|
||||
Kit not found!=Kit non trovato!
|
||||
x@1 @2 added to @3!=x@1 @2 aggiunto a @3!
|
||||
@1 reset!=@1 resettata!
|
||||
@1 reset!=@1 ripristinata!
|
||||
@1 kits have been copied to @2!=I kit di @1 sono stati copiati in @2!
|
||||
Nobody must be in the editor!=Nessuno deve essere nell'editor!
|
||||
The enabling process may take a few moments, please wait...=Il processo di abilitazione potrebbe richiedere del tempo, attendere...
|
||||
The enabling process may take a few moments, please wait...=Il processo di abilitazione potrebbe richiedere del tempo, attendere...
|
||||
@1 is being reset!=@1 è in fase di ripristino!
|
|
@ -53,4 +53,5 @@ x@1 @2 added to @3!=
|
|||
@1 reset!=
|
||||
@1 kits have been copied to @2!=
|
||||
Nobody must be in the editor!=
|
||||
The enabling process may take a few moments, please wait...=
|
||||
The enabling process may take a few moments, please wait...=
|
||||
@1 is being reset!=
|
14
utils.lua
14
utils.lua
|
@ -1,11 +1,11 @@
|
|||
function skywars.print_error(player, msg)
|
||||
minetest.chat_send_player(player, minetest.colorize("#e6482e", skywars_settings.prefix .. msg))
|
||||
function skywars.print_error(pl_name, msg)
|
||||
minetest.chat_send_player(pl_name, minetest.colorize("#e6482e", skywars_settings.prefix .. msg))
|
||||
end
|
||||
|
||||
|
||||
|
||||
function skywars.print_msg(player, msg)
|
||||
minetest.chat_send_player(player, skywars_settings.prefix .. msg)
|
||||
|
||||
|
||||
|
||||
function skywars.print_msg(pl_name, msg)
|
||||
minetest.chat_send_player(pl_name, skywars_settings.prefix .. msg)
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue