Hautex Posted June 14 Share Posted June 14 I have recently begun modding in DST, and I have run into quite the annoying problem. No matter how or when I do it, trying to use the player inventory component always returns nil. I've been looking into the issue for a few days now, and tried starting over with simple piece code like this that gives the player a spear (in modmain.lua): SpawnPrefab = GLOBAL.SpawnPrefab function Init(player) print("spawning item") local prefab = SpawnPrefab("spear") player.components.inventory:GiveItem(prefab) end AddSimPostInit(Init) But the spear never shows up, only .inventory nil errors do. If I try to use different PostInit functions, or GLOBAL.ThePlayer, or add nil checks it's all the same story. I also tried to use replica, but that also doesn't seem to function too well either. The mod is server-side, by the way. What am I missing here? Any help is very much appreciated. Link to comment Share on other sites More sharing options...
-LukaS- Posted June 14 Share Posted June 14 SimPostInit is too early do be handing out items to players. You should use PlayerPostInit for that. AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return end inst.components.inventory:GiveItem(GLOBAL.SpawnPrefab("spear")) end) 1 Link to comment Share on other sites More sharing options...
Hautex Posted June 14 Author Share Posted June 14 Strangely, I had already tried AddPlayerPostInit and it didn't work at all. Your code works though, so I guess it had something to do with the function part? In any case, thanks a ton! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now