Skip to content

Commit

Permalink
fix some more errors, move some stuff from globals to crosscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
bgkillas committed Dec 7, 2024
1 parent f908cf7 commit ac98103
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
4 changes: 2 additions & 2 deletions quant.ew/files/resource/cbs/item_notify.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function throw_item()
GlobalsSetValue("ew_thrown", tostring(GetUpdatedEntityID()))
CrossCall("ew_thrown", GetUpdatedEntityID())
end

function item_pickup()
Expand All @@ -8,5 +8,5 @@ function item_pickup()
if com ~= nil then
ComponentSetValue2(com, "permanently_attached", false)
end
GlobalsSetValue("ew_picked", tostring(ent))
CrossCall("ew_picked", ent)
end
46 changes: 21 additions & 25 deletions quant.ew/files/system/item_sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,6 @@ function item_sync.make_item_global(item, instant, give_authority_to)
end
end

local function get_global_ent(key)
local val = tonumber(GlobalsGetValue(key, "0"))
GlobalsSetValue(key, "0")
if val ~= 0 then
return val
end
end

local function remove_client_items_from_world()
if GameGetFrameNum() % 5 ~= 3 then
return
Expand Down Expand Up @@ -446,6 +438,27 @@ local function send_item_positions(all)
dead_entities = {}
end

util.add_cross_call("ew_thrown", function(thrown_item)
if thrown_item ~= nil
and (item_sync.get_global_item_id(thrown_item) == nil or item_sync.is_my_item(item_sync.get_global_item_id(thrown_item)))
and EntityGetFirstComponentIncludingDisabled(thrown_item, "VariableStorageComponent", "ew_egg") == nil then
item_sync.make_item_global(thrown_item)
end
end)

util.add_cross_call("ew_picked", function(picked_item)
if picked_item ~= nil and EntityHasTag(picked_item, "ew_global_item") then
local gid = item_sync.get_global_item_id(picked_item)
if gid ~= nil then
if ctx.is_host then
item_sync.host_localize_item(gid, ctx.my_id)
else
rpc.item_localize_req(gid)
end
end
end
end)

function item_sync.on_world_update()
-- TODO check that we not removing item we are going to pick now, instead of checking if picker gui is open.
if is_safe_to_remove() then
Expand Down Expand Up @@ -489,24 +502,7 @@ function item_sync.on_world_update()
if GameGetFrameNum() % 5 == 4 then
mark_in_inventory(ctx.my_player)
end
local thrown_item = get_global_ent("ew_thrown")
if thrown_item ~= nil
and (item_sync.get_global_item_id(thrown_item) == nil or item_sync.is_my_item(item_sync.get_global_item_id(thrown_item)))
and EntityGetFirstComponentIncludingDisabled(thrown_item, "VariableStorageComponent", "ew_egg") == nil then
item_sync.make_item_global(thrown_item)
end

local picked_item = get_global_ent("ew_picked")
if picked_item ~= nil and EntityHasTag(picked_item, "ew_global_item") then
local gid = item_sync.get_global_item_id(picked_item)
if gid ~= nil then
if ctx.is_host then
item_sync.host_localize_item(gid, ctx.my_id)
else
rpc.item_localize_req(gid)
end
end
end
remove_client_items_from_world()
end

Expand Down
2 changes: 1 addition & 1 deletion quant.ew/files/system/local_health/local_health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ function module.on_world_update()
-- Restore the player back to small amount of hp.
local new_hp = 3 * max_hp_new / 20
if ctx.proxy_opt.no_notplayer then
new_hp = new_hp * 3
new_hp = new_hp * 5
end
local final_hp = math.max(new_hp, math.min(2/5, max_hp_new))
util.set_ent_health(ctx.my_player.entity, {final_hp, max_hp_new})
Expand Down
6 changes: 3 additions & 3 deletions quant.ew/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ function OnProjectileFired(shooter_id, projectile_id, initial_rng, position_x, p
np.SetProjectileSpreadRNG(rng)
end

--function OnProjectileFiredPost(shooter_id, projectile_id, rng, position_x, position_y, target_x, target_y, send_message,
-- unknown1, multicast_index, unknown3)
--end
function OnProjectileFiredPost(shooter_id, projectile_id, rng, position_x, position_y, target_x, target_y, send_message,
unknown1, multicast_index, unknown3)
end

function OnPausedChanged(paused, is_wand_pickup)
ctx.is_paused = paused
Expand Down

0 comments on commit ac98103

Please sign in to comment.