/kick command implemented

master
Zughy 2020-06-11 02:36:17 +02:00
parent 55810ac7e2
commit 56216a2c65
9 changed files with 91 additions and 50 deletions

View File

@ -151,7 +151,11 @@ The second field, on the contrary, is a table of parameters: they define the ver
> Beware: as you noticed, the hub spawn point is bound to the very minigame. In fact, there is no global spawn point as arena_lib could be used even in a survival server that wants to feature just a couple minigames. If you're looking for a hub manager because your goal is to create a full minigame server, have a look at my other mod [Hub Manager](https://gitlab.com/zughy-friends-minetest/hub-manager)
### 2.1 Commands
You need to connect the functions of the library with your mod in order to use them. The best way is with commands and again I suggest you the [ChatCmdBuilder](https://rubenwardy.com/minetest_modding_book/en/players/chat_complex.html) by rubenwardy. [This](https://gitlab.com/zughy-friends-minetest/minetest-quake/-/blob/master/commands.lua) is what I came up with in my Quake minigame, which relies on arena_lib. As you can see, I declared a `local mod = "quake"` at the beginning, because it's how I stored my mod inside the library. Also, I created the support for both the editor and the chat commands.
A couple of general commands are already declared inside arena_lib, them being:
* `/kick player_name`: kicks a player out of an ongoing game. The sender needs the `arenalib_admin` privilege in order to use it
* `/quit`: quits a game
Those aside, you need to connect a few functions with your mod in order to use them. The best way is with commands and again I suggest you the [ChatCmdBuilder](https://rubenwardy.com/minetest_modding_book/en/players/chat_complex.html) by rubenwardy. [This](https://gitlab.com/zughy-friends-minetest/minetest-quake/-/blob/master/commands.lua) is what I came up with in my Quake minigame, which relies on arena_lib. As you can see, I declared a `local mod = "quake"` at the beginning, because it's how I stored my mod inside the library. Also, I created the support for both the editor and the chat commands.
### 2.2 Callbacks
To customise your mod even more, there are a few empty callbacks you can use. They are:

53
api.lua
View File

@ -259,7 +259,7 @@ function arena_lib.create_arena(sender, mod, arena_name, min_players, max_player
-- aggiorno l'ID globale nello storage
storage:set_int(mod .. ".HIGHEST_ARENA_ID", mod_ref.highest_arena_ID)
minetest.chat_send_player(sender, mod_ref.prefix .. S("Arena @1 succesfully created", arena_name))
minetest.chat_send_player(sender, mod_ref.prefix .. S("Arena @1 successfully created", arena_name))
end
@ -998,44 +998,13 @@ function arena_lib.remove_player_from_arena(p_name, reason)
-- reason 2 = has been kicked
-- reason 3 = has quit the arena
local mod, arena_ID
local mod = arena_lib.get_mod_by_player(p_name)
-- se non è in partita né in coda, annullo
if arena_lib.is_player_in_arena(p_name) then
mod = players_in_game[p_name].minigame
arena_ID = players_in_game[p_name].arenaID
elseif arena_lib.is_player_in_queue(p_name) then
mod = players_in_queue[p_name].minigame
arena_ID = players_in_queue[p_name].arenaID
else
return end
-- se il giocatore non è né in coda né in partita, annullo
if not mod then return end
local mod_ref = arena_lib.mods[mod]
local arena = mod_ref.arenas[arena_ID]
if arena == nil then return end
-- se provo a rimuovere qualcuno durante la celebrazione, annullo
if arena.in_celebration then
minetest.chat_send_player(p_name, minetest.colorize("#e6482e" ,S("[!] You can't quit when a match is terminating!")))
return end
-- se uso /quit e on_prequit ritorna false, annullo
if reason == 3 and mod_ref.on_prequit then
if mod_ref.on_prequit(arena, p_name) == false then return end
end
-- lo rimuovo
arena.players[p_name] = nil
players_in_game[p_name] = nil
players_in_queue[p_name] = nil
arena.players_amount = arena.players_amount - 1
if #arena.teams > 1 then
local p_team_ID = arena.players[p_name].teamID
arena.players_amount_per_team[p_team_ID] = arena.players_amount_per_team[p_team_ID] - 1
end
arena_lib.update_sign(arena.sign, arena)
local arena = arena_lib.get_arena_by_player(p_name)
-- se una ragione è specificata
if reason ~= nil then
@ -1081,6 +1050,18 @@ function arena_lib.remove_player_from_arena(p_name, reason)
arena_lib.send_message_players_in_arena(arena, minetest.colorize("#f16a54", "<<< " .. p_name ))
end
-- lo rimuovo
arena.players[p_name] = nil
players_in_game[p_name] = nil
players_in_queue[p_name] = nil
arena.players_amount = arena.players_amount - 1
if #arena.teams > 1 then
local p_team_ID = arena.players[p_name].teamID
arena.players_amount_per_team[p_team_ID] = arena.players_amount_per_team[p_team_ID] - 1
end
arena_lib.update_sign(arena.sign, arena)
-- se l'arena era in coda e ora ci son troppi pochi giocatori, annullo la coda
if arena.in_queue then

View File

@ -2,15 +2,61 @@ local S = minetest.get_translator("arena_lib")
minetest.register_chatcommand("kick", {
description = S("Kick a player from an ongoing game"),
privs = {
arenalib_admin = true,
},
func = function(sender, param)
local p_name = string.match(param, "^([%a%d_-]+)$")
-- se non è specificato niente, annullo
if not p_name then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Unknown parameter!")))
return false end
-- se il giocatore non è online, annullo
if not minetest.get_player_by_name(p_name) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] This player is not online!")))
return false end
-- se il giocatore non è in partita, annullo
if not arena_lib.is_player_in_arena(p_name) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e" ,S("[!] The player must be in a game to perform this action!")))
return false end
minetest.chat_send_player(sender, S("Player successfully kicked"))
arena_lib.remove_player_from_arena(p_name, 2)
return true
end
})
minetest.register_chatcommand("quit", {
description = S("Quit an ongoing game"),
func = function(name, param)
if not arena_lib.is_player_in_arena(name) then
minetest.chat_send_player(name, minetest.colorize("#e6482e" ,S("[!] You're not in a match!")))
minetest.chat_send_player(name, minetest.colorize("#e6482e" , S("[!] You must be in a game to perform this action!")))
return false end
local arena = arena_lib.get_arena_by_player(name)
-- se è l'ultimo giocatore rimasto, annullo
if arena.players_amount == 1 then
minetest.chat_send_player(p_name, minetest.colorize("#e6482e" ,S("[!] You can't perform this action if you're the only one left!")))
return end
-- se uso /quit e on_prequit ritorna false, annullo
if mod_ref.on_prequit then
if mod_ref.on_prequit(arena, p_name) == false then
return false end
end
arena_lib.remove_player_from_arena(name, 3)
return true
end

View File

@ -1,4 +1,4 @@
local version = "3.0.0"
local version = "3.1.0"
dofile(minetest.get_modpath("arena_lib") .. "/api.lua")
dofile(minetest.get_modpath("arena_lib") .. "/callbacks.lua")
@ -7,6 +7,7 @@ dofile(minetest.get_modpath("arena_lib") .. "/debug_utilities.lua")
dofile(minetest.get_modpath("arena_lib") .. "/hud.lua")
dofile(minetest.get_modpath("arena_lib") .. "/items.lua")
dofile(minetest.get_modpath("arena_lib") .. "/player_manager.lua")
dofile(minetest.get_modpath("arena_lib") .. "/privs.lua")
dofile(minetest.get_modpath("arena_lib") .. "/signs.lua")
dofile(minetest.get_modpath("arena_lib") .. "/utils.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_edit_tools/editor_main.lua")

View File

@ -6,7 +6,7 @@
# api.lua
[!] An arena with that name exists already!=[!] Esiste già un'arena con quel nome!
[!] Parameters don't seem right!=[!] I parametri hanno qualcosa che non va!
Arena @1 succesfully created=Arena @1 creata con successo
Arena @1 successfully created=Arena @1 creata con successo
Arena @1 successfully removed=Arena @1 rimossa con successo
[!] This team doesn't exist!=[!] Questo team non esiste!
[!] No spawner with that ID to overwrite!=[!] Nessuno spawner con quell'ID da sovrascrivere!
@ -35,7 +35,6 @@ Arena @1 successfully enabled=Arena @1 abilitata con successo
Arena @1 successfully disabled=Arena @1 disabilitata con successo
@1 wins the game=@1 ha vinto la partita
Team @1 wins the game=La squadra @1 ha vinto la partita
[!] You can't quit when a match is terminating!=[!] Non puoi abbandonare durante il concludersi di un match!
@1 has been eliminated=@1 è stato eliminato
@1 has been kicked=@1 è stato cacciato
@1 has quit the match=@1 ha abbandonato la partita
@ -46,8 +45,12 @@ You're the last player standing: you win!=Sei l'ultimo giocatore rimasto in part
You win the game due to not enough players=Hai vinto la partita per troppi pochi giocatori
# chat.lua
Kick a player from an ongoing game=Caccia un giocatore da una partita in corso
[!] This player is not online!=[!] Questo giocatore non è online!
[!] The player must be in a game to perform this action!=[!] Il giocatore deve essere in partita per eseguire questa azione!
[!] You must be in a game to perform this action!=[!] Devi essere in partita per eseguire questa azione!
Quit an ongoing game=Abbandona una partita in corso
[!] You're not in a match!=[!] Non sei in partita!
[!] You can't perform this action if you're the only one left!=[!] Non puoi eseguire quest'azione se sei l'unico giocatore rimasto!
# debug_utilities.lua
name: =nome:

View File

@ -6,7 +6,7 @@
# api.lua
[!] An arena with that name exists already!=
[!] Parameters don't seem right!=
Arena @1 succesfully created=
Arena @1 successfully created=
Arena @1 successfully removed=
[!] This team doesn't exist!=
[!] No spawner with that ID to overwrite!=
@ -35,7 +35,6 @@ Arena @1 successfully enabled=
Arena @1 successfully disabled=
@1 wins the game=
Team @1 wins the game=
[!] You can't quit when a match is terminating!=
@1 has been eliminated=
@1 has been kicked=
@1 has quit the match=
@ -46,8 +45,12 @@ You're the last player standing: you win!=
You win the game due to not enough players=
# chat.lua
Kick a player from an ongoing game=
[!] This player is not online!=
[!] The player must be in a game to perform this action!=
[!] You must be in a game to perform this action!=
Quit an ongoing game=
[!] You're not in a match!=
[!] You can't perform this action if you're the only one left!=
# debug_utilities.lua
name: =

View File

@ -24,8 +24,13 @@ minetest.register_on_leaveplayer(function(player)
local p_name = player:get_player_name()
arena_lib.remove_player_from_arena(p_name)
arena_lib.quit_editor(player)
if arena_lib.is_player_in_arena(p_name) or arena_lib.is_player_in_queue(p_name) then
arena_lib.remove_player_from_arena(p_name)
end
if arena_lib.is_player_in_edit_mode(p_name) then
arena_lib.quit_editor(player)
end
end)

1
privs.lua Normal file
View File

@ -0,0 +1 @@
minetest.register_privilege("arenalib_admin", {})

View File

@ -1,6 +1,3 @@
--
-- For the item to set signs, being a declaration of a new item, look at items.lua
--
local S = minetest.get_translator("arena_lib")
local function assign_team() end