Jump to content

Recommended Posts

I'm working on additional perks for my Bender character and I want to make him function like a crockpot.When you click on him he should open the four slots to put your food in.I want him to still make sound when cooking and glow, just like the crockpot.I guess when it's ready you have to click on him to harvest your prepared food.So far I added this under local fn = function(inst):

inst:AddComponent("stewer")    inst.components.stewer.onstartcooking = startcookfn    inst.components.stewer.oncontinuecooking = continuecookfn    inst.components.stewer.oncontinuedone = continuedonefn    inst.components.stewer.ondonecooking = donecookfn    inst.components.stewer.onharvest = harvestfn	inst:AddComponent("container")    inst.components.container.itemtestfn = itemtest    inst.components.container:SetNumSlots(4)    inst.components.container.widgetslotpos = slotpos    inst.components.container.widgetanimbank = "ui_cookpot_1x4"    inst.components.container.widgetanimbuild = "ui_cookpot_1x4"    inst.components.container.widgetpos = Vector3(200,0,0)    inst.components.container.widgetbuttoninfo = widgetbuttoninfo    inst.components.container.acceptsstacks = false    inst.components.container.onopenfn = onopen    inst.components.container.onclosefn = onclose	inst:AddComponent("lootdropper")    inst:AddComponent("workable")
The rest of the things still needed are tricky for me. Can someone show me what I still have to add in the prefab?

Whilst he is cooking it could be a heat source for him , but I think he would have to learn how to turn himself into a portable crockpot as gaining this on day 1 seems a bit over the top

But Bender was built that way. Edited by infernalthing

Can someone help me with this? Anyway I added a bunch of things from the crookpot in the prefab but the game closes as soon as I load my save. The log.txt says there's an error with in function 'customfn'.Anyway, here's the things I added:

local fn = function(inst)		-- choose which sounds this character will play	inst.soundsname = "wx78"	-- a minimap icon must be specified	inst.MiniMapEntity:SetIcon( "wx78.png" )	-- todo: Add an example special power here.	inst:AddComponent("firebug")	inst.components.firebug.prefab = "willowfire"		inst.components.health.fire_damage_scale = 0	inst.components.health.absorb = 0.7	inst.components.eater.ignoresspoilage = true	inst.components.health:SetMaxHealth(TUNING.WILSON_HEALTH * 1.5 )	inst.components.hunger:SetMax(TUNING.WILSON_HUNGER * 1.5 )	inst.components.combat.damagemultiplier = 1.5	inst.components.temperature.inherentinsulation = 30*12	inst:AddTag("fridge")	--crockpot    inst:AddComponent("stewer")    inst.components.stewer.onstartcooking = startcookfn    inst.components.stewer.oncontinuecooking = continuecookfn    inst.components.stewer.oncontinuedone = continuedonefn    inst.components.stewer.ondonecooking = donecookfn    inst.components.stewer.onharvest = harvestfn    inst:AddComponent("container")    inst.components.container.itemtestfn = itemtest    inst.components.container:SetNumSlots(4)    inst.components.container.widgetslotpos = slotpos    inst.components.container.widgetanimbank = "ui_cookpot_1x4"    inst.components.container.widgetanimbuild = "ui_cookpot_1x4"    inst.components.container.widgetpos = Vector3(200,0,0)    inst.components.container.widgetbuttoninfo = widgetbuttoninfo    inst.components.container.acceptsstacks = false    inst.components.container.onopenfn = onopen    inst.components.container.onclosefn = onclose    inst:AddComponent("lootdropper")    inst:AddComponent("workable")    local light = inst.entity:AddLight()    inst.Light:Enable(false)	inst.Light:SetRadius(.6)    inst.Light:SetFalloff(1)    inst.Light:SetIntensity(.5)    inst.Light:SetColour(235/255,62/255,12/255)    --inst.Light:SetColour(1,0,0)endlocal widgetbuttoninfo = {	text = "Cook",	position = Vector3(0, -165, 0),	fn = function(inst)		inst.components.stewer:StartCooking()		end,		validfn = function(inst)		return inst.components.stewer:CanCook()	end,}local function itemtest(inst, item, slot)	if cooking.IsCookingIngredient(item.prefab) then		return true	endendlocal function startcookfn(inst)	--inst.AnimState:PlayAnimation("cooking_loop", true)	--play a looping sound	inst.SoundEmitter:KillSound("snd")	inst.SoundEmitter:PlaySound("dontstarve/common/cookingpot_rattle", "snd")	inst.Light:Enable(true)endlocal function onopen(inst)	--inst.AnimState:PlayAnimation("cooking_pre_loop", true)	inst.SoundEmitter:PlaySound("dontstarve/common/cookingpot_open", "open")	inst.SoundEmitter:PlaySound("dontstarve/common/cookingpot", "snd")endlocal function onclose(inst)	if not inst.components.stewer.cooking then		--inst.AnimState:PlayAnimation("idle_empty")		inst.SoundEmitter:KillSound("snd")	end	inst.SoundEmitter:PlaySound("dontstarve/common/cookingpot_close", "close")endlocal function donecookfn(inst)	--inst.AnimState:PlayAnimation("cooking_pst")	--inst.AnimState:PushAnimation("idle_full")	--inst.AnimState:OverrideSymbol("swap_cooked", "cook_pot_food", inst.components.stewer.product)		inst.SoundEmitter:KillSound("snd")	inst.SoundEmitter:PlaySound("dontstarve/common/cookingpot_finish", "snd")	inst.Light:Enable(false)	--play a one-off soundendlocal function continuedonefn(inst)	--inst.AnimState:PlayAnimation("idle_full")	--inst.AnimState:OverrideSymbol("swap_cooked", "cook_pot_food", inst.components.stewer.product)endlocal function continuecookfn(inst)	--inst.AnimState:PlayAnimation("cooking_loop", true)	--play a looping sound	inst.Light:Enable(true)	inst.SoundEmitter:PlaySound("dontstarve/common/cookingpot_rattle", "snd")endlocal function harvestfn(inst)	--inst.AnimState:PlayAnimation("idle_empty")end

