• Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About meltorefas

  • Rank
    Junior Member
  1. I am using AddPrefabPostInit, but otherwise yes. Your explanation makes sense, I understand the error now. Adding an If statement was the first thing I tried when I encountered the problem, and all it did was prevent the item from being added (which, while it did prevent the crash, also failed to accomplish the mod's purpose). However, I have changed things since then, so I tried the If statement again just now and the it worked fine. So I guess something else was causing the error the first time I tried it, which threw me off. At any rate, thanks for the explanation, and for the incentive to try it again.
  2. I... pretty much already did, above? But if you really want: local function add_mpower (inst) inst:ListenForEvent("itemlose", OnDropCheckMPower) inst:DoTaskInTime(5, function(inst) inst.components.inventory:GiveItem(GLOBAL.SpawnPrefab("mpower")) end) end As I said, it works fine in a forest world, but if I include caves it crashes AFTER the item appears in the inventory, claiming that 'inventory' is a nil value. Just to be absolutely clear: The second line of the function is the one returning the error, because it references inst.components.inventory. I have no idea what causes it to fail when caves are included in worldgen.
  3. Yeah, I tried that, at which point it no longer gives them the item, but again only if Caves were generated. The thing is, other items from their starting inventory appear just fine, and they can pick stuff up. Their inventory is obviously *there*, but for some reason when running with Caves generated it just acts like it isn't (at least for this one script in modmain).
  4. Okay, it turns out my mod crashes the game if it is run on a server that is using caves. The offending line is simply this: inst.components.inventory:GiveItem(GLOBAL.SpawnPrefab("mpower")) The error returned (if caves were generated) is "attempt to index field 'inventory' (a nil value)" I even tried changing the line to this: inst:DoTaskInTime(5, function(inst) inst.components.inventory:GiveItem(GLOBAL.SpawnPrefab("mpower")) end) In this case the player spawns, after 5 seconds the item appears in their inventory. And then the game crashes with the same error. So... I have no idea what is going on? The inventory is obviously there. Any help would be appreciated.
  5. Hey, sorry it took so long for me to reply, been sick (and I forgot I posted this >.>). I actually got this working on my own, turned out I had a simple problem and the method I was using was fine once I fixed it (in my case the issue was one of mod priorities). Thanks for the reply though!
  6. Basically, I am just trying to add an item of my own creation to the starting inventories of a set of characters. I've verified my item exists by spawning it with the console. I have tried adding it using AddPrefabPostInit but I haven't figured out what to put in the function itself to add the item. If anyone can advise me on how to do this I would appreciate it, as my searches turned up nothing useful. Thanks.