add some nil checks

This commit is contained in:
bgkillas 2024-10-05 06:12:44 -04:00
parent 27fab90db7
commit 09e861c6dc
4 changed files with 25 additions and 9 deletions

View file

@ -129,9 +129,15 @@ function end_fight.on_world_update()
local collision = EntityGetFirstComponentIncludingDisabled(entity, "PlayerCollisionComponent") local collision = EntityGetFirstComponentIncludingDisabled(entity, "PlayerCollisionComponent")
local suck = EntityGetFirstComponentIncludingDisabled(entity, "MaterialSuckerComponent") local suck = EntityGetFirstComponentIncludingDisabled(entity, "MaterialSuckerComponent")
local gui = EntityGetFirstComponentIncludingDisabled(entity, "InventoryGuiComponent") local gui = EntityGetFirstComponentIncludingDisabled(entity, "InventoryGuiComponent")
EntitySetComponentIsEnabled(entity, gui, false) if gui ~= nil then
EntitySetComponentIsEnabled(entity, suck, false) EntitySetComponentIsEnabled(entity, gui, false)
EntitySetComponentIsEnabled(entity, collision, false) end
if suck ~= nil then
EntitySetComponentIsEnabled(entity, suck, false)
end
if collision ~= nil then
EntitySetComponentIsEnabled(entity, collision, false)
end
for _, child in ipairs(EntityGetAllChildren(entity) or {}) do for _, child in ipairs(EntityGetAllChildren(entity) or {}) do
EntityKill(child) EntityKill(child)
end end

View file

@ -246,7 +246,9 @@ function spectate.on_world_update()
if inv_spec ~= nil then if inv_spec ~= nil then
ComponentSetValue2(inv_spec, "mActive", false) ComponentSetValue2(inv_spec, "mActive", false)
end end
ComponentSetValue2(inv_me, "mActive", false) if inv_me ~= nil then
ComponentSetValue2(inv_me, "mActive", false)
end
elseif GameGetFrameNum() % 10 == 0 then elseif GameGetFrameNum() % 10 == 0 then
for peer_id, data in pairs(ctx.players) do for peer_id, data in pairs(ctx.players) do
if peer_id ~= ctx.my_id then if peer_id ~= ctx.my_id then

View file

@ -73,7 +73,9 @@ end
function rpc.send_money(money) function rpc.send_money(money)
local entity = ctx.rpc_player_data.entity local entity = ctx.rpc_player_data.entity
local wallet = EntityGetFirstComponentIncludingDisabled(entity, "WalletComponent") local wallet = EntityGetFirstComponentIncludingDisabled(entity, "WalletComponent")
ComponentSetValue2(wallet, "money", money) if wallet ~= nil then
ComponentSetValue2(wallet, "money", money)
end
end end
local last_spectate local last_spectate
@ -128,7 +130,9 @@ function module.on_world_update()
end end
if GameGetFrameNum() % 60 == 47 then if GameGetFrameNum() % 60 == 47 then
local wallet = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "WalletComponent") local wallet = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "WalletComponent")
rpc.send_money(ComponentGetValue2(wallet, "money")) if wallet ~= nil then
rpc.send_money(ComponentGetValue2(wallet, "money"))
end
end end
end end

View file

@ -307,12 +307,16 @@ local function on_world_pre_update_inner()
if GameGetFrameNum() % 4 == 0 then if GameGetFrameNum() % 4 == 0 then
local x, y = EntityGetTransform(ctx.my_player.entity) local x, y = EntityGetTransform(ctx.my_player.entity)
change_homing(x, y) if x ~= nil then
change_homing(x, y)
end
elseif GameGetFrameNum() % 4 == 1 then elseif GameGetFrameNum() % 4 == 1 then
local x, y = EntityGetTransform(ctx.my_player.entity) local x, y = EntityGetTransform(ctx.my_player.entity)
local cx, cy = GameGetCameraPos() local cx, cy = GameGetCameraPos()
if math.abs(x - cx) > 256 or math.abs(y - cy) > 256 then if x ~= nil and cx ~= nil then
change_homing(cx, cy) if math.abs(x - cx) > 256 or math.abs(y - cy) > 256 then
change_homing(cx, cy)
end
end end
end end