[MENTION=17097]infernalthing[/MENTION] Don't you need to return inst at the end of the function? Also mind sharing the log error line?

Can you tell me how exactly return inst? I'm not really good at understanding some things in lua.
...ze shet/DS 11/mods/Bender/scripts/prefabs/bender.lua:60: variable 'startcookfn' is not declaredLUA ERROR stack traceback:        =[C] in function 'error'        D:/ze shet/DS 11/data/scripts/strict.lua(23,1)        D:/ze shet/DS 11/mods/Bender/scripts/prefabs/bender.lua(60,1) in function 'customfn'        D:/ze shet/DS 11/data/scripts/prefabs/player_common.lua(295,1) in function 'fn'        D:/ze shet/DS 11/data/scripts/mainfunctions.lua(61,1)        =[C] in function 'SpawnPrefab'        D:/ze shet/DS 11/data/scripts/mainfunctions.lua(94,1) in function 'SpawnPrefab'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(293,1) in function 'PopulateWorld'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(612,1) in function 'DoInitGame'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(756,1) in function 'cb'        D:/ze shet/DS 11/data/scripts/saveindex.lua(158,1)	...        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/saveindex.lua(60,1) in function 'Load'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(861,1) in function 'callback'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(253,1) in function 'Set'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(213,1)        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(211,1) in function 'Load'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(860,1) in main chunk        =[C] in function 'require'        D:/ze shet/DS 11/data/scripts/mainfunctions.lua(553,1)D:/ze shet/DS 11/data/scripts/frontend.lua(276,1)	SCRIPT ERROR! Showing error screenD:/ze shet/DS 11/data/scripts/gamelogic.lua:294: could not spawn player characterLUA ERROR stack traceback:        =[C] in function 'assert'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(294,1) in function 'PopulateWorld'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(612,1) in function 'DoInitGame'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(756,1) in function 'cb'        D:/ze shet/DS 11/data/scripts/saveindex.lua(158,1)        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/saveindex.lua(141,1) in function 'GetSaveData'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(758,1) in function 'DoLoadWorld'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(795,1) in function 'LoadSlot'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(827,1) in function 'complete_callback'        D:/ze shet/DS 11/data/scripts/upsell.lua(26,1) in function 'UpdateGamePurchasedState'	...        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/saveindex.lua(60,1) in function 'Load'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(861,1) in function 'callback'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(253,1) in function 'Set'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(213,1)        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(211,1) in function 'Load'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(860,1) in main chunk        =[C] in function 'require'        D:/ze shet/DS 11/data/scripts/mainfunctions.lua(553,1)

