Change min/max players in game (both editor and CLI) + small fixes

This commit is contained in:
Marco 2020-06-23 23:13:11 +02:00
parent 2ab59fbb9c
commit 8b97d83ab7
12 changed files with 180 additions and 10 deletions

View File

@ -2,6 +2,29 @@ local S = minetest.get_translator("arena_lib")
minetest.register_tool("arena_lib:editor_players", {
description = S("Players"),
inventory_image = "arenalib_editor_players.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user)
user:get_meta():set_int("arena_lib_editor.players_number", 2)
arena_lib.HUD_send_msg("hotbar", user:get_player_name(), S("Players | num to set: @1 (left/right click slot #3 to change)", 2))
minetest.after(0, function()
arena_lib.give_players_tools(user)
end)
end
})
minetest.register_tool("arena_lib:editor_spawners", {
description = S("Spawners"),

View File

@ -2,7 +2,7 @@ local S = minetest.get_translator("arena_lib")
local arenas_in_edit_mode = {} -- KEY: arena name; VALUE: name of the player inside the editor
local players_in_edit_mode = {} -- KEY: player name; VALUE: {inv (player old inventory), pos (player old position)}
local editor_tools = {
"",
"arena_lib:editor_players",
"arena_lib:editor_spawners",
"arena_lib:editor_signs",
"",
@ -44,8 +44,11 @@ function arena_lib.enter_editor(sender, mod, arena_name)
arenas_in_edit_mode[arena_name] = sender
players_in_edit_mode[sender] = { inv = player:get_inventory():get_list("main"), pos = player:get_pos()}
-- teletrasporto e mostro gli spawner
arena_lib.teleport_in_arena(sender, mod, arena_name)
-- se c'è almeno uno spawner, teletrasporto
if next(arena.spawn_points) then
arena_lib.teleport_in_arena(sender, mod, arena_name)
end
arena_lib.show_waypoints(sender, arena)
-- cambio l'inventario
@ -70,11 +73,13 @@ function arena_lib.quit_editor(player)
player:get_meta():set_string("arena_lib_editor.mod", "")
player:get_meta():set_string("arena_lib_editor.arena", "")
player:get_meta():set_string("arena_lib_editor.spawner_ID", "")
player:get_meta():set_int("arena_lib_editor.players_number", 0)
player:get_meta():set_int("arena_lib_editor.spawner_ID", 0)
player:get_meta():set_int("arena_lib_editor.team_ID", 0)
arena_lib.remove_waypoints(p_name)
-- se si è disconnesso mi fermo qua
-- se si è disconnesso, mi fermo qua
if not minetest.get_player_by_name(p_name) then return end
-- teletrasporto

99
_editor/tools_players.lua Normal file
View File

@ -0,0 +1,99 @@
local S = minetest.get_translator("arena_lib")
local players_tools = {
"arena_lib:players_min",
"arena_lib:players_max",
"arena_lib:players_change",
"",
"",
"",
"arena_lib:editor_return",
"arena_lib:editor_quit",
}
minetest.register_tool("arena_lib:players_min", {
description = S("Min amount of players"),
inventory_image = "arenalib_tool_players_min.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
local mod = user:get_meta():get_string("arena_lib_editor.mod")
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local players_amount = user:get_meta():get_int("arena_lib_editor.players_number")
arena_lib.change_players_amount(user:get_player_name(), mod, arena_name, players_amount, nil)
end
})
minetest.register_tool("arena_lib:players_max", {
description = S("Max amount of players"),
inventory_image = "arenalib_tool_players_max.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
local mod = user:get_meta():get_string("arena_lib_editor.mod")
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local players_amount = user:get_meta():get_int("arena_lib_editor.players_number")
arena_lib.change_players_amount(user:get_player_name(), mod, arena_name, nil, players_amount)
end
})
minetest.register_tool("arena_lib:players_change", {
description = S("Change the current number"),
inventory_image = "arenalib_tool_players_change.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
change_players_number(user, true)
end,
on_place = function(itemstack, placer, pointed_thing)
change_players_number(placer, false)
end
})
function arena_lib.give_players_tools(player)
player:get_inventory():set_list("main", players_tools)
end
----------------------------------------------
---------------FUNZIONI LOCALI----------------
----------------------------------------------
function change_players_number(player, decrease)
local players_number = player:get_meta():get_int("arena_lib_editor.players_number")
if not decrease then
players_number = players_number +1
else
if players_number > 1 then
players_number = players_number -1
else return end
end
player:get_meta():set_int("arena_lib_editor.players_number", players_number)
arena_lib.HUD_send_msg("hotbar", player:get_player_name(), S("Players | num to set: @1 (left/right click slot #3 to change)", players_number))
end

39
api.lua
View File

@ -214,7 +214,7 @@ function arena_lib.create_arena(sender, mod, arena_name, min_players, max_player
-- controllo che non abbiano messo parametri assurdi per i giocatori minimi/massimi
if min_players and max_players then
if min_players > max_players or min_players == 0 then
if min_players > max_players or min_players == 0 or max_players < 2 then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!")))
return end
end
@ -307,11 +307,44 @@ function arena_lib.rename_arena(sender, mod, arena_name, new_name)
local old_name = arena.name
arena.name = new_name
minetest.chat_send_player(sender, "Arena " .. old_name .. " rinominata con successo in " .. new_name)
-- aggiorno storage e cartello
update_storage(false, mod, id, arena)
arena_lib.update_sign(arena.sign, arena)
minetest.chat_send_player(sender, S("Arena @1 successfully renamed in @2", old_name, new_name))
end
function arena_lib.change_players_amount(sender, mod, arena_name, min_players, max_players)
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end
-- salvo i vecchi parametri così da poterne modificare anche solo uno senza if lunghissimi
local old_min_players = arena.min_players
local old_max_players = arena.max_players
arena.min_players = min_players or arena.min_players
arena.max_players = max_players or arena.max_players
-- se ha parametri assurdi, annullo
if arena.min_players > arena.max_players or arena.min_players == 0 or arena.max_players < 2 then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!")))
arena.min_players = old_min_players
arena.max_players = old_max_players
return end
-- svuoto i vecchi spawner per evitare problemi
arena_lib.set_spawner(sender, mod, arena_name, nil, "deleteall")
update_storage(false, mod, id, arena)
arena_lib.update_sign(arena.sign, arena)
minetest.chat_send_player(sender, arena_lib.mods[mod].prefix .. S("Players amount successfully changed ( min @1 | max @2 )", arena.min_players, arena.max_players))
end

View File

@ -1,4 +1,4 @@
local version = "3.1.0-dev"
local version = "3.2.0"
dofile(minetest.get_modpath("arena_lib") .. "/api.lua")
dofile(minetest.get_modpath("arena_lib") .. "/callbacks.lua")
@ -13,6 +13,7 @@ dofile(minetest.get_modpath("arena_lib") .. "/signs.lua")
dofile(minetest.get_modpath("arena_lib") .. "/utils.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_editor/editor_main.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_editor/editor_icons.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_editor/tools_players.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_editor/tools_sign.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_editor/tools_spawner.lua")

View File

@ -8,6 +8,8 @@
[!] Parameters don't seem right!=[!] I parametri hanno qualcosa che non va!
Arena @1 successfully created=Arena @1 creata con successo
Arena @1 successfully removed=Arena @1 rimossa con successo
Arena @1 successfully renamed in @2=Arena @1 rinominata con successo in @2
Players amount successfully changed ( min @1 | max @2 )=Numero dei giocatori modificato con successo ( min @1 | max @2 )
[!] This team doesn't exist!=[!] Questo team non esiste!
[!] No spawner with that ID to overwrite!=[!] Nessuno spawner con quell'ID da sovrascrivere!
[!] No team must be specified for this function!=[!] Non va specificato nessun team per questa funzione!
@ -119,6 +121,8 @@ Get ready!=Preparati!
Arena_lib editor | Now editing: @1=Arena_lib editor | Stai modificando: @1
# _editor/editor_icons.lua
Players=Giocatori
Players | num to set: @1 (left/right click slot #3 to change)=Giocatori | num: @1 (click sx/dx su slot #3 per cambiare)
Spawners=Spawner
Spawners | sel. ID: @1 (right click slot #2 to change)=Spawner | ID sel.: @1 (tasto dx su slot #2 per cambiare)
Signs=Cartelli

View File

@ -1,4 +1,4 @@
# version 3.1.0-dev
# version 3.2.0
# author(s):
# reviewer(s):
# textdomain: arena_lib
@ -8,6 +8,8 @@
[!] Parameters don't seem right!=
Arena @1 successfully created=
Arena @1 successfully removed=
Arena @1 successfully renamed in @2=
Players amount successfully changed ( min @1 | max @2 )=
[!] This team doesn't exist!=
[!] No spawner with that ID to overwrite!=
[!] No team must be specified for this function!=
@ -119,6 +121,8 @@ Get ready!=
Arena_lib editor | Now editing: @1=
# _editor/editor_icons.lua
Players=
Players | num to set: @1 (left/right click slot #3 to change)=
Spawners=
Spawners | sel. ID: @1 (right click slot #2 to change)=
Signs=

View File

@ -9,6 +9,7 @@ minetest.register_on_joinplayer(function(player)
p_meta:set_string("arena_lib_editor.mod", "")
p_meta:set_string("arena_lib_editor.arena", "")
p_meta:set_int("arena_lib_editor.players_number", 0)
p_meta:set_int("arena_lib_editor.spawner_ID", 0)
p_meta:set_int("arena_lib_editor.team_ID", 0)

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B