add health bar, remove spread max health function as it is deprecated... hopefully

This commit is contained in:
bgkillas 2024-08-16 15:59:44 -04:00
parent cc8b8d0c6a
commit 28b7dd2a4b
6 changed files with 47 additions and 16 deletions

View file

@ -410,9 +410,22 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata)
end
GamePrint("Spawning player for "..peer_id)
local new = EntityLoad("mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_base.xml", x, y)
if ctx.proxy_opt.game_mode == "shared_health" then
local player_components = EntityGetAllComponents(new)
if player_components ~= nil then
for _, comp in ipairs(player_components) do
if ComponentHasTag(comp, "health_bar") or ComponentHasTag(comp, "health_bar_back") then
EntitySetComponentIsEnabled(new, comp, false)
end
end
end
end
if ctx.proxy_opt.friendly_fire then
GenomeSetHerdId(new, "player_pvp")
end
local new_playerdata = existing_playerdata or player_fns.make_playerdata_for(new, peer_id)
new_playerdata.entity = new
-- util.tpcall(nickname.addLabel, new, new_playerdata.name, "data/fonts/font_pixel_white.xml", 1)
@ -473,17 +486,6 @@ function player_fns.respawn_if_necessary()
end
end
function player_fns.spread_max_health()
if ctx.is_host then
local _, max_hp = util.get_ent_health(ctx.my_player.entity)
for peer_id, player_data in pairs(ctx.players) do
if peer_id ~= ctx.my_id then
util.set_ent_health(player_data.entity, {-1, max_hp})
end
end
end
end
function player_fns.is_inventory_open()
local player_entity = ctx.players[ctx.my_id].entity
local inventory_gui_comp = EntityGetFirstComponentIncludingDisabled(player_entity, "InventoryGuiComponent")

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -464,7 +464,7 @@
_enabled="0"
></SpriteComponent>
<SpriteComponent
<!-- <SpriteComponent
_tags="character,player_hat2_shadow"
alpha="1"
image_file="data/enemies_gfx/player_hat2_shadow.xml"
@ -475,7 +475,7 @@
z_index="0.58"
_enabled="0"
></SpriteComponent>
-->
<LuaComponent
script_source_file="data/scripts/magic/amulet.lua"
execute_on_added="1"
@ -619,4 +619,4 @@
<BossHealthBarComponent gui_max_distance_visible="1500" gui="1"/>
<LuaComponent _tags="ew_remove_on_send" script_wand_fired = "mods/quant.ew/files/resource/cbs/count_times_wand_fired.lua"/>
</Entity>
</Entity>

View file

@ -576,6 +576,36 @@
value_string=""
/>
<SpriteComponent
_tags = "health_bar_back,ui,no_hitbox"
has_special_scale = "1"
image_file = "mods/quant.ew/files/resource/health_slider_back.png"
offset_x = "5"
offset_y = "-11"
special_scale_y = "0.45"
alpha = "0.4"
z_index = "-9000"
never_ragdollify_on_death = "1"
>
</SpriteComponent>
<SpriteComponent
_tags= "health_bar,ui,no_hitbox"
has_special_scale= "1"
image_file = "mods/quant.ew/files/resource/health_slider_front.png"
offset_x = "5"
offset_y = "-11"
special_scale_y = "0.45"
z_index = "-9001"
never_ragdollify_on_death = "1"
>
</SpriteComponent>
<BossHealthBarComponent
gui="0"
in_world="1">
</BossHealthBarComponent>
<Entity name="chunk_loader">
<Base file="mods/quant.ew/files/resource/entities/chunk_loader.xml">
</Base>
@ -600,4 +630,4 @@
></SpriteComponent>
</Entity>
<Entity name="inventory_quick">
</Entity>
</Entity>

View file

@ -221,7 +221,6 @@ local function on_world_pre_update_inner()
if GameGetFrameNum() % 120 == 0 then
player_fns.respawn_if_necessary()
player_fns.spread_max_health()
end
if ctx.events.new_player_just_connected or ctx.events.inventory_maybe_just_changed or (GameGetFrameNum() % 5 == 0 and inventory_helper.has_inventory_changed(ctx.my_player)) then