Can you tell me how exactly return inst? I'm not really good at understanding some things in lua.

...ze shet/DS 11/mods/Bender/scripts/prefabs/bender.lua:60: variable 'startcookfn' is not declaredLUA ERROR stack traceback:        =[C] in function 'error'        D:/ze shet/DS 11/data/scripts/strict.lua(23,1)        D:/ze shet/DS 11/mods/Bender/scripts/prefabs/bender.lua(60,1) in function 'customfn'        D:/ze shet/DS 11/data/scripts/prefabs/player_common.lua(295,1) in function 'fn'        D:/ze shet/DS 11/data/scripts/mainfunctions.lua(61,1)        =[C] in function 'SpawnPrefab'        D:/ze shet/DS 11/data/scripts/mainfunctions.lua(94,1) in function 'SpawnPrefab'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(293,1) in function 'PopulateWorld'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(612,1) in function 'DoInitGame'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(756,1) in function 'cb'        D:/ze shet/DS 11/data/scripts/saveindex.lua(158,1)	...        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/saveindex.lua(60,1) in function 'Load'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(861,1) in function 'callback'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(253,1) in function 'Set'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(213,1)        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(211,1) in function 'Load'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(860,1) in main chunk        =[C] in function 'require'        D:/ze shet/DS 11/data/scripts/mainfunctions.lua(553,1)D:/ze shet/DS 11/data/scripts/frontend.lua(276,1)	SCRIPT ERROR! Showing error screenD:/ze shet/DS 11/data/scripts/gamelogic.lua:294: could not spawn player characterLUA ERROR stack traceback:        =[C] in function 'assert'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(294,1) in function 'PopulateWorld'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(612,1) in function 'DoInitGame'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(756,1) in function 'cb'        D:/ze shet/DS 11/data/scripts/saveindex.lua(158,1)        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/saveindex.lua(141,1) in function 'GetSaveData'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(758,1) in function 'DoLoadWorld'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(795,1) in function 'LoadSlot'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(827,1) in function 'complete_callback'        D:/ze shet/DS 11/data/scripts/upsell.lua(26,1) in function 'UpdateGamePurchasedState'	...        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/saveindex.lua(60,1) in function 'Load'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(861,1) in function 'callback'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(253,1) in function 'Set'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(213,1)        =[C] in function 'GetPersistentString'        D:/ze shet/DS 11/data/scripts/playerprofile.lua(211,1) in function 'Load'        D:/ze shet/DS 11/data/scripts/gamelogic.lua(860,1) in main chunk        =[C] in function 'require'        D:/ze shet/DS 11/data/scripts/mainfunctions.lua(553,1)
What's causing the current error is simply the order of declaration/use of local variables in the code. You're using startcookfn inside fn, but startcookfn only gets declared later (local variables can be tricky, this wouldn't happen with global ones; not that I'm suggesting you should use global ones instead). Just cut the definition of fn and paste it at the end of the file (but before the file's return statement!).

looks like you forgot to add the functions:

    inst.components.stewer.onstartcooking = startcookfn    inst.components.stewer.oncontinuecooking = continuecookfn    inst.components.stewer.oncontinuedone = continuedonefn    inst.components.stewer.ondonecooking = donecookfn    inst.components.stewer.onharvest = harvestfn
all the functions behind the "=" must be declared/defined above those linesEdit:damnit, I'm slow at typing

looks like you forgot to add the functions:

    inst.components.stewer.onstartcooking = startcookfn    inst.components.stewer.oncontinuecooking = continuecookfn    inst.components.stewer.oncontinuedone = continuedonefn    inst.components.stewer.ondonecooking = donecookfn    inst.components.stewer.onharvest = harvestfn
all the functions behind the "=" must be declared/defined above those linesEdit:damnit, I'm slow at typing
How do I declare those functions?

[MENTION=17097]infernalthing[/MENTION] whats happening is that your assigining a variable to a variable but there is no variable on the second half. Add a () to the end of each addition as im assuming your trying to assign the variable to the result of a function?

I fixed the crash but but now there's a new problem.I can't open the slots by clicking on my character!I made him inspectable, even showing his status but I can't click on him.I guess characters aren't meant to be clickable, but is there a solution to this?

One obvious problem (without actually looking at the issue) is that the character is already registered to handle all sorts of click behaviors, for instance, with a crockpot, when you click on the crockpot with food on the cursor, it puts it in the crockpot. The same behavior as a player may put it in your inventory, right clicking will eat it. Not saying that these behaviors are incompatible, but more that they're already defined so you can't do it as simply as a crockpot itself might, since the crockpot itself is otherwise a pretty simple world entity that only serves that purpose. Also, adding the workable component is a bit weird. That is a component that deals with things that can be chopped down, or hammered down, or picked. You haven't defined it further so it probably won't do anything, but it could have weird consequences if you were to fight a deerclops or something.The whole idea of the player being a container is a bit weird to be honest. I can't say with any certainty that you can't make it work, but the game certainly doesn't expect the player to be a container. I would start your game and go into the console and type:GetPlayer().components.container:Open(GetPlayer())And see if it opens the container like you expect. If it does, then it's an issue with collecting the open action when you click on the player, probably because of some conflict. If it doesn't then either there's a problem properly displaying the inventory widget, or some other weird problem related to the player itself being a container.If I were to attempt something like this, I would instead make something like a cooker module that would be maybe a BODY slot item, like a backpack. That cooker module would be a 4 slot container like a mini-backpack. I'd then work a right-click action into that item that would let you cook the food in that container when it was equipped. That way you could also pretty easily do the graphics overrides the same way as any other armor piece does. Actually working it into the player is awkward, maybe doable, but it would get probably much more complex than you are realizing. Good luck though :)

The container opens with the console command but pressing cook makes the game crash. It says : components/stewer.lua:75: attempt to perform arithmetic on local 'cooktime'(a nil value)A special slot like module was the first thing I had in mind but it was to hard for me (if it's doable) but looking in the crockpot related files made me think I can make the player openable.Can the module idea work? I have no idea how that could be done.

Your crash is not one that I would expect, but looking at the code it makes sense.Cooking isn't really meant to be done with anything but a crockpot ("cookpot"). Trying to do otherwise will be a reasonable challenge. All of the recipes are added to the crockpot prefab directly. Your attempt to cook crashed the game because basically your character has no recipes, so whatever it tries to cook, it has no cooking time.cookpot adds recipes with 'local cooking = require("cooking")', it then iterates through cooking and adds the results to its prefab list. I think you might be able to do something similar, but it's getting to the point where you'll have a real trouble proceeding with help. Doing it with a module or something would give you similar issues.How I recommend you tackle it would be like this:1) Make a mod if you haven't. Don't edit the data files directly. Learn how to properly add prefabs and add components to existing prefabs through the mod interface. 2) In your mod, make a duplicate of the cookpot with a different name. Figure out how to spawn it, and figure out how to get it to cook like a normal cookpot. Make sure you can have both the standard cookpot and your custom cookpot co-existing in the world.3) Make the duplicate cookpot into an inventory item and figure out a way to pick it up. You'll have to understand how the SceneAction handlers work to do this. This is going to be a challenge because the default pick-up action is left-click and that is also the default open-cookpot action.4) Find a way to open the cookpot from the inventory. This will take the same skills as #4 really. 5) Armed with all of that knowledge, you would be able to either have a cookpot-type item that can be equipped (if you make it an equippable item) or you can probably override some behavior to allow you to open the container component of the player. At that point it's a matter of what you think works best for your mod, more a style issue than a technical issue. I prefer the equippable item idea because of the way the player is very special for handling inputs. Doing this whole thing is probably a bit beyond where you're at right now, but I think it's something you could learn to do if you take it one step at a time.

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