mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-29 07:23:01 +00:00
Nametags update (#385)
* Slight Nametags update Made Nametags not render if behind camera * Optimizations and commands rework * Update nametags.lua
This commit is contained in:
parent
3ab4c944ac
commit
89fa4fbe5b
1 changed files with 46 additions and 15 deletions
|
@ -115,6 +115,14 @@ local function name_without_hex(name)
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function split(s)
|
||||||
|
local result = {}
|
||||||
|
for match in (s):gmatch(string.format("[^%s]+", " ")) do
|
||||||
|
table.insert(result, match)
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
local function on_hud_render()
|
local function on_hud_render()
|
||||||
if gGlobalSyncTable.dist == 0 or (not showSelfTag and network_player_connected_count() == 1) or not gNetworkPlayers[0].currAreaSyncValid or obj_get_first_with_behavior_id(id_bhvActSelector) ~= nil then return end
|
if gGlobalSyncTable.dist == 0 or (not showSelfTag and network_player_connected_count() == 1) or not gNetworkPlayers[0].currAreaSyncValid or obj_get_first_with_behavior_id(id_bhvActSelector) ~= nil then return end
|
||||||
|
|
||||||
|
@ -123,13 +131,11 @@ local function on_hud_render()
|
||||||
|
|
||||||
for i = if_then_else(showSelfTag, 0, 1), (MAX_PLAYERS - 1) do
|
for i = if_then_else(showSelfTag, 0, 1), (MAX_PLAYERS - 1) do
|
||||||
local m = gMarioStates[i]
|
local m = gMarioStates[i]
|
||||||
if m.marioBodyState.updateTorsoTime == gMarioStates[0].marioBodyState.updateTorsoTime and active_player(m) ~= 0 and m.action ~= ACT_IN_CANNON and (m.playerIndex ~= 0 or (m.playerIndex == 0 and m.action ~= ACT_FIRST_PERSON)) then
|
|
||||||
local out = { x = 0, y = 0, z = 0 }
|
local out = { x = 0, y = 0, z = 0 }
|
||||||
local pos = { x = m.marioObj.header.gfx.pos.x, y = m.pos.y + 210, z = m.marioObj.header.gfx.pos.z }
|
local pos = { x = m.marioObj.header.gfx.pos.x, y = m.pos.y + 210, z = m.marioObj.header.gfx.pos.z }
|
||||||
djui_hud_world_pos_to_screen_pos(pos, out)
|
if djui_hud_world_pos_to_screen_pos(pos, out) and m.marioBodyState.updateTorsoTime == gMarioStates[0].marioBodyState.updateTorsoTime and active_player(m) ~= 0 and m.action ~= ACT_IN_CANNON and (m.playerIndex ~= 0 or (m.playerIndex == 0 and m.action ~= ACT_FIRST_PERSON)) then
|
||||||
|
|
||||||
local scale = MAX_SCALE
|
local scale = MAX_SCALE
|
||||||
local dist = vec3f_dist(gMarioStates[0].pos, m.pos)
|
local dist = vec3f_dist(gLakituState.pos, m.pos)
|
||||||
if m.playerIndex ~= 0 and dist > 1000 then
|
if m.playerIndex ~= 0 and dist > 1000 then
|
||||||
scale = 0.5
|
scale = 0.5
|
||||||
scale = scale + dist / gGlobalSyncTable.dist
|
scale = scale + dist / gGlobalSyncTable.dist
|
||||||
|
@ -162,33 +168,58 @@ local function on_hud_render()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_nametag_distance_command(msg)
|
local function on_distance_command(msg)
|
||||||
|
if not network_is_server() and not network_is_moderator() then
|
||||||
|
djui_chat_message_create("\\#d86464\\You do not have permission to run this command.")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
local dist = tonumber(msg)
|
local dist = tonumber(msg)
|
||||||
if dist ~= nil then
|
if dist ~= nil then
|
||||||
djui_chat_message_create("Set nametag distance to " .. msg)
|
djui_chat_message_create("Set nametag distance to " .. msg)
|
||||||
gGlobalSyncTable.dist = dist
|
gGlobalSyncTable.dist = dist
|
||||||
return true
|
return true
|
||||||
|
else
|
||||||
|
djui_chat_message_create("/nametags \\#00ffff\\distance\\#ffff00\\ [number]\\#ffffff\\\nSets the distance at which nametags disappear,\ndefault is \\#ffff00\\7000\\#ffffff\\, \\#ffff00\\0\\#ffffff\\ turns nametags off")
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_show_health_command()
|
local function on_show_health_command(msg)
|
||||||
|
if msg == "?" then
|
||||||
|
djui_chat_message_create("/nametags \\#00ffff\\show-health\\#ffffff\\\nToggles showing health above the nametag, default is \\#00ff00\\ON")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
showHealth = not showHealth
|
showHealth = not showHealth
|
||||||
djui_chat_message_create("Show health status: " .. on_or_off(showHealth))
|
djui_chat_message_create("Show health status: " .. on_or_off(showHealth))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_show_tag_command()
|
local function on_show_tag_command(msg)
|
||||||
|
if msg == "?" then
|
||||||
|
djui_chat_message_create("/nametags \\#00ffff\\show-tag\\#ffffff\\\nToggles your own nametag on or off, default is \\#ff0000\\OFF")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
showSelfTag = not showSelfTag
|
showSelfTag = not showSelfTag
|
||||||
djui_chat_message_create("Show my tag status: " .. on_or_off(showSelfTag))
|
djui_chat_message_create("Show my tag status: " .. on_or_off(showSelfTag))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
hook_event(HOOK_ON_HUD_RENDER, on_hud_render)
|
local function on_nametags_command(msg)
|
||||||
|
local args = split(msg)
|
||||||
if network_is_server() then
|
if args[1] == "distance" then
|
||||||
hook_chat_command("nametag-distance", "[number] set the distance at which nametags disappear, default is 7000, 0 turns nametags off", on_nametag_distance_command)
|
return on_distance_command(args[2])
|
||||||
|
elseif args[1] == "show-health" then
|
||||||
|
return on_show_health_command(args[2])
|
||||||
|
elseif args[1] == "show-tag" then
|
||||||
|
return on_show_tag_command(args[2])
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
hook_chat_command("show-health", "to toggle showing health above the nametag, default is \\#00ff00\\ON", on_show_health_command)
|
hook_event(HOOK_ON_HUD_RENDER, on_hud_render)
|
||||||
hook_chat_command("show-tag", "to toggle your own nametag on or off, default is \\#ff0000\\OFF", on_show_tag_command)
|
|
||||||
|
hook_chat_command("nametags", "[show-tag|show-health|distance]", on_nametags_command)
|
||||||
|
|
Loading…
Reference in a new issue