Jump to content

Adding a component?


Recommended Posts

Ok. So I want the ghost to drop nightmare fuel.

 

 But the problem is, the ghost.lua prefab doesn't have a "lootdropper" component. So I'm not really sure how I would add that to my mod. Any ideas? I know the answer is probably simple.   

 

Here is my code right now.   

--For Ghostsfunction ghostpostinit(inst)	inst.components.lootdropper:SetLoot("nightmarefuel") --No lootdropper component 	inst.components.lootdropper.numrandomloot = 0endAddPrefabPostInit("ghost", ghostpostinit)
Link to comment
Share on other sites

Ok. Sorry, I was doing this late last night and I had to sleep. But I will elaborate on everything.   

 

So, my original code (the one I posted) doesn't crash the game, but my HUD disappears whenever I debug spawn the ghost for some reason. (My inventory, crafting tab, health bar, hunger bar, sanity bar, clock, etc. They all disappear).

 

Anyway, the code doesn't work because the ghost still doesn't drop the nightmare fuel. I checked my logs and it said this. 

Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 

So, I thought it was because the ghost.lua prefab doesn't have a "lootdropper" component to it. That's why it can't drop any items.  

 

Then I did what @seronis suggested by using the inst.AddComponent("lootdropper") into my modmain.lua and still doesn't work. 

Link to comment
Share on other sites

So, my original code (the one I posted) doesn't crash the game, but my HUD disappears whenever I debug spawn the ghost for some reason. (My inventory, crafting tab, health bar, hunger bar, sanity bar, clock, etc. They all disappear). I'm not sure if this is due to another complication with another mod or not. (I will test this when I get back from work).

 

That's caused by missing assets and alike.

 

Anyway, the code doesn't work because the ghost still doesn't drop the nightmare fuel. I checked my logs and it said this.

 

It always spams with "could not unload orphaned resource", that is unrelated to the crash. Look for an indent part (the lines above a "Lua stack traceback")

 

Then I did what @seronis suggested by using the inst.AddComponent("lootdropper"). Same result.

 

I hope you used a collon ':' instead of a full stop '.'

Link to comment
Share on other sites

Ok. So it was the collon. (Yeah, I'm really tired sorry. x_x)  

 

I revised my code to this

--For Ghostsfunction ghostpostinit(inst)	inst:AddComponent("lootdropper")	inst.components.lootdropper:SetLoot("nightmarefuel")	inst.components.lootdropper.numrandomloot = 0end

And the HUD vanishing thing is not a problem anymore. So don't worry about that.  

 

The thing is, whenever I kill the ghost it crashes the game and I get this messsage.   

LUA ERROR stack traceback:        =[C] in function 'ipairs'        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/lootdropper.lua(112,1) in function 'GenerateLoot'        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/lootdropper.lua(209,1) in function 'DropLoot'        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/stategraphs/SGghost.lua(112,1)        =(tail call) ?        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/stategraph.lua(358,1) in function 'HandleEvents'        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/stategraph.lua(131,1) in function 'Update'        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/update.lua(127,1)scripts/frontend.lua(723,1) SCRIPT ERROR! Showing error screen	

Any ideas? or am I just writing the code wrong?

Link to comment
Share on other sites

The thing is, whenever I kill the ghost it crashes the game and I get this messsage.   

LUA ERROR stack traceback

Any ideas? or am I just writing the code wrong?

 

The lines above the stack traceback please.

 

EDIT: I assume though, it's either meant to be a loot table or because the randomnumber is zero.

Link to comment
Share on other sites

.../dont_starve/data/scripts/components/lootdropper.lua:112: bad argument #1 to 'ipairs' (table expected, got string)

Ok, this is what is above the stack traceback.  

 

 

I got it to work now. I am so stupid sometimes. I re-wrote my code to this. 

--For Ghostsfunction ghostpostinit(inst)	inst:AddComponent("lootdropper")	inst.components.lootdropper:SetLoot({"nightmarefuel"})	inst.components.lootdropper.numrandomloot = 0end

I just forgot to add the {curly brackets} inside the SetLoot(). It's supposed to be an array, not a string. I am so dumb. x_x    

 

Thanks for the help everybody. Especially, Mobbstar and Seronis. Thank you. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...