Jump to content

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
https://forums.kleientertainment.com/forums/topic/48755-adding-a-component/
Share on other sites

I tried that, doesn't work for some reason

Quite difficult to determine the problem with just "doesn't work". Please elaborate on what happened when you tried it. Did it crash the game? Prevent a crash? Error messages, logs?

Edited by Blueberrys

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. 

Edited by Pianobeats

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

Edited by Mobbstar

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?

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.

Edited by Mobbstar
.../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. 

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