Spectate: right-click to change subject counterwise (closes #188)
This commit is contained in:
parent
c4c46427d8
commit
06696cbb6c
@ -186,7 +186,7 @@ end
|
||||
-- find next spectatatable target
|
||||
----------------------------
|
||||
|
||||
function arena_lib.find_and_spectate_player(sp_name, change_team)
|
||||
function arena_lib.find_and_spectate_player(sp_name, change_team, go_counterwise)
|
||||
|
||||
local arena = arena_lib.get_arena_by_player(sp_name)
|
||||
|
||||
@ -247,9 +247,15 @@ function arena_lib.find_and_spectate_player(sp_name, change_team)
|
||||
players_amount = arena.players_amount
|
||||
end
|
||||
|
||||
local watching_ID = spectator:get_meta():get_int("arenalib_watchID")
|
||||
local new_ID = players_amount <= watching_ID and 1 or watching_ID + 1
|
||||
local mod = arena_lib.get_mod_by_player(sp_name)
|
||||
local current_ID = spectator:get_meta():get_int("arenalib_watchID")
|
||||
local new_ID
|
||||
|
||||
if go_counterwise then
|
||||
new_ID = current_ID == 1 and players_amount or current_ID - 1
|
||||
else
|
||||
new_ID = players_amount <= current_ID and 1 or current_ID + 1
|
||||
end
|
||||
|
||||
-- trovo il giocatore da seguire
|
||||
-- squadre:
|
||||
@ -280,7 +286,7 @@ end
|
||||
|
||||
|
||||
|
||||
function arena_lib.find_and_spectate_entity(mod, arena, sp_name)
|
||||
function arena_lib.find_and_spectate_entity(mod, arena, sp_name, go_counterwise)
|
||||
|
||||
local e_amount = arena.spectate_entities_amount
|
||||
|
||||
@ -303,11 +309,16 @@ function arena_lib.find_and_spectate_entity(mod, arena, sp_name)
|
||||
end
|
||||
|
||||
local current_ID = spectator:get_meta():get_int("arenalib_watchID")
|
||||
local new_ID = e_amount <= current_ID and 1 or current_ID + 1
|
||||
local new_ID
|
||||
|
||||
if go_counterwise then
|
||||
new_ID = current_ID == 1 and e_amount or current_ID - 1
|
||||
else
|
||||
new_ID = e_amount <= current_ID and 1 or current_ID + 1
|
||||
end
|
||||
|
||||
local i = 1
|
||||
|
||||
for en_name, _ in pairs(entities_storage[mod][arena_name]) do
|
||||
|
||||
if i == new_ID then
|
||||
set_spectator(mod, arena_name, spectator, "entity", en_name, i)
|
||||
return true
|
||||
@ -342,11 +353,16 @@ function arena_lib.find_and_spectate_area(mod, arena, sp_name)
|
||||
end
|
||||
|
||||
local current_ID = spectator:get_meta():get_int("arenalib_watchID")
|
||||
local new_ID = ar_amount <= current_ID and 1 or current_ID + 1
|
||||
local new_ID
|
||||
|
||||
if go_counterwise then
|
||||
new_ID = current_ID == 1 and ar_amount or current_ID - 1
|
||||
else
|
||||
new_ID = ar_amount <= current_ID and 1 or current_ID + 1
|
||||
end
|
||||
|
||||
local i = 1
|
||||
|
||||
for pos_name, _ in pairs(areas_storage[mod][arena_name]) do
|
||||
|
||||
if i == new_ID then
|
||||
set_spectator(mod, arena_name, spectator, "area", pos_name, i)
|
||||
return true
|
||||
|
@ -7,13 +7,19 @@ minetest.register_tool("arena_lib:spectate_changeplayer", {
|
||||
description = S("Change player"),
|
||||
inventory_image = "arenalib_spectate_changeplayer.png",
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
on_place = function() end,
|
||||
on_drop = function() end,
|
||||
|
||||
on_use = function(itemstack, user)
|
||||
arena_lib.find_and_spectate_player(user:get_player_name())
|
||||
end
|
||||
end,
|
||||
|
||||
on_secondary_use = function(itemstack, user)
|
||||
arena_lib.find_and_spectate_player(user:get_player_name(), false, true)
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, user)
|
||||
arena_lib.find_and_spectate_player(user:get_player_name(), false, true)
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
@ -23,11 +29,9 @@ minetest.register_tool("arena_lib:spectate_changeteam", {
|
||||
description = S("Change team"),
|
||||
inventory_image = "arenalib_spectate_changeteam.png",
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
on_place = function() end,
|
||||
on_drop = function() end,
|
||||
|
||||
on_use = function(itemstack, user)
|
||||
|
||||
local p_name = user:get_player_name()
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
@ -35,8 +39,27 @@ minetest.register_tool("arena_lib:spectate_changeteam", {
|
||||
if arena_lib.get_active_teams(arena) == 1 then return end
|
||||
|
||||
arena_lib.find_and_spectate_player(p_name, true)
|
||||
end
|
||||
end,
|
||||
|
||||
on_secondary_use = function(itemstack, user)
|
||||
local p_name = user:get_player_name()
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
-- non far cambiare se c'è rimasto solo una squadra da seguire
|
||||
if arena_lib.get_active_teams(arena) == 1 then return end
|
||||
|
||||
arena_lib.find_and_spectate_player(p_name, true, true)
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, user)
|
||||
local p_name = user:get_player_name()
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
-- non far cambiare se c'è rimasto solo una squadra da seguire
|
||||
if arena_lib.get_active_teams(arena) == 1 then return end
|
||||
|
||||
arena_lib.find_and_spectate_player(p_name, true, true)
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
@ -46,18 +69,31 @@ minetest.register_tool("arena_lib:spectate_changeentity", {
|
||||
description = S("Change entity"),
|
||||
inventory_image = "arenalib_spectate_changeentity.png",
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
on_place = function() end,
|
||||
on_drop = function() end,
|
||||
|
||||
on_use = function(itemstack, user)
|
||||
|
||||
local p_name = user:get_player_name()
|
||||
local mod = arena_lib.get_mod_by_player(p_name)
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
arena_lib.find_and_spectate_entity(mod, arena, p_name)
|
||||
end
|
||||
end,
|
||||
|
||||
on_secondary_use = function(itemstack, user)
|
||||
local p_name = user:get_player_name()
|
||||
local mod = arena_lib.get_mod_by_player(p_name)
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
arena_lib.find_and_spectate_entity(mod, arena, p_name, true)
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, user)
|
||||
local p_name = user:get_player_name()
|
||||
local mod = arena_lib.get_mod_by_player(p_name)
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
arena_lib.find_and_spectate_entity(mod, arena, p_name, true)
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
@ -67,18 +103,31 @@ minetest.register_tool("arena_lib:spectate_changearea", {
|
||||
description = S("Change area"),
|
||||
inventory_image = "arenalib_spectate_changearea.png",
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
on_place = function() end,
|
||||
on_drop = function() end,
|
||||
|
||||
on_use = function(itemstack, user)
|
||||
|
||||
local p_name = user:get_player_name()
|
||||
local mod = arena_lib.get_mod_by_player(p_name)
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
arena_lib.find_and_spectate_area(mod, arena, p_name)
|
||||
end
|
||||
end,
|
||||
|
||||
on_secondary_use = function(itemstack, user)
|
||||
local p_name = user:get_player_name()
|
||||
local mod = arena_lib.get_mod_by_player(p_name)
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
arena_lib.find_and_spectate_area(mod, arena, p_name, true)
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, user)
|
||||
local p_name = user:get_player_name()
|
||||
local mod = arena_lib.get_mod_by_player(p_name)
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
arena_lib.find_and_spectate_area(mod, arena, p_name, true)
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
@ -98,7 +147,6 @@ minetest.register_tool("arena_lib:spectate_join", {
|
||||
|
||||
arena_lib.join_arena(mod, p_name, arena_ID)
|
||||
end
|
||||
|
||||
})
|
||||
|
||||
|
||||
@ -114,5 +162,4 @@ minetest.register_tool("arena_lib:spectate_quit", {
|
||||
on_use = function(itemstack, user)
|
||||
arena_lib.remove_player_from_arena(user:get_player_name(), 3)
|
||||
end
|
||||
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user