Custom camera offset per minigame

This commit is contained in:
Zughy 2020-12-17 15:33:50 +01:00
parent 1db52592b3
commit 4aedde4887
2 changed files with 19 additions and 1 deletions

View File

@ -55,6 +55,7 @@ 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"`)
* `mod_ref.camera_offset`: change the offset of the camera for evey player. It's structured as such: `{1st_person, 3rd_person}`, e.g. `{nil, {x=5, y=3, z=-4}}`
* `mod_ref.hotbar`: a table to override the server hotbar while inside an arena. Its fields are:
* `slots =`: (int) the number of slots
* `background_image =`: (string) the background image

19
api.lua
View File

@ -24,7 +24,8 @@ local function time_start() end
local players_in_game = {} -- KEY: player name, VALUE: {(string) minigame, (int) arenaID}
local players_in_queue = {} -- KEY: player name, VALUE: {(string) minigame, (int) arenaID}
local players_temp_storage = {} -- KEY: player_name, VALUE: {(int) hotbar_slots, (string) hotbar_background_image, (string) hotbar_selected_image, (int) bgm_handle}
local players_temp_storage = {} -- KEY: player_name, VALUE: {(int) hotbar_slots, (string) hotbar_background_image, (string) hotbar_selected_image,
-- (int) bgm_handle, (table) camera_offset}
local arena_default = {
name = "",
@ -99,6 +100,7 @@ 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.camera_offset = nil
mod_ref.hotbar = nil
mod_ref.join_while_in_progress = false
mod_ref.keep_inventory = false
@ -146,6 +148,10 @@ function arena_lib.register_minigame(mod, def)
mod_ref.chat_all_color = def.chat_all_color
end
if def.camera_offset and type(def.camera_offset) == "table" then
mod_ref.camera_offset = def.camera_offset
end
if def.hotbar and type(def.hotbar) == "table" then
mod_ref.hotbar = {}
mod_ref.hotbar.slots = def.hotbar.slots
@ -1975,6 +1981,12 @@ function operations_before_entering_arena(mod_ref, mod, arena, arena_ID, p_name)
local player = minetest.get_player_by_name(p_name)
-- applico eventuale scostamento camera
if mod_ref.camera_offset then
players_temp_storage[p_name].camera_offset = player:get_eye_offset()
player:set_eye_offset(mod_ref.camera_offset[1], mod_ref.camera_offset[2])
end
-- nascondo i nomi se l'opzione è abilitata
if not mod_ref.show_nametags then
player:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}})
@ -2078,6 +2090,11 @@ function operations_before_leaving_arena(mod_ref, arena, p_name)
end
end
-- resetto eventuale camera
if mod_ref.camera_offset then
player:set_eye_offset(players_temp_storage[p_name].camera_offset[1], players_temp_storage[p_name].camera_offset[2])
end
-- resetto gli HP e teletrasporto fuori dall'arena e
player:set_hp(minetest.PLAYER_MAX_HP_DEFAULT)
player:set_pos(mod_ref.settings.hub_spawn_point)