custom physics override

This commit is contained in:
Zughy 2020-10-28 15:00:38 +01:00
parent b5db1eecd2
commit a03304de14
2 changed files with 42 additions and 20 deletions

View File

@ -196,7 +196,6 @@ The second field, on the contrary, is a table of parameters: they define the ver
* `mod_ref.chat_team_prefix`: prefix for every message sent in the team chat. Default is `[team] ` (geolocalised)
* `mod_ref.chat_all_color`: color for every message sent in arena, team chat aside. Default is white (`"#ffffff"`)
* `mod_ref.chat_team_color`: color for every message sent in the team chat. Default is light sky blue (`"#ddfdff"`)
* `disabled_damage_types`: a table containing which damage types will be disabled once in a game. Damage types are strings, the same as in reason.type in the [minetest API](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L4414)
* `join_while_in_progress`: whether the minigame allows to join an ongoing match. Default is false
* `keep_inventory`: whether to keep players inventories when joining an arena. Default is false
* `show_nametags`: whether to show the players nametags while in game. Default is false
@ -208,6 +207,8 @@ The second field, on the contrary, is a table of parameters: they define the ver
* `queue_waiting_time`: the time to wait before the loading phase starts. It gets triggered when the minimium amount of players has been reached to start the queue. Default is 10
* `load_time`: the time between the loading state and the start of the match. Default is 3
* `celebration_time`: the time between the celebration state and the end of the match. Default is 3
* `in_game_physics`: an optional table containing a physical override to set to each player when they enter an arena
* `disabled_damage_types`: a table containing which damage types will be disabled once in a game. Damage types are strings, the same as in reason.type in the [minetest API](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt)
* `properties`: explained down below
* `temp_properties`: same
* `player_properties`: same

59
api.lua
View File

@ -81,7 +81,6 @@ function arena_lib.register_minigame(mod, def)
mod_ref.chat_team_prefix = "[" .. S("team") .. "] "
mod_ref.chat_all_color = "#ffffff"
mod_ref.chat_team_color = "#ddfdff"
mod_ref.disabled_damage_types = {}
mod_ref.join_while_in_progress = false
mod_ref.keep_inventory = false
mod_ref.show_nametags = false
@ -90,6 +89,8 @@ function arena_lib.register_minigame(mod, def)
mod_ref.queue_waiting_time = 10
mod_ref.load_time = 3 -- time in the loading phase (the pre-match)
mod_ref.celebration_time = 3 -- time in the celebration phase
mod_ref.in_game_physics = nil
mod_ref.disabled_damage_types = {}
mod_ref.properties = {}
mod_ref.temp_properties = {}
mod_ref.player_properties = {}
@ -131,10 +132,6 @@ function arena_lib.register_minigame(mod, def)
mod_ref.chat_all_color = def.chat_all_color
end
if def.disabled_damage_types and type(def.disabled_damage_types) == "table" then
mod_ref.disabled_damage_types = def.disabled_damage_types
end
if def.join_while_in_progress == true then
mod_ref.join_while_in_progress = def.join_while_in_progress
end
@ -167,6 +164,14 @@ function arena_lib.register_minigame(mod, def)
mod_ref.celebration_time = def.celebration_time
end
if def.in_game_physics and type(def.in_game_physics) == "table" then
mod_ref.in_game_physics = def.in_game_physics
end
if def.disabled_damage_types and type(def.disabled_damage_types) == "table" then
mod_ref.disabled_damage_types = def.disabled_damage_types
end
if def.properties then
mod_ref.properties = def.properties
end
@ -915,11 +920,6 @@ function arena_lib.load_arena(mod, arena_ID)
-- chiudo eventuali formspec
minetest.close_formspec(pl_name, "")
-- li blocco sul posto
player:set_physics_override({
speed = 0,
})
-- cambio eventuale colore texture (richiede i team)
if arena.teams_enabled and mod_ref.teams_color_overlay then
player:set_properties({
@ -936,6 +936,11 @@ function arena_lib.load_arena(mod, arena_ID)
end
end
-- imposto eventuale fisica personalizzata
if mod_ref.in_game_physics then
player:set_physics_override(mod_ref.in_game_physics)
end
-- teletrasporto i giocatori
if not arena.teams_enabled then
player:set_pos(shuffled_spawners[count].pos)
@ -978,15 +983,6 @@ function arena_lib.start_arena(mod_ref, arena)
arena.in_loading = false
arena_lib.update_sign(arena)
for pl_name, stats in pairs(arena.players) do
minetest.get_player_by_name(pl_name):set_physics_override({
speed = 1,
jump = 1,
gravity = 1,
})
end
-- parte l'eventuale tempo
if mod_ref.time_mode > 0 then
arena.current_time = arena.initial_time
@ -1043,6 +1039,11 @@ function arena_lib.join_arena(mod, p_name, arena_ID)
end
end
-- imposto eventuale fisica personalizzata
if mod_ref.in_game_physics then
player:set_physics_override(mod_ref.in_game_physics)
end
-- riempio HP, teletrasporto e aggiungo
player:set_hp(minetest.PLAYER_MAX_HP_DEFAULT)
player:set_pos(arena_lib.get_random_spawner(arena, arena.players[p_name].teamID))
@ -1131,6 +1132,16 @@ function arena_lib.end_arena(mod_ref, mod, arena)
if minetest.get_modpath("hub_manager") then
hub_manager.set_items(player)
hub_manager.set_hub_physics(player)
else
-- TODO 4.2: parametro personalizzato tramite /arenasettings
player:set_physics_override({
speed = 1,
jump = 1,
gravity = 1,
sneak = true,
sneak_glitch = false,
new_move = true
})
end
-- riattivo la minimappa eventualmente disattivata
@ -1336,6 +1347,16 @@ function arena_lib.remove_player_from_arena(p_name, reason, executioner)
if minetest.get_modpath("hub_manager") then
hub_manager.set_items(minetest.get_player_by_name(p_name))
hub_manager.set_hub_physics(player)
else
-- TODO 4.2: parametro personalizzato tramite /arenasettings
player:set_physics_override({
speed = 1,
jump = 1,
gravity = 1,
sneak = true,
sneak_glitch = false,
new_move = true
})
end
-- resetto la minimappa eventualmente disattivata