dont spectate dead players in end fight, spawn gold effect for everyone at end fight

This commit is contained in:
bgkillas 2024-09-27 09:06:18 -04:00
parent 92b8e049f3
commit 2adbdcdb66
3 changed files with 48 additions and 18 deletions

View file

@ -5,6 +5,7 @@ local wait_to_heal = false
local init = -1
local done = false
local kill_walls = false
local rpc = net.new_rpc_namespace()
ModTextFileSetContent("data/entities/animals/boss_centipede/ending/gold_effect.xml", "<Entity/>")
ModTextFileSetContent("data/entities/animals/boss_centipede/ending/midas_sand.xml", "<Entity/>")
@ -45,6 +46,11 @@ local function teleport_random()
EntitySetTransform(ctx.my_player.entity, x, y)
end
rpc.opts_everywhere()
function rpc.try_kill(x, y)
EntityLoad("mods/quant.ew/files/system/end_fight/gold_effect.xml", x, y )
end
function end_fight.on_world_update()
if GameHasFlagRun("ending_game_completed") and not done then
if kill_walls == GameGetFrameNum() then
@ -73,7 +79,6 @@ function end_fight.on_world_update()
LoadGameEffectEntityTo(ctx.my_player.entity, "mods/quant.ew/files/system/local_health/notplayer/safe_effect2.xml")
kill_walls = GameGetFrameNum() + 180
elseif init < GameGetFrameNum() and GameGetFrameNum() % 10 == 0 then
teleport_random()
local exists = false
for peer_id, playerdata in pairs(ctx.players) do
if peer_id ~= ctx.my_id and not EntityHasTag(playerdata.entity, "ew_notplayer") then
@ -91,7 +96,7 @@ function end_fight.on_world_update()
if not exists and not EntityHasTag(ctx.my_player.entity, "ew_notplayer") then
if try_kill <= GameGetFrameNum() then
local x, y = EntityGetTransform(ctx.my_player.entity)
EntityLoad("mods/quant.ew/files/system/end_fight/gold_effect.xml", x, y )
rpc.try_kill(x, y)
done = true
elseif try_kill == -1 then
try_kill = GameGetFrameNum() + 180

View file

@ -22,12 +22,19 @@ local has_switched = false
local function get_me()
local i = 0
for peer_id, _ in pairs(ctx.players) do
i = i + 1
if peer_id == ctx.my_id then
return i
local alive = -1, -1
for peer_id, potential_target in pairs(ctx.players) do
if GameHasFlagRun("ending_game_completed") and EntityHasTag(potential_target.entity, "ew_notplayer") then
goto continue
end
i = i + 1
alive = peer_id, i
if peer_id == ctx.my_id then
return peer_id, i
end
::continue::
end
return alive
end
local function target()
@ -58,7 +65,7 @@ local function target()
return
end
GameSetCameraFree(true)
if not EntityGetIsAlive(cam_target.entity) then
if cam_target == nil or not EntityGetIsAlive(cam_target.entity) then
return
end
local my_x, my_y = GameGetCameraPos()
@ -117,6 +124,9 @@ local function set_camera_pos()
if cam_target == nil or re_cam then
local i = 0
for peer_id, potential_target in pairs(ctx.players) do
if GameHasFlagRun("ending_game_completed") and EntityHasTag(potential_target.entity, "ew_notplayer") then
goto continue
end
i = i + 1
if i == camera_player then
cam_target = potential_target
@ -125,10 +135,10 @@ local function set_camera_pos()
camera_player_id = peer_id
break
end
::continue::
end
if cam_target == nil then
camera_player = get_me()
camera_player_id = ctx.my_id
camera_player_id, camera_player = get_me()
re_cam = true
set_camera_pos()
else
@ -141,22 +151,29 @@ end
local function update_i()
local i = 0
for peer_id, _ in pairs(ctx.players) do
for peer_id, potential_target in pairs(ctx.players) do
if GameHasFlagRun("ending_game_completed") and EntityHasTag(potential_target.entity, "ew_notplayer") then
goto continue
end
i = i + 1
if peer_id == camera_player_id then
camera_player = i
re_cam = true
return
end
::continue::
end
camera_player = get_me()
camera_player_id = ctx.my_id
camera_player_id, camera_player = get_me()
end
local function number_of_players()
local i = 0
for _, _ in pairs(ctx.players) do
for _, potential_target in pairs(ctx.players) do
if GameHasFlagRun("ending_game_completed") and EntityHasTag(potential_target.entity, "ew_notplayer") then
goto continue
end
i = i + 1
::continue::
end
return i
end
@ -168,13 +185,11 @@ function spectate.on_world_update()
was_notplayer = true
elseif was_notplayer then
was_notplayer = false
camera_player = get_me()
camera_player_id = ctx.my_id
camera_player_id, camera_player = get_me()
re_cam = true
end
if camera_player == nil then
camera_player = get_me()
camera_player_id = ctx.my_id
camera_player_id, camera_player = get_me()
re_cam = true
end
if last_len == nil then
@ -184,6 +199,13 @@ function spectate.on_world_update()
update_i()
last_len = number_of_players()
end
if cam_target ~= nil and GameHasFlagRun("ending_game_completed") and EntityHasTag(cam_target.entity, "ew_notplayer") then
update_i()
last_len = number_of_players()
end
if camera_player == -1 then
return
end
if InputIsKeyJustDown(54) or InputIsJoystickButtonJustDown(0, 13) then
camera_player = camera_player - 1

View file

@ -66,7 +66,7 @@ local function is_acceptable_help_target(spectating_over)
end
-- No helping notplayers
local player_data = ctx.players[spectating_over]
if player_data.status == nil or not player_data.status.is_alive then
if player_data == nil or player_data.status == nil or not player_data.status.is_alive then
return false
end
-- No helping polied players
@ -82,6 +82,9 @@ function module.on_local_player_polymorphed(_currently_polymorphed)
end
function module.on_world_update()
if GameHasFlagRun("ending_game_completed") then
return
end
local notplayer_active = GameHasFlagRun("ew_flag_notplayer_active")
if notplayer_active and ctx.spectating_over_peer_id ~= nil and is_acceptable_help_target(ctx.spectating_over_peer_id) then
spectating_which.set(ctx.spectating_over_peer_id)