Hyaciao Posted September 30, 2015 Share Posted September 30, 2015 To summarize I'm trying to give a character the ability to create or spawn an item into their inventory with push of a button & in the future consume a type of item in-exchange for the ability to create an item. [Kinda like crafting without actually crafting] I've read into Milk's thread about spawning Prefabs and looked at the pigking trader code as well. 1) I'm not 100% sure how I should be calling up the function2) I'm not sure if I'm simply using the wrong declaration/identifier/target as I've tried "player.components" & "self" which gave the same nil error.3) I probably have no idea what i'm doing so i'll just shut up and listen. I know the " - -" changes the "inst." part into a comment in lua. I'm just highlighting the main part with it here as this code gives a nil declaration error. Below I'm using smallmeat in the code to test. Also this is in modmain.lua for reference encase I misplaced it. AddModRPCHandler(modname, "POCKETFOOD", function(player) if not player:HasTag("playerghost") and player.prefab == "fluff" then if not player.pocketfoodincooldown then player.components.talker:Say("Oh I found something.") player.components.health:DoDelta(-1) player.components.sanity:DoDelta(-5)-- inst.components.inventory:GiveItem(SpawnPrefab("smallmeat")) end player:DoTaskInTime(60, function() player.components.talker:Say("I'm all rest up") player.pocketfoodincooldown = false end) else player.components.talker:Say("I need some time.") end endend) Link to comment https://forums.kleientertainment.com/forums/topic/58221-help-how-to-spawn-an-itemprefab-with-a-push-of-a-button/ Share on other sites More sharing options...
DarkXero Posted September 30, 2015 Share Posted September 30, 2015 @Hyaciao:AddModRPCHandler(modname, "POCKETFOOD", function(player) if not player:HasTag("playerghost") and player.prefab == "fluff" then if not player.pocketfoodincooldown then player.components.talker:Say("Oh I found something.") player.components.health:DoDelta(-1) player.components.sanity:DoDelta(-5) local item = GLOBAL.SpawnPrefab("smallmeat") player.components.inventory:GiveItem(item) player:DoTaskInTime(60, function() player.components.talker:Say("I'm all rest up") player.pocketfoodincooldown = false end) else player.components.talker:Say("I need some time.") end endend) Link to comment https://forums.kleientertainment.com/forums/topic/58221-help-how-to-spawn-an-itemprefab-with-a-push-of-a-button/#findComment-677026 Share on other sites More sharing options...
Hyaciao Posted October 7, 2015 Author Share Posted October 7, 2015 @DarkXero As always thank you good sir for your help. Also sorry for the late reply. How have you been? Link to comment https://forums.kleientertainment.com/forums/topic/58221-help-how-to-spawn-an-itemprefab-with-a-push-of-a-button/#findComment-678552 Share on other sites More sharing options...
DarkXero Posted October 7, 2015 Share Posted October 7, 2015 How have you been? Link to comment https://forums.kleientertainment.com/forums/topic/58221-help-how-to-spawn-an-itemprefab-with-a-push-of-a-button/#findComment-678555 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