Argonwolf Posted January 7, 2021 Share Posted January 7, 2021 I tried using the following code: inst.components.inventory:GiveItem("boards",3) But it tells me that components is a nil value, even though I know inst is a reference to a player. The same syntax is used in the consolecommands.lua file to give the player an item with the c_give command. Anybody know what I'm doing wrong? Link to comment https://forums.kleientertainment.com/forums/topic/125806-how-do-i-correctly-add-an-item-to-a-players-inventory/ Share on other sites More sharing options...
penguin0616 Posted January 7, 2021 Share Posted January 7, 2021 Mind providing your code? That single line is insufficient. 2 Link to comment https://forums.kleientertainment.com/forums/topic/125806-how-do-i-correctly-add-an-item-to-a-players-inventory/#findComment-1414107 Share on other sites More sharing options...
Thomas_klei Posted January 7, 2021 Share Posted January 7, 2021 for i = 1 ,amount do inst.components.inventory:GiveItem(SpawnPrefab("Name_Of_Prefab")) end --function Inventory:GiveItem(inst, slot, src_pos) inst = item, slot = slot it will go too 1 Link to comment https://forums.kleientertainment.com/forums/topic/125806-how-do-i-correctly-add-an-item-to-a-players-inventory/#findComment-1414154 Share on other sites More sharing options...
Argonwolf Posted January 7, 2021 Author Share Posted January 7, 2021 13 hours ago, penguin0616 said: Mind providing your code? That single line is insufficient. Certainly! AddPlayerPostInit(function(inst) inst:DoPeriodicTask(0.25, function(inst) inst.components.inventory:GiveItem("boards") end) end) 10 hours ago, thomas4846 said: for i = 1 ,amount do inst.components.inventory:GiveItem(SpawnPrefab("Name_Of_Prefab")) end --function Inventory:GiveItem(inst, slot, src_pos) inst = item, slot = slot it will go too I tried this and it says SpawnPrefab is a nil value. Link to comment https://forums.kleientertainment.com/forums/topic/125806-how-do-i-correctly-add-an-item-to-a-players-inventory/#findComment-1414353 Share on other sites More sharing options...
penguin0616 Posted January 8, 2021 Share Posted January 8, 2021 inst.components should be present, unless DoPeriodicTask calls your function with a non-player. Also, GLOBAL.SpawnPrefab 2 1 Link to comment https://forums.kleientertainment.com/forums/topic/125806-how-do-i-correctly-add-an-item-to-a-players-inventory/#findComment-1414431 Share on other sites More sharing options...
Argonwolf Posted January 8, 2021 Author Share Posted January 8, 2021 15 hours ago, thomas4846 said: for i = 1 ,amount do inst.components.inventory:GiveItem(SpawnPrefab("Name_Of_Prefab")) end --function Inventory:GiveItem(inst, slot, src_pos) inst = item, slot = slot it will go too 54 minutes ago, penguin0616 said: inst.components should be present, unless DoPeriodicTask calls your function with a non-player. Also, GLOBAL.SpawnPrefab That did the trick, thank you very much for your help, both of you. I may acquaint myself with this game's odd engine structure yet! Link to comment https://forums.kleientertainment.com/forums/topic/125806-how-do-i-correctly-add-an-item-to-a-players-inventory/#findComment-1414450 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