parameter 'teams_color_overlay' implemented, for better distinguish players in enemy teams

master
Zughy 2020-07-26 17:13:20 +02:00
parent e7ca4eb98f
commit c84985be8a
5 changed files with 39 additions and 6 deletions

View File

@ -143,9 +143,10 @@ arena_lib.register_minigame("yourmod", {parameter1, parameter2 etc})
```
"yourmod" is how arena_lib will store your mod inside its storage, and it's also what it needs in order to understand you're referring to that specific mod (that's why almost every `arena_lib` function contains "mod" as a parameter). You'll need it when calling for commands or callbacks.
The second field, on the contrary, is a table of parameters: they define the very features of your minigame. They are:
* `prefix`: what's going to appear in most of the lines printed by your mod. Default is `[arena_lib]`
* `prefix`: what's going to appear in most of the lines printed by your mod. Default is `[Arena_lib] `
* `hub_spawn_point`: where players will be teleported when a match _in your mod_ ends. Default is `{ x = 0, y = 20, z = 0 }`
* `teams`: a table of strings containing teams. If not declared, your minigame won't have teams and the table will be equal to `{-1}`. You can add as many teams as you like, as the number of spawners (and players) will be multiplied by the number of teams (so `max_players = 4` * 3 teams = `max_players = 12`)
* `teams_color_overlay`: a table of [color strings](https://drafts.csswg.org/css-color/#named-colors). It applies a color overlay onto the players' skin according to their team, to better distinguish them. It requires team. Default is none
* `is_team_chat_default`: whether players messages in a game should be sent to their teammates only. It requires `teams`, default is false
* `mod_ref.chat_all_prefix`: prefix for every message sent in arena, team chat aside. Default is none
* `mod_ref.chat_team_prefix`: prefix for every message sent in the team chat. Default is `[team] ` (geolocalised)

36
api.lua
View File

@ -70,6 +70,7 @@ function arena_lib.register_minigame(mod, def)
mod_ref.prefix = "[Arena_lib] "
mod_ref.hub_spawn_point = { x = 0, y = 20, z = 0}
mod_ref.teams = {}
mod_ref.teams_color_overlay = nil
mod_ref.is_team_chat_default = false
mod_ref.chat_all_prefix = ""
mod_ref.chat_team_prefix = "[" .. S("team") .. "] "
@ -103,6 +104,10 @@ function arena_lib.register_minigame(mod, def)
if def.teams and type(def.teams) == "table" then
mod_ref.teams = def.teams
if def.teams_color_overlay then
mod_ref.teams_color_overlay = def.teams_color_overlay
end
if def.is_team_chat_default == true then
mod_ref.is_team_chat_default = def.is_team_chat_default
end
@ -214,7 +219,6 @@ function arena_lib.update_properties(mod)
end
update_storage(false, mod, id, arena)
for temp_property, v in pairs(mod_ref.temp_properties) do
arena[temp_property] = v
end
@ -787,7 +791,7 @@ function arena_lib.load_arena(mod, arena_ID)
-- my child, let's talk about some black magic: in order to teleport players in their team spawners, first of all I need to
-- sort them by team. Once it's done, I need to skip every spawner of that team if the maximum number of players is not reached:
-- otherwise, people will find theirselves in the wrong team (and you don't want that to happen). So I use this int to prevent it,
-- which increases of 1 or more every time I look for a spawner, comparing the 'team' spawner value to the player's. This happens
-- which increases by 1 or more every time I look for a spawner, comparing the 'team' spawner value to the player's. This happens
-- in assign_team_spawner, which also returns the new value for team_count
local team_count = 1
@ -850,6 +854,13 @@ function arena_lib.load_arena(mod, arena_ID)
speed = 0,
})
-- cambio eventuale colore texture (richiede i team)
if arena.teams_enabled and mod_ref.teams_color_overlay then
player:set_properties({
textures = {player:get_properties().textures[1] .. "^[colorize:" .. mod_ref.teams_color_overlay[arena.players[pl_name].teamID] .. ":85"}
})
end
-- teletrasporto i giocatori
if not arena.teams_enabled then
player:set_pos(shuffled_spawners[count].pos)
@ -942,6 +953,13 @@ function arena_lib.join_arena(mod, p_name, arena_ID)
player:get_inventory():set_list("craft",{})
end
-- cambio eventuale colore texture (richiede i team)
if arena.teams_enabled and mod_ref.teams_color_overlay then
player:set_properties({
textures = {player:get_properties().textures[1] .. "^[colorize:" .. mod_ref.teams_color_overlay[arena.players[p_name].teamID] .. ":85"}
})
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))
@ -1033,6 +1051,13 @@ function arena_lib.end_arena(mod_ref, mod, arena)
player:get_inventory():set_list("craft",{})
end
-- resetto eventuali texture
if arena.teams_enabled and mod_ref.teams_color_overlay then
player:set_properties({
textures = {string.match(player:get_properties().textures[1], "(.*)^%[")}
})
end
-- teletrasporto nella lobby
player:set_pos(mod_ref.hub_spawn_point)
@ -1189,6 +1214,13 @@ function arena_lib.remove_player_from_arena(p_name, reason)
player:get_inventory():set_list("craft",{})
end
-- resetto eventuali texture
if arena.teams_enabled and mod_ref.teams_color_overlay then
player:set_properties({
textures = {string.match(player:get_properties().textures[1], "(.*)^%[")}
})
end
-- resetto gli HP, teletrasporto fuori dall'arena e ripristino nome
player:set_hp(minetest.PLAYER_MAX_HP_DEFAULT)
player:set_pos(mod_ref.hub_spawn_point)

View File

@ -1,4 +1,4 @@
local version = "3.4.0-dev"
local version = "3.4.0"
dofile(minetest.get_modpath("arena_lib") .. "/api.lua")
dofile(minetest.get_modpath("arena_lib") .. "/callbacks.lua")

View File

@ -1,4 +1,4 @@
# version 3.4.0-dev
# version 3.4.0
# author(s): Zughy
# reviewer(s):
# textdomain: arena_lib

View File

@ -1,4 +1,4 @@
# version 3.4.0-dev
# version 3.4.0
# author(s):
# reviewer(s):
# textdomain: arena_lib