Jump to content

Recommended Posts

So before i added extra codes to the prefab.lua, i was able to run my character mod, but since i added the codes the game says that the mod is 'Crashed! Disabled'. Here's the .lua:

local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}
local prefabs = {}

-- Custom starting items
local start_inv = {
}

-- When the character is revived from human
local function onbecamehuman(inst)
    -- Set speed when reviving from ghost (optional)
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "rinko_speed_mod", 1.05)
end

local function onbecameghost(inst)
    -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "rinko_speed_mod")
end

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end

local function UpdateSpeed(inst, phase)
    local mult = 1
    if phase == "day" then
        mult = 1.1
    elseif phase == "dusk" then
        mult = 1
    elseif phase == "night" then
        mult = 0.95
    end
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "phase_speed", mult)
end

-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst) 
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "rinko.tex" )
end

local function DoSanityDeltaOnAttacked(inst)
    for _, v in pairs(AllPlayers) do
        if v.components.sanity ~= nil and not v:HasTag("playerghost")
            if v == inst then
                v.components.sanity:DoDelta(-10)
            else
                v.components.sanity:DoDelta(-3)
            end
        end
    end
end

local function DoSanityDeltaOnDeath()
    for _, v in pairs(AllPlayers) do
        if v.components.sanity ~= nil and not v:HasTag("playerghost")
            v.components.sanity:DoDelta(-90)
        end
    end
end

local function SetSanityOnRevive(inst)
    inst:DoTaskInTime(0, function(inst) v.components.sanity.current = 20 end)
end

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
    -- choose which sounds this character will play
    inst.soundsname = "willow"
    
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
    
    -- Stats    
    inst.components.health:SetMaxHealth(200)
    inst.components.hunger:SetMax(140)
    inst.components.sanity:SetMax(250)
    
    inst:ListenForEvent("attacked", DoSanityDeltaOnAttacked)
inst:ListenForEvent("ms_becameghost", DoSanityDeltaOnDeath)
inst:ListenForEvent("ms_respawnedfromghost", SetSanityOnRevive)
    
    inst.components.sanity.night_drain_mult = 0
    inst.components.sanity.neg_aura_mult = 1
    

    inst:WatchWorldState("phase", UpdateSpeed)
    UpdateSpeed(inst, TheWorld.state.phase)


    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
    
    -- Hunger rate (optional)
    inst.components.hunger.hungerrate = 0.95 * TUNING.WILSON_HUNGER_RATE
    
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
    
end

return MakePlayerCharacter("rinko", prefabs, assets, common_postinit, master_postinit, start_inv)

Edited by DonMatio

I used to have something like the speed stuff you got, while I'm not at my computer I believe the errors revolve around phase_speed and updatespeed, If I remember correctly there has to be something in your master postinit yo make it function

Yeah i think i found what it was - 

inst:WatchWorldState("phase", UpdateSpeed)
UpdateSpeed(inst, TheWorld.state.phase)

I placed it in my master_postinit but it still says 'Crashed! Disabled'

(I compiled it again after i placed it in)

Edited by DonMatio

This error appeared the third time i tried to run the mod:

 

 

[string "scripts/mainfunctions.lua"]:147: Error loading file prefabs/rinko

[string "../mods/workshop-361202313/scripts/prefabs/rinko.lua"]:58: 'then' expected near 'if'

LUA ERROR stack traceback:

    =[C] in fucntions 'assert'

    scripts/mainfucntions.lua(147,1)

    =(tail call) ?

    =[C] in functions 'xpcall'

    scripts/mods.lua(158,1)

    scripts/mods.lua(596,1)

    scripts/gamelogic.lua(267,1) in function 'LoadAssets'

Edited by DonMatio
5 hours ago, ksaab said:

if v.components.sanity ~= nil and not v:HasTag("playerghost") then

it works now, thank you so much! 

Can i add you to the mod's credit description when i'm completely done with the mod?

Edited by DonMatio

So there just happens to be another error, this time the game crashes for the host after i revive myself with this character mod in our server.

(Image taken by my friend who was the host)

unknown (1).png

Edited by DonMatio

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...