Jump to content

Recommended Posts

Hello!

I'm trying to make Wortox spend hunger on Soul Hops instead of Souls. This already works well without caves, but with caves it crashes.

image.jpeg.adc7e8a6063c475948f0f62d8af62f51.jpeg

I guess the problem is somewhere here:

local function GetSouls(inst) -- EDITED123
    local souls = inst.components.inventory:FindItems(IsSoul) -- <<<<<<<<<< CRASH
    local count = 0
    for i, v in ipairs(souls) do
        count = count + GetStackSize(v)
    end
    local souls2 = math.floor(inst.components.hunger.current / TUNING.SOUL_HOP_DRAIN)
    return souls, count, souls2
end

local function CanSoulhop(inst, souls2) -- EDITED123
    -- if not TheWorld.ismastersim then
    --     return inst
    -- end

    souls2 = souls2 or 1
    local _, _, soulscount = GetSouls(inst)
    if soulscount < souls2 then
        return false
    end

    local rider = inst.replica.rider
    if rider == nil or not rider:IsRiding() then
        return true
    end
    return false
end

I don't understand why it's complaining about inventory. I tried using "if not TheWorld.ismastersim" but I have trouble understanding how to use it. If you uncomment this part, then everything seems to work, but when opening the map the player will see the opportunity for Soul Hops, even if the character does not have enough hunger for this. Which is confusing.

soulhopmap.jpg.796866ff4e6b7b1c220797448c6b16cb.jpg

I think I roughly understand, but my experience is not enough to solve this.

I have attached the modified Wortox.lua file and tagged the changes with the tag "EDITED123".

wortox.lua

-- local function CanSoulhop(inst, souls) -- EDITED123
--     if inst.replica.inventory:Has("wortox_soul", souls or 1) then
--         local rider = inst.replica.rider
--         if rider == nil or not rider:IsRiding() then
--             return true
--         end
--     end
--     return false
-- end

local function CanSoulhop(inst, souls2) -- EDITED123
    if not TheWorld.ismastersim then
        return inst
    end

    souls2 = souls2 or 1
    local _, _, soulscount = GetSouls(inst)
    if soulscount < souls2 then
        return false
    end

    local rider = inst.replica.rider
    if rider == nil or not rider:IsRiding() then
        return true
    end
    return false
end


The function you call is the 'GetSouls' function which refers directly to server side components which is most likely the issue you encountered; the hunger function is most likely to be replicated, so you only need to refer to that instead + removing the anything referring to server-side components.

Typically when your mod crashes with caves it's usually due to issues pertaining to client side issues.

not entirely sure about the map issues, but It may be due to when trying to know whenever wortox can't teleport to a location on the map it derives from different code from wortox itself. I believe there is a file scripts/componentactions where it will verify possible actions so it may contain there.

Peace out bro or brossete or bro-binary, I'm in my sims 4 era so i may be late to reply.

 

ALSO I'M BEING REALLY PETTY BUT PLEASE NAME VARAIBLES APPROPRAITELY!!!

I did some research on the forum before creating the post. I understand that the problem is somewhere in the server/client connection, that perhaps I need a replica of the hunger component, etc. I spent a lot of time, but so far I don't understand how to solve this.

9 hours ago, Thomas Die said:

ALSO I'M BEING REALLY PETTY BUT PLEASE NAME VARAIBLES APPROPRAITELY!!!

Don't you like "souls2"? I don't think this is a problem when this is the only variable I added. Especially when this variable simply takes away part of the functionality with the "souls" variable. It's just quick and easy to understand, I think. But if I were going to publish the mod on the Steam Workshop, I would definitely change the name of the variable.

Anyway. Thanks for the reply.

Edited by sjtdhiqbwczfzpu
20 hours ago, Rickzzs said:

use inst.replica.hunger and inst.replica.inventory. there is no .component.xxx

I'm sure I tried using "inst.replica.hunger" and it didn't work, or I did something wrong. I'll try this again later.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...