Jump to content

Attempt to index "health" (nil value)


Recommended Posts

Hello!

The game crashed when I pressed the button G.
Error is located at scripts/consolecommands, at line 680)
Reason : "attempt to index "health" (nil value)"

Here's the in-game code scripts/consolecommands:

function c_armor(player)
    player = ListingOrConsolePlayer(player)
    if player ~= nil then
        SuUsed("c_armor", true)
        player.components.health:SetAbsorptionAmount(1)
        print("Enabled full absorption on " .. tostring(player.userid))
    end
end


And here's the part in my character file that triggers the error:
(It is located in modmain.lua)
 

local function doAreaDamage (inst, x, y, z, damageRange, damageToLivingEntities, doDamageToNonCombatants, workableDamage, isExplosion, ignite, mustHaveTags, cantHaveTags, mustHaveOneOfTheseTags)

    local ents = TheSim : FindEntities (x, y, z, 12, nil, {"INLIMBO"}, nil)

    for i, v in ipairs(ents) do
        if v ~= inst and v:IsValid() and not v:IsInLimbo() then

            if v:IsValid() and not v:IsInLimbo() then

                if v ~= inst and v:IsValid() and not v:IsInLimbo() then
                    if workableDamage > 0 and 
                        v.components.workable ~= nil and v.components.workable:CanBeWorked() then
                        v.components.workable:WorkedBy(inst, workableDamage, nil)
                    end

                    if ignite and
                        v.components.fueled == nil and
                        v.components.burnable ~= nil and
                        not v.components.burnable:IsBurning() and
                        not v:HasTag("burnt") then
                        v.components.burnable:Ignite()
                    end

                    if v.components.health ~= nil and not v.components.health:IsDead() then
                        if v.components.combat ~= nil then
                        v.components.combat:GetAttacked(inst, damageToLivingEntities, nil)
                        elseif doDamageToNonCombatants then
                        v.components.health:DoDelta(inst, damageToLivingEntities, nil)
                        end
                    end
                end
            end
        end
    end
end


local function AkaExplosion(player)
    if player.components.health:IsDead() or (player.explosiontime and GLOBAL.GetTime() - player.explosiontime < 1) then return end  
    local x,y,z = player.Transform:GetWorldPosition()  
    doAreaDamage(player, x, y, z, 12, 50, true, 0, true, false, nil, { "player", "structure", "INLIMBO", "NOCLICK" }, nil)
        -- spawn fx  
        local fx = GLOBAL.SpawnPrefab("groundpound_fx")
        local fxx = GLOBAL.SpawnPrefab("groundpoundring_fx")
        fx.Transform:SetPosition(x, y, z)
        fxx.Transform:SetPosition(x, y, z)
        -- cost
        player.components.sanity:DoDelta(-10)
        player.components.hunger:DoDelta(-15)
        -- save time
        player.explosiontime = GLOBAL.GetTime()
        -- dialogue
        player.components.talker:Say("Cursed Technique Reversal: Red")
end

AddModRPCHandler(modname, "Aka", AkaExplosion)



GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_G, function()
    if GLOBAL.ThePlayer and GLOBAL.ThePlayer.prefab == "gojo" and GLOBAL.TheFrontEnd:GetActiveScreen() == GLOBAL.ThePlayer.HUD then
        if GLOBAL.TheWorld.ismastersim then
            AkaExplosion(GLOBAL.ThePlayer)
        else
            SendModRPCToServer(GetModRPC(modname, "Aka"))
        end
    end
end)

I believe somewhere makes health become no value, which crashes with the in-game code and leads to the error.
Can anyone point out where the mistake is and how to fix it?
Help will be much appreciated !

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...