Jump to content

Custom Character Crash On World Loading


Recommended Posts

Hello!

I,ve imported a DS character to DST and without his prefabs and componets it works well but when i add them i get this:
 

Disabling Custom because it had an error.
[string "../mods/Custom/modmain.lua"]:40: attempt to index global 'player' (a nil value)
LUA ERROR stack traceback:
        ../mods/Custom/modmain.lua(40,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(105,1)
        scripts/mods.lua(547,1) in function 'SimPostInit'
        scripts/gamelogic.lua(881,1) in function 'DoInitGame'
        scripts/gamelogic.lua(971,1) in function 'cb'
        scripts/saveindex.lua(640,1)
        =[C] in function 'SetPersistentString'
        scripts/saveindex.lua(84,1) in function 'Save'
        scripts/saveindex.lua(669,1)
        =[C] in function 'SetPersistentString'
        scripts/saveindex.lua(672,1) in function 'OnGenerateNewWorld'
        scripts/gamelogic.lua(981,1) in function 'cb'
        scripts/screens/worldgenscreen.lua(183,1) in function 'cb'
        scripts/frontend.lua(424,1) in function 'DoFadingUpdate'
        scripts/frontend.lua(479,1) in function 'Update'
        scripts/update.lua(91,1)

What is wrong with it ?
Link to comment
Share on other sites

modmain.lua

 
PrefabFiles = {"mabel","sweaterbal","sweaterber","sweaterbol","sweaterclo","sweatercre","sweaterhea","sweaterind","sweaterlla","sweatermab","sweatermeo","sweatermus","sweaternot","sweatersco","sweatersta","sweaterumb"}ComponentFiles = {"sweaterswitch",}Assets = {    Asset( "IMAGE", "images/saveslot_portraits/mabel.tex" ),Asset( "ATLAS", "images/saveslot_portraits/mabel.xml" ),    Asset( "IMAGE", "images/selectscreen_portraits/mabel.tex" ),Asset( "ATLAS", "images/selectscreen_portraits/mabel.xml" ),    Asset( "IMAGE", "images/selectscreen_portraits/mabel_silho.tex" ),Asset( "ATLAS", "images/selectscreen_portraits/mabel_silho.xml" ),    Asset( "IMAGE", "bigportraits/mabel.tex" ),Asset( "ATLAS", "bigportraits/mabel.xml" ),}function sSwitch(player)    if player.components.sweaterswitch then        player.components.sweaterswitch:RanSweater()    endendlocal STRINGS = GLOBAL.STRINGSlocal Ingredient = GLOBAL.Ingredientlocal RECIPETABS = GLOBAL.RECIPETABSGLOBAL.STRINGS.NAMES.SWEATERBAL = "Basketball Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERBAL = "Barkley for 2!"GLOBAL.STRINGS.NAMES.SWEATERBER = "Strawberry Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERBER = "Does not come with shortcake sweater."GLOBAL.STRINGS.NAMES.SWEATERBOL = "Bolt Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERBOL = "A bolt of lightning!"GLOBAL.STRINGS.NAMES.SWEATERCLO = "Clover Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERCLO = "Today's my lucky day!"GLOBAL.STRINGS.NAMES.SWEATERCRE = "Crest Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERCRE = "Trust no-one."GLOBAL.STRINGS.NAMES.SWEATERHEA = "Cool Heart Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERHEA = "Too radicool for you!"GLOBAL.STRINGS.NAMES.SWEATERIND = "Pattern Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERIND = "It's so cute!"GLOBAL.STRINGS.NAMES.SWEATERLLA = "LLama Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERLLA = "Here's a llama, there's a llama!"GLOBAL.STRINGS.NAMES.SWEATERMAB = "Mabel Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERMAB = "Lights not included."GLOBAL.STRINGS.NAMES.SWEATERMEO = "Meow Wow Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERMEO = "Wow!"GLOBAL.STRINGS.NAMES.SWEATERMUS = "Mushroom Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERMUS = "Practically camouflage!"GLOBAL.STRINGS.NAMES.SWEATERNOT = "Music Note Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERNOT = "Because you're F A B!"GLOBAL.STRINGS.NAMES.SWEATERSCO = "Promise Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERSCO = "Scouts honour!"GLOBAL.STRINGS.NAMES.SWEATERSTA = "Star Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERSTA = "Make a wish!"GLOBAL.STRINGS.NAMES.SWEATERUMB = "Umbrella Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERUMB = "Ella, ella, ay, ay, ay."AddSimPostInit(sSwitch)AddPrefabPostInit('sweaterbal')AddPrefabPostInit('sweaterber')AddPrefabPostInit('sweaterbol')AddPrefabPostInit('sweaterclo')AddPrefabPostInit('sweatercre')AddPrefabPostInit('sweaterhea')AddPrefabPostInit('sweaterind')AddPrefabPostInit('sweaterlla')AddPrefabPostInit('sweatermab')AddPrefabPostInit('sweatermeo')AddPrefabPostInit('sweatermus')AddPrefabPostInit('sweaternot')AddPrefabPostInit('sweatersco')AddPrefabPostInit('sweatersta')AddPrefabPostInit('sweaterumb')AddComponentPostInit('sweaterswitch')AddModCharacter("mabel")AddSimPostInit(pcHat)STRINGS.CHARACTERS.GENERIC.DESCRIBE.MABEL = {GENERIC = "It's Mabel!",ATTACKER = "That Mabel looks shifty...",MURDERER = "Murderer!",REVIVER = "Mabel, friend of ghosts.",GHOST = "Mabel could use a heart.",}

prefab custom character.lua
 

local MakePlayerCharacter = require "prefabs/player_common"local assets = {        Asset( "ANIM", "anim/player_basic.zip" ),        Asset( "ANIM", "anim/player_idles_shiver.zip" ),        Asset( "ANIM", "anim/player_actions.zip" ),        Asset( "ANIM", "anim/player_actions_axe.zip" ),        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),        Asset( "ANIM", "anim/player_actions_shovel.zip" ),        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),        Asset( "ANIM", "anim/player_actions_eat.zip" ),        Asset( "ANIM", "anim/player_actions_item.zip" ),        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),        Asset( "ANIM", "anim/player_actions_fishing.zip" ),        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),        Asset( "ANIM", "anim/player_bush_hat.zip" ),        Asset( "ANIM", "anim/player_attacks.zip" ),        Asset( "ANIM", "anim/player_idles.zip" ),        Asset( "ANIM", "anim/player_rebirth.zip" ),        Asset( "ANIM", "anim/player_jump.zip" ),        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),        Asset( "ANIM", "anim/player_teleport.zip" ),        Asset( "ANIM", "anim/wilson_fx.zip" ),        Asset( "ANIM", "anim/player_one_man_band.zip" ),        Asset( "ANIM", "anim/shadow_hands.zip" ),        Asset( "SOUND", "sound/sfx.fsb" ),        Asset( "SOUND", "sound/wilson.fsb" ),        Asset( "ANIM", "anim/beard.zip" ),-- Don't forget to include your character's custom assets!        Asset( "ANIM", "anim/mabel.zip" ),        Asset( "ANIM", "anim/ghost_mabel_build.zip" ),Asset( "ANIM", "anim/mabel_bal.zip" ),Asset( "ANIM", "anim/mabel_ber.zip" ),Asset( "ANIM", "anim/mabel_bol.zip" ),Asset( "ANIM", "anim/mabel_clo.zip" ),Asset( "ANIM", "anim/mabel_cre.zip" ),Asset( "ANIM", "anim/mabel_hea.zip" ),Asset( "ANIM", "anim/mabel_ind.zip" ),Asset( "ANIM", "anim/mabel_lla.zip" ),Asset( "ANIM", "anim/mabel_mab.zip" ),Asset( "ANIM", "anim/mabel_meo.zip" ),Asset( "ANIM", "anim/mabel_mus.zip" ),Asset( "ANIM", "anim/mabel_not.zip" ),Asset( "ANIM", "anim/mabel_sco.zip" ),Asset( "ANIM", "anim/mabel_sta.zip" ),Asset( "ANIM", "anim/mabel_umb.zip" ),Asset("IMAGE", "images/hud/tab_sweater.tex"), Asset("ATLAS", "images/hud/tab_sweater.xml"),Asset("IMAGE", "images/inventoryimages/sweaterbal.tex"), Asset("ATLAS", "images/inventoryimages/sweaterbal.xml")}local prefabs = { "piggyback", "sweaternot"}local start_inv = { "piggyback"}local fn = function(inst)-- choose which sounds this character will playinst.soundsname = "willow"-- a minimap icon must be specifiedinst.MiniMapEntity:SetIcon( "wendy.png" )inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.15)inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.2)inst.components.combat.damagemultiplier = 0.9inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE-- todo: Add an example special power here.inst:AddComponent("sweaterswitch")local sweatertab = {str = "Sweaters", sort=999, icon = "clock_NIGHT.tex"}inst.components.builder:AddRecipeTab(sweatertab)local s01Recipe = Recipe("sweaterbal", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s01Recipe.atlas = "images/inventoryimages/sweaterbal.xml"local s02Recipe = Recipe("sweaterber", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s02Recipe.atlas = "images/inventoryimages/sweaterber.xml"local s03Recipe = Recipe("sweaterbol", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s03Recipe.atlas = "images/inventoryimages/sweaterbol.xml"local s04Recipe = Recipe("sweaterclo", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s04Recipe.atlas = "images/inventoryimages/sweaterclo.xml"local s05Recipe = Recipe("sweatercre", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s05Recipe.atlas = "images/inventoryimages/sweatercre.xml"local s06Recipe = Recipe("sweaterhea", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s06Recipe.atlas = "images/inventoryimages/sweaterhea.xml"local s07Recipe = Recipe("sweaterind", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s07Recipe.atlas = "images/inventoryimages/sweaterind.xml"local s08Recipe = Recipe("sweaterlla", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s08Recipe.atlas = "images/inventoryimages/sweaterlla.xml"local s09Recipe = Recipe("sweatermab", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s09Recipe.atlas = "images/inventoryimages/sweatermab.xml"local s10Recipe = Recipe("sweatermeo", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s10Recipe.atlas = "images/inventoryimages/sweatermeo.xml"local s11Recipe = Recipe("sweatermus", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s11Recipe.atlas = "images/inventoryimages/sweatermus.xml"local s12Recipe = Recipe("sweaternot", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s12Recipe.atlas = "images/inventoryimages/sweaternot.xml"local s13Recipe = Recipe("sweatersco", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s13Recipe.atlas = "images/inventoryimages/sweatersco.xml"local s14Recipe = Recipe("sweatersta", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s14Recipe.atlas = "images/inventoryimages/sweatersta.xml"local s15Recipe = Recipe("sweaterumb", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s15Recipe.atlas = "images/inventoryimages/sweaterumb.xml"end-- strings! Any "WOD" below would have to be replaced by the prefab name of your character.-- First up, the character select screen lines -- note: these are lower-case character nameSTRINGS.CHARACTER_TITLES.mabel = "The Eccentric Sister"STRINGS.CHARACTER_NAMES.mabel = "Mabel"STRINGS.CHARACTER_DESCRIPTIONS.mabel = "*Has a lot of sweaters\n*Loves her pet pig\n*Tends to look on the bright side of things"STRINGS.CHARACTER_QUOTES.mabel = "\"We're somewhere where it looks like we're nowhere.\""-- You can also add any kind of custom dialogue that you would like. Don't forget to make-- categores that don't exist yet using = {}-- note: these are UPPER-CASE charcacter nameSTRINGS.CHARACTERS.MABEL = require "speech_mabel"return MakePlayerCharacter("mabel", prefabs, assets, fn, start_inv)

component sweaterswitch.lua:
 

 
local Sweater = Class(function(self, inst)    self.inst = instself.fLoad = falseself.sName = ""self.sweaters = {"bal", "ber", "bol", "clo", "cre", "hea", "ind", "lla", "mab", "meo", "mus", "not", "sco", "sta", "umb"}end)function Sweater:SetSweater(name)GetPlayer().AnimState:SetBuild("mabel_"..name)self.sName = nameendfunction Sweater:RanSweater()if self.fLoad == false thenself.sName = self.sweaters[math.random(#self.sweaters)]GetPlayer().AnimState:SetBuild("mabel_"..self.sName)self.fLoad = trueendendfunction Sweater:OnSave()local data ={fLoad = self.fLoad,sName = self.sName}return dataendfunction Sweater:OnLoad(data)    if data.fLoad thenself.fLoad = data.fLoadself.sName = data.sNameGetPlayer().AnimState:SetBuild("mabel_"..self.sName)endendreturn Sweater
 

 

Link to comment
Share on other sites

@Fredson, You can't use AddSimPostInit for this. The player doesn't exist yet when the Sim is initialized, and as you're finding from your error, there's no argument being passed to your function (that's why player is nil). Instead, you should probably just be putting that code directly into the character's prefab.

 

Also, you should look at some DST character prefab files, you just have fn in yours, and that needs to be split into common_postinit and master_postinit.

Link to comment
Share on other sites

@Fredson, You can't use AddSimPostInit for this. The player doesn't exist yet when the Sim is initialized, and as you're finding from your error, there's no argument being passed to your function (that's why player is nil). Instead, you should probably just be putting that code directly into the character's prefab.

 

Also, you should look at some DST character prefab files, you just have fn in yours, and that needs to be split into common_postinit and master_postinit.

:/ the thing is i dont know how to do it, im beginning in this, i followed the extended character tutorial to import a character from DS, and that character has a sweater switch component

Link to comment
Share on other sites

i have fixed the prefab:
 

local MakePlayerCharacter = require "prefabs/player_common"local assets = {        Asset( "ANIM", "anim/player_basic.zip" ),        Asset( "ANIM", "anim/player_idles_shiver.zip" ),        Asset( "ANIM", "anim/player_actions.zip" ),        Asset( "ANIM", "anim/player_actions_axe.zip" ),        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),        Asset( "ANIM", "anim/player_actions_shovel.zip" ),        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),        Asset( "ANIM", "anim/player_actions_eat.zip" ),        Asset( "ANIM", "anim/player_actions_item.zip" ),        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),        Asset( "ANIM", "anim/player_actions_fishing.zip" ),        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),        Asset( "ANIM", "anim/player_bush_hat.zip" ),        Asset( "ANIM", "anim/player_attacks.zip" ),        Asset( "ANIM", "anim/player_idles.zip" ),        Asset( "ANIM", "anim/player_rebirth.zip" ),        Asset( "ANIM", "anim/player_jump.zip" ),        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),        Asset( "ANIM", "anim/player_teleport.zip" ),        Asset( "ANIM", "anim/wilson_fx.zip" ),        Asset( "ANIM", "anim/player_one_man_band.zip" ),        Asset( "ANIM", "anim/shadow_hands.zip" ),        Asset( "SOUND", "sound/sfx.fsb" ),        Asset( "SOUND", "sound/wilson.fsb" ),        Asset( "ANIM", "anim/beard.zip" ),        Asset( "ANIM", "anim/mabel.zip" ),        Asset( "ANIM", "anim/ghost_mabel_build.zip" ),Asset( "ANIM", "anim/mabel_bal.zip" ),Asset( "ANIM", "anim/mabel_ber.zip" ),Asset( "ANIM", "anim/mabel_bol.zip" ),Asset( "ANIM", "anim/mabel_clo.zip" ),Asset( "ANIM", "anim/mabel_cre.zip" ),Asset( "ANIM", "anim/mabel_hea.zip" ),Asset( "ANIM", "anim/mabel_ind.zip" ),Asset( "ANIM", "anim/mabel_lla.zip" ),Asset( "ANIM", "anim/mabel_mab.zip" ),Asset( "ANIM", "anim/mabel_meo.zip" ),Asset( "ANIM", "anim/mabel_mus.zip" ),Asset( "ANIM", "anim/mabel_not.zip" ),Asset( "ANIM", "anim/mabel_sco.zip" ),Asset( "ANIM", "anim/mabel_sta.zip" ),Asset( "ANIM", "anim/mabel_umb.zip" ),Asset("IMAGE", "images/hud/tab_sweater.tex"), Asset("ATLAS", "images/hud/tab_sweater.xml"),Asset("IMAGE", "images/inventoryimages/sweaterbal.tex"), Asset("ATLAS", "images/inventoryimages/sweaterbal.xml")}local prefabs = { "piggyback", "sweaternot"}local start_inv = { "piggyback"}AddSimPostInit(sSwitch)AddPrefabPostInit('sweaterbal')AddPrefabPostInit('sweaterber')AddPrefabPostInit('sweaterbol')AddPrefabPostInit('sweaterclo')AddPrefabPostInit('sweatercre')AddPrefabPostInit('sweaterhea')AddPrefabPostInit('sweaterind')AddPrefabPostInit('sweaterlla')AddPrefabPostInit('sweatermab')AddPrefabPostInit('sweatermeo')AddPrefabPostInit('sweatermus')AddPrefabPostInit('sweaternot')AddPrefabPostInit('sweatersco')AddPrefabPostInit('sweatersta')AddPrefabPostInit('sweaterumb')AddComponentPostInit('sweaterswitch')AddModCharacter("mabel")AddSimPostInit(pcHat)function sSwitch(player)    if player.components.sweaterswitch then        player.components.sweaterswitch:RanSweater()    endend-- This initializes for both clients and the hostlocal common_postinit = function(inst) -- Minimap iconinst.MiniMapEntity:SetIcon( "mabel.tex" )end-- This initializes for the host onlylocal master_postinit = function(inst)-- choose which sounds this character will playinst.soundsname = "willow"-- Stats inst.components.health:SetMaxHealth(200)inst.components.hunger:SetMax(150)inst.components.sanity:SetMax(200) inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.15)inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.3)inst.components.combat.damagemultiplier = 1.2inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE-- todo: Add an example special power here.inst:AddComponent("sweaterswitch")local sweatertab = {str = "Sweaters", sort=999, icon = "clock_NIGHT.tex"}inst.components.builder:AddRecipeTab(sweatertab)local s01Recipe = Recipe("sweaterbal", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s01Recipe.atlas = "images/inventoryimages/sweaterbal.xml"local s02Recipe = Recipe("sweaterber", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s02Recipe.atlas = "images/inventoryimages/sweaterber.xml"local s03Recipe = Recipe("sweaterbol", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s03Recipe.atlas = "images/inventoryimages/sweaterbol.xml"local s04Recipe = Recipe("sweaterclo", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s04Recipe.atlas = "images/inventoryimages/sweaterclo.xml"local s05Recipe = Recipe("sweatercre", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s05Recipe.atlas = "images/inventoryimages/sweatercre.xml"local s06Recipe = Recipe("sweaterhea", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s06Recipe.atlas = "images/inventoryimages/sweaterhea.xml"local s07Recipe = Recipe("sweaterind", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s07Recipe.atlas = "images/inventoryimages/sweaterind.xml"local s08Recipe = Recipe("sweaterlla", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s08Recipe.atlas = "images/inventoryimages/sweaterlla.xml"local s09Recipe = Recipe("sweatermab", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s09Recipe.atlas = "images/inventoryimages/sweatermab.xml"local s10Recipe = Recipe("sweatermeo", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s10Recipe.atlas = "images/inventoryimages/sweatermeo.xml"local s11Recipe = Recipe("sweatermus", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s11Recipe.atlas = "images/inventoryimages/sweatermus.xml"local s12Recipe = Recipe("sweaternot", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s12Recipe.atlas = "images/inventoryimages/sweaternot.xml"local s13Recipe = Recipe("sweatersco", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s13Recipe.atlas = "images/inventoryimages/sweatersco.xml"local s14Recipe = Recipe("sweatersta", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s14Recipe.atlas = "images/inventoryimages/sweatersta.xml"local s15Recipe = Recipe("sweaterumb", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s15Recipe.atlas = "images/inventoryimages/sweaterumb.xml"endreturn MakePlayerCharacter("mabel", prefabs, assets, common_postinit, master_postinit, start_inv)

but still crashes

 

Link to comment
Share on other sites

Well... I think this isn't a good starter project. You will have to do quite a bit of work to get character-specific recipes/recipetabs working, and the recipe system right now totally bugs out if you have more than one recipe mod. But if you do get back to it later, you can't have recipes in character prefabs anymore, because the recipe table needs to be the same for everyone (so you put them in the modmain instead).

 

Also, since you removed sSwitch, you should comment out or remove the AddSimPostInit.

 

I don't know why the sweaterswitch needs a call outside of the prefab like that, but I guess there's probably a reason. Hard to say where and how to place it without seeing that component.

Link to comment
Share on other sites

so the sweater function cannot work in DST ?

btw heres the component:
 

 
local Sweater = Class(function(self, inst)    self.inst = instself.fLoad = falseself.sName = ""self.sweaters = {"bal", "ber", "bol", "clo", "cre", "hea", "ind", "lla", "mab", "meo", "mus", "not", "sco", "sta", "umb"}end)function Sweater:SetSweater(name)GetPlayer().AnimState:SetBuild("mabel_"..name)self.sName = nameendfunction Sweater:RanSweater()if self.fLoad == false thenself.sName = self.sweaters[math.random(#self.sweaters)]GetPlayer().AnimState:SetBuild("mabel_"..self.sName)self.fLoad = trueendendfunction Sweater:OnSave()local data ={fLoad = self.fLoad,sName = self.sName}return dataendfunction Sweater:OnLoad(data)    if data.fLoad thenself.fLoad = data.fLoadself.sName = data.sNameGetPlayer().AnimState:SetBuild("mabel_"..self.sName)endendreturn Sweater

 

Link to comment
Share on other sites

@Fredson, Oh... I think the author just wanted it to run after the OnLoad. So the easy solution is to put it in the OnLoad instead...

function Sweater:OnLoad(data)    if data.fLoad then        self.fLoad = data.fLoad        self.sName = data.sName        self.inst.AnimState:SetBuild("mabel_"..self.sName)    end    self:RanSweater()end

Also, wherever you see GetPlayer() you'll have to change it. Inside the sweaterswitch component, it should be using self.inst instead, but elsewhere it will vary.

Link to comment
Share on other sites

ok, and this goes in prefabs right ? but in any order ?
 

AddSimPostInit(sSwitch)AddPrefabPostInit('sweaterbal')AddPrefabPostInit('sweaterber')AddPrefabPostInit('sweaterbol')AddPrefabPostInit('sweaterclo')AddPrefabPostInit('sweatercre')AddPrefabPostInit('sweaterhea')AddPrefabPostInit('sweaterind')AddPrefabPostInit('sweaterlla')AddPrefabPostInit('sweatermab')AddPrefabPostInit('sweatermeo')AddPrefabPostInit('sweatermus')AddPrefabPostInit('sweaternot')AddPrefabPostInit('sweatersco')AddPrefabPostInit('sweatersta')AddPrefabPostInit('sweaterumb')AddComponentPostInit('sweaterswitch')AddModCharacter("mabel")AddSimPostInit(pcHat)function sSwitch(player)    if player.components.sweaterswitch then        player.components.sweaterswitch:RanSweater()    endend

 

Link to comment
Share on other sites

AddPrefabPostInit('sweaterbal') AddPrefabPostInit('sweaterber') AddPrefabPostInit('sweaterbol') AddPrefabPostInit('sweaterclo') AddPrefabPostInit('sweatercre') AddPrefabPostInit('sweaterhea') AddPrefabPostInit('sweaterind') AddPrefabPostInit('sweaterlla') AddPrefabPostInit('sweatermab') AddPrefabPostInit('sweatermeo') AddPrefabPostInit('sweatermus') AddPrefabPostInit('sweaternot') AddPrefabPostInit('sweatersco') AddPrefabPostInit('sweatersta') AddPrefabPostInit('sweaterumb')

You don't need to do any of this. Although it does seem like the function is saying it's adding the prefab after initialization, what it's actually doing is adding a post-initialization function to a prefab (or component). So if you're not giving it a function as the second argument, it's not really doing anything.

 

Edit: Going back and looking at the modmain, it looks like the original author did this in place of declaring them in the PrefabFiles table, which is definitely the nicer way to make sure they get loaded:

PrefabFiles = {	"sweaterbal",	"sweaterber",	"sweaterbol",	"sweaterclo",	"sweatercre",	"sweaterhea",}

... and so on

Edited by rezecib
Link to comment
Share on other sites

ok, i think evrything is fine but it crashed loading the last part of the mabel.lua prefab
 

string "../mods/Mabel Pines/scripts/prefabs/mabel.l..."]:93: attempt to call method 'AddRecipeTab' (a nil value)LUA ERROR stack traceback:../mods/Mabel Pines/scripts/prefabs/mabel.lua:93 in (upvalue) master_postinit (Lua) <76-140>   inst = 116954 -  (valid:true)   sweatertab = table: 327941B0scripts/prefabs/player_common.lua:1188 in (upvalue) oldfn (Lua) <969-1217>   inst = 116954 -  (valid:true)../mods/workshop-359424598/modmain.lua:41 in (upvalue) oldfn (Lua) <40-51>../mods/workshop-359424598/modmain.lua:65 in (field) fn (Lua) <64-69>scripts/mainfunctions.lua:147 in () ? (Lua) <136-167>   name = mabel   prefab = Prefab mabel - =[C]:-1 in (method) SendSpawnRequestToServer (C) <-1--1>scripts/mainfunctions.lua:1134 in (local) cb (Lua) <1132-1138>scripts/frontend.lua:424 in (method) DoFadingUpdate (Lua) <388-428>

heres the crashing line:

inst:AddComponent("sweaterswitch")local sweatertab = {str = "Sweaters", sort=999, icon = "clock_NIGHT.tex"}inst.components.builder:AddRecipeTab(sweatertab)local s01Recipe = Recipe("sweaterbal", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s01Recipe.atlas = "images/inventoryimages/sweaterbal.xml"local s02Recipe = Recipe("sweaterber", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s02Recipe.atlas = "images/inventoryimages/sweaterber.xml"local s03Recipe = Recipe("sweaterbol", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s03Recipe.atlas = "images/inventoryimages/sweaterbol.xml"local s04Recipe = Recipe("sweaterclo", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s04Recipe.atlas = "images/inventoryimages/sweaterclo.xml"local s05Recipe = Recipe("sweatercre", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s05Recipe.atlas = "images/inventoryimages/sweatercre.xml"local s06Recipe = Recipe("sweaterhea", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s06Recipe.atlas = "images/inventoryimages/sweaterhea.xml"local s07Recipe = Recipe("sweaterind", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s07Recipe.atlas = "images/inventoryimages/sweaterind.xml"local s08Recipe = Recipe("sweaterlla", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s08Recipe.atlas = "images/inventoryimages/sweaterlla.xml"local s09Recipe = Recipe("sweatermab", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s09Recipe.atlas = "images/inventoryimages/sweatermab.xml"local s10Recipe = Recipe("sweatermeo", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s10Recipe.atlas = "images/inventoryimages/sweatermeo.xml"local s11Recipe = Recipe("sweatermus", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s11Recipe.atlas = "images/inventoryimages/sweatermus.xml"local s12Recipe = Recipe("sweaternot", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s12Recipe.atlas = "images/inventoryimages/sweaternot.xml"local s13Recipe = Recipe("sweatersco", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s13Recipe.atlas = "images/inventoryimages/sweatersco.xml"local s14Recipe = Recipe("sweatersta", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s14Recipe.atlas = "images/inventoryimages/sweatersta.xml"local s15Recipe = Recipe("sweaterumb", {}, sweatertab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})s15Recipe.atlas = "images/inventoryimages/sweaterumb.xml"

also in the crash made reference to another mod lines that said AddComponent 

 

Link to comment
Share on other sites

@Fredson, Recipe tabs are very difficult to add right now. I think the Tiny Tina mod adds one, so you can look at how that does it. And I think I said this before, but you can't have recipes in the prefab, they need to be in the modmain or the entire recipe system will break.

Link to comment
Share on other sites

ok it doesnt crash anymore, but the sweatertab does not appear, this appears in tiny tina modmain.lua not sure if this is for the CUSTOM_RECIPETAB :
 

AddClassPostConstruct("widgets/crafttabs", function(class)if class.owner:HasTag("bombzerker") thenlocal v = CUSTOM_RECIPETABS.ORDINANCElocal k = #class.tab_order + 1local tab_bg = {normal = "tab_normal.tex",selected = "tab_selected.tex",highlight = "tab_highlight.tex",bufferedhighlight = "tab_place.tex",overlay = "tab_researchable.tex",}class.tabs.spacing = 750/klocal tab = class.tabs:AddTab(STRINGS.TABS[v.str], resolvefilepath("images/hud.xml"), v.icon_atlas or resolvefilepath("images/hud.xml"), v.icon, tab_bg.normal, tab_bg.selected, tab_bg.highlight, tab_bg.bufferedhighlight, tab_bg.overlay,                        function() --select fn                if not class.controllercraftingopen then                                        if class.craft_idx_by_tab[k] then                        class.crafting.idx = class.craft_idx_by_tab[k]                    end                    class.crafting:SetFilter(                         function(recipe)                            local rec = GLOBAL.AllRecipes[recipe]                            return rec and rec.tab == v                        end)                                                                                                                class.crafting:Open()                end            end,             function() --deselect fn                class.craft_idx_by_tab[k] = class.crafting.idx                class.crafting:Close()            end)        tab.filter = v        tab.icon = v.icon        tab.icon_atlas = v.icon_atlas or resolvefilepath("images/hud.xml")        tab.tabname = STRINGS.TABS[v.str]        class.tabbyfilter[v] = tab        table.insert(class.tab_order, tab)endend)

also, were should i put this ? 
 

inst:AddComponent("sweaterswitch")

it was written before the sweater recipes

 

Edited by Fredson
Link to comment
Share on other sites

the modmain.lua of my mod modfified if you need it :
 

 
PrefabFiles = {"mabel","sweaterbal","sweaterber","sweaterbol","sweaterclo","sweatercre","sweaterhea","sweaterind","sweaterlla","sweatermab","sweatermeo","sweatermus","sweaternot","sweatersco","sweatersta","sweaterumb"}Assets = {    Asset( "IMAGE", "images/saveslot_portraits/mabel.tex" ),    Asset( "ATLAS", "images/saveslot_portraits/mabel.xml" ),    Asset( "IMAGE", "images/selectscreen_portraits/mabel.tex" ),    Asset( "ATLAS", "images/selectscreen_portraits/mabel.xml" ),    Asset( "IMAGE", "images/selectscreen_portraits/mabel_silho.tex" ),    Asset( "ATLAS", "images/selectscreen_portraits/mabel_silho.xml" ),    Asset( "IMAGE", "bigportraits/mabel.tex" ),    Asset( "ATLAS", "bigportraits/mabel.xml" ),Asset( "IMAGE", "images/map_icons/mabel.tex" ),Asset( "ATLAS", "images/map_icons/mabel.xml" ),Asset( "IMAGE", "images/avatars/avatar_mabel.tex" ),    Asset( "ATLAS", "images/avatars/avatar_mabel.xml" ),Asset( "IMAGE", "images/avatars/avatar_ghost_mabel.tex" ),    Asset( "ATLAS", "images/avatars/avatar_ghost_mabel.xml" ),}GLOBAL.STRINGS.NAMES.SWEATERBAL = "Basketball Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERBAL = "Barkley for 2!"GLOBAL.STRINGS.NAMES.SWEATERBER = "Strawberry Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERBER = "Does not come with shortcake sweater."GLOBAL.STRINGS.NAMES.SWEATERBOL = "Bolt Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERBOL = "A bolt of lightning!"GLOBAL.STRINGS.NAMES.SWEATERCLO = "Clover Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERCLO = "Today's my lucky day!"GLOBAL.STRINGS.NAMES.SWEATERCRE = "Crest Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERCRE = "Trust no-one."GLOBAL.STRINGS.NAMES.SWEATERHEA = "Cool Heart Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERHEA = "Too radicool for you!"GLOBAL.STRINGS.NAMES.SWEATERIND = "Pattern Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERIND = "It's so cute!"GLOBAL.STRINGS.NAMES.SWEATERLLA = "LLama Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERLLA = "Here's a llama, there's a llama!"GLOBAL.STRINGS.NAMES.SWEATERMAB = "Mabel Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERMAB = "Lights not included."GLOBAL.STRINGS.NAMES.SWEATERMEO = "Meow Wow Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERMEO = "Wow!"GLOBAL.STRINGS.NAMES.SWEATERMUS = "Mushroom Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERMUS = "Practically camouflage!"GLOBAL.STRINGS.NAMES.SWEATERNOT = "Music Note Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERNOT = "Because you're F A B!"GLOBAL.STRINGS.NAMES.SWEATERSCO = "Promise Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERSCO = "Scouts honour!"GLOBAL.STRINGS.NAMES.SWEATERSTA = "Star Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERSTA = "Make a wish!"GLOBAL.STRINGS.NAMES.SWEATERUMB = "Umbrella Sweater"GLOBAL.STRINGS.RECIPE_DESC.SWEATERUMB = "Ella, ella, ay, ay, ay."local require = GLOBAL.requirelocal STRINGS = GLOBAL.STRINGS    local resolvefilepath = GLOBAL.resolvefilepath    local TECH = GLOBAL.TECH    local CUSTOM_RECIPETABS = GLOBAL.CUSTOM_RECIPETABS    GLOBAL.CUSTOM_RECIPETABS.SWEATERS = { str = "SWEATERS", sort = 998, icon = "tab_sweater.tex", icon_atlas = resolvefilepath("images/hud/tab_sweater.xml")}    STRINGS.TABS.SWEATERS = "Sweaters"--local sweatertab = {str = "Sweaters", sort=999, icon = "tab_sweater.tex", icon_atlas = resolvefilepath("images/hud/tab_sweater.xml")}--inst.components.builder:AddRecipeTab(GLOBAL.CUSTOM_RECIPETABS.SWEATERS)local s01Recipe = Recipe("sweaterbal", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s01Recipe.atlas = "images/inventoryimages/sweaterbal.xml"local s02Recipe = Recipe("sweaterber", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s02Recipe.atlas = "images/inventoryimages/sweaterber.xml"local s03Recipe = Recipe("sweaterbol", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s03Recipe.atlas = "images/inventoryimages/sweaterbol.xml"local s04Recipe = Recipe("sweaterclo", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s04Recipe.atlas = "images/inventoryimages/sweaterclo.xml"local s05Recipe = Recipe("sweatercre", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s05Recipe.atlas = "images/inventoryimages/sweatercre.xml"local s06Recipe = Recipe("sweaterhea", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s06Recipe.atlas = "images/inventoryimages/sweaterhea.xml"local s07Recipe = Recipe("sweaterind", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s07Recipe.atlas = "images/inventoryimages/sweaterind.xml"local s08Recipe = Recipe("sweaterlla", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s08Recipe.atlas = "images/inventoryimages/sweaterlla.xml"local s09Recipe = Recipe("sweatermab", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s09Recipe.atlas = "images/inventoryimages/sweatermab.xml"local s10Recipe = Recipe("sweatermeo", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s10Recipe.atlas = "images/inventoryimages/sweatermeo.xml"local s11Recipe = Recipe("sweatermus", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s11Recipe.atlas = "images/inventoryimages/sweatermus.xml"local s12Recipe = Recipe("sweaternot", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s12Recipe.atlas = "images/inventoryimages/sweaternot.xml"local s13Recipe = Recipe("sweatersco", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s13Recipe.atlas = "images/inventoryimages/sweatersco.xml"local s14Recipe = Recipe("sweatersta", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s14Recipe.atlas = "images/inventoryimages/sweatersta.xml"local s15Recipe = Recipe("sweaterumb", {}, GLOBAL.CUSTOM_RECIPETABS.SWEATERS, TECH.NONE, nil, nil, nil, nil, true)s15Recipe.atlas = "images/inventoryimages/sweaterumb.xml"s01Recipe.atlas = resolvefilepath("images/inventoryimages/sweaterbal.xml")s02Recipe.atlas = resolvefilepath("images/inventoryimages/sweaterber.xml")s03Recipe.atlas = resolvefilepath("images/inventoryimages/sweaterbol.xml")s04Recipe.atlas = resolvefilepath("images/inventoryimages/sweaterclo.xml")s05Recipe.atlas = resolvefilepath("images/inventoryimages/sweatercre.xml")s06Recipe.atlas = resolvefilepath("images/inventoryimages/sweaterhea.xml")s07Recipe.atlas = resolvefilepath("images/inventoryimages/sweaterind.xml")s08Recipe.atlas = resolvefilepath("images/inventoryimages/sweaterlla.xml")s09Recipe.atlas = resolvefilepath("images/inventoryimages/sweatermab.xml")s10Recipe.atlas = resolvefilepath("images/inventoryimages/sweatermeo.xml")s11Recipe.atlas = resolvefilepath("images/inventoryimages/sweatermus.xml")s12Recipe.atlas = resolvefilepath("images/inventoryimages/sweaternot.xml")s13Recipe.atlas = resolvefilepath("images/inventoryimages/sweatersco.xml")s14Recipe.atlas = resolvefilepath("images/inventoryimages/sweatersta.xml")s15Recipe.atlas = resolvefilepath("images/inventoryimages/sweaterumb.xml")-- The character select screen linesSTRINGS.CHARACTER_TITLES.mabel = "The Eccentric Sister"STRINGS.CHARACTER_NAMES.mabel = "Mabel"STRINGS.CHARACTER_DESCRIPTIONS.mabel = "*Has a lot of sweaters\n*Loves her pet pig\n*Tends to look on the bright side of things"STRINGS.CHARACTER_QUOTES.mabel = "\"We're somewhere where it looks loke we're nowhere\""-- Custom speech stringsSTRINGS.CHARACTERS.MABEL = require "speech_mabel"-- The character's name as appears in-game STRINGS.NAMES.MABEL = "Mabel Pines"-- The default responses of examining the characterSTRINGS.CHARACTERS.GENERIC.DESCRIBE.MABEL = {GENERIC = "It's Mabel!",ATTACKER = "That Mabel looks shifty...",MURDERER = "Murderer!",REVIVER = "Mabel, friend of ghosts.",GHOST = "Mabel could use a heart.",}-- Let the game know character is male, female, or robottable.insert(GLOBAL.CHARACTER_GENDERS.FEMALE, "mabel")AddMinimapAtlas("images/map_icons/mabel.xml")AddModCharacter("mabel")
 
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...