dont leave floating capes when other player mvoes out of range

This commit is contained in:
bgkillas 2024-10-15 17:28:26 -04:00
parent 2f7230377c
commit 77c4faeced
2 changed files with 27 additions and 1 deletions

View file

@ -29,7 +29,8 @@ function player_color(player_entity)
EntityKill(cape)
local player_cape_sprite_file = "mods/quant.ew/files/system/player/tmp/" .. ctx.my_id .. "_cape.xml"
local cape2 = EntityLoad(player_cape_sprite_file, 0, 0)
local x, y = EntityGetTransform(ctx.my_player.entity)
local cape2 = EntityLoad(player_cape_sprite_file, x, y)
EntityAddChild( player_entity, cape2 )
end

View file

@ -61,6 +61,31 @@ function module.on_world_update()
rpc.check_gamemode(np.GetGameModeName(n))
end
end
if GameGetFrameNum() % 16 == 7 then
local mx, my = GameGetCameraPos()
for peer_id, player in pairs(ctx.players) do
local ent = player.entity
local x, y = EntityGetTransform(ent)
local dx, dy = x - mx, y - my
local cape
for _, child in ipairs(EntityGetAllChildren(ent) or {}) do
if EntityGetName(child) == "cape" then
cape = child
break
end
end
if dx * dx + dy * dy > 300 * 300 then
if cape ~= nil then
EntityKill(cape)
end
elseif cape == nil then
local player_cape_sprite_file = "mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_cape.xml"
local cape2 = EntityLoad(player_cape_sprite_file, x, y)
EntityAddChild(ent, cape2)
end
end
end
end
return module