on_disconnect() callback implemented

master
Marco 2020-06-13 10:49:54 +02:00
parent 4a492de7b4
commit 4bb6cc59f7
3 changed files with 13 additions and 7 deletions

10
DOCS.md
View File

@ -171,9 +171,10 @@ To customise your mod even more, there are a few empty callbacks you can use. Th
* `arena_lib.on_timer_tick(mod, function(arena))`: called every second inside the arena if there is a timer and it's greater than 0
* `arena_lib.on_timeout(mod, function(arena))`: called when the timer of an arena, if exists, reaches 0
* `arena_lib.on_eliminate(mod, function(arena, p_name))`: called when a player is eliminated (see `arena_lib.remove_player_from_arena(...)`)
* `arena_lib.on_kick(mod, function(arena, p_name))`: called when a player is kicked from an arena (same as above)
* `arena_lib.on_quit(mod, function(arena, p_name))`: called when a player quits from an arena (same as above)
* `arena_lib.on_kick(mod, function(arena, p_name))`: called when a player is kicked from a match (same as above)
* `arena_lib.on_quit(mod, function(arena, p_name))`: called when a player quits from a match (same as above)
* `arena_lib.on_prequit(mod, function(arena, p_name))`: called when a player tries to quit. If it returns false, quit is cancelled. Useful ie. to ask confirmation first, or simply impede a player to quit
* `arena_lib.on_disconnect(mod, function(arena, p_name))`: called when a player disconnects while in a match
> Beware: there is a default behaviour already for most of these situations: for instance when a player dies, its deaths increase by 1. These callbacks exist just in case you want to add some extra behaviour to arena_lib's.
@ -253,10 +254,11 @@ There are also some other functions which might turn useful. They are:
* `arena_lib.is_player_in_same_team(arena, p_name, t_name)`: compares two players teams by the players names. Returns true if on the same team, false if not
* `arena_lib.is_team_declared(mod_ref, team_name)`: returns true if there is a team called `team_name`. Otherwise it returns false
* `arena_lib.remove_player_from_arena(p_name, <reason>)`: removes the player from the arena and it brings back the player to the lobby if still online. Reason is an int, and if specified equals to...
* `0`: player disconnected. Calls `on_disconnect`
* `1`: player eliminated. Calls `on_eliminate`
* `2`: player kicked. Calls `on_kick`
* `3`: player quit. Calls `on_quit`
Kicks and quits are automatically managed by arena_lib, so in this case it's better to use callbacks
* `3`: player quit. Calls `on_quit`
Default is 0 and these are mostly hardcoded in arena_lib already, so it's advised to not touch it and to use callbacks. The only exception is in case of manual elimination (ie. in a murder minigame, so reason = 1)
* `arena_lib.send_message_players_in_arena(arena, msg)`: send a message to all the players in that specific arena
* `arena_lib.immunity(player)`: grants immunity to the specified player. It lasts till the `immunity_time` declared in `arena_lib.register_minigame`

View File

@ -998,6 +998,7 @@ end
function arena_lib.remove_player_from_arena(p_name, reason)
-- reason 0 = has disconnected
-- reason 1 = has been eliminated
-- reason 2 = has been kicked
-- reason 3 = has quit the arena
@ -1011,7 +1012,7 @@ function arena_lib.remove_player_from_arena(p_name, reason)
local arena = arena_lib.get_arena_by_player(p_name)
-- se una ragione è specificata
if reason ~= nil then
if reason ~= 0 then
local player = minetest.get_player_by_name(p_name)
@ -1050,8 +1051,10 @@ function arena_lib.remove_player_from_arena(p_name, reason)
end
end
else
--TODO: considerare se rimuovere questo avviso dato che il server avvisa di base i giocatori
arena_lib.send_message_players_in_arena(arena, minetest.colorize("#f16a54", "<<< " .. p_name ))
if mod_ref.on_disconnect then
mod_ref.on_disconnect(arena, p_name)
end
end
-- lo rimuovo

View File

@ -20,12 +20,13 @@ minetest.register_on_joinplayer(function(player)
end)
minetest.register_on_leaveplayer(function(player)
local p_name = player:get_player_name()
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)
arena_lib.remove_player_from_arena(p_name, 0)
end
if arena_lib.is_player_in_edit_mode(p_name) then