rons0n Posted July 31, 2017 Share Posted July 31, 2017 So just tweaking another character and mine and I wanted to do this simple tweak. If my character dies and becomes a ghost how can I insert an item in its ghost inventory? Same goes when becoming human. I thought it'd be easy as: local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_speed_mod") inst.components.inventory:GiveItem("item") end local function onbecamehuman(inst) -- Set speed when reviving from ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "character_speed_mod", 2) inst.components.inventory:GiveItem("item") end I thought just slapping give item would make it do the trick but I guess im wrong. Appreciate the help! Link to comment Share on other sites More sharing options...
Lumina Posted July 31, 2017 Share Posted July 31, 2017 I'm not sure you can give item to a ghost, usually they have no inventory. I don't know why it's not working when the character is alive... Link to comment Share on other sites More sharing options...
rons0n Posted July 31, 2017 Author Share Posted July 31, 2017 I assumed they'd have an inventory because inst.components.inventoryitem.keepondeath = true is a thing, but im guessing on death = human inventory regardless. For both onbecamehuman and onbecameghost I keep getting this error: [00:00:41]: [string "scripts/components/inventory.lua"]:637: attempt to index field 'components' (a nil value) LUA ERROR stack traceback: scripts/components/inventory.lua:637 in (method) GiveItem (Lua) <636-769> ../mods/Frisk(Undertale OS4)/scripts/prefabs/frisk.lua:30 in (local) fn (Lua) <27-31> scripts/entityscript.lua:998 in (method) PushEvent (Lua) <985-1012> scripts/prefabs/player_common.lua:1110 in (local) fn (Lua) <1015-1119> scripts/entityscript.lua:998 in (method) PushEvent (Lua) <985-1012> scripts/stategraphs/SGwilson.lua:1185 in () ? (Lua) <1165-1188> =(tail call):-1 in () (tail) <-1--1> scripts/stategraph.lua:397 in (method) HandleEvents (Lua) <391-411> scripts/stategraph.lua:145 in (method) Update (Lua) <109-148> scripts/update.lua:218 in () ? (Lua) <149-228> Well If i ever do find a solution i'll probably edit this post. Thanks for your thoughts Link to comment Share on other sites More sharing options...
ZupaleX Posted July 31, 2017 Share Posted July 31, 2017 You see it complains about components being nil inside the inventory.lua at line 637. Did you check what is happening at that point? It test if the item you are trying to give has a components inventoryitem. But apparently the item you attempt to give doesn't even have a field components (?) What are you trying to give? Link to comment Share on other sites More sharing options...
rons0n Posted July 31, 2017 Author Share Posted July 31, 2017 (edited) Well I tried giving my character a custom prefab called friskbandaid which indeed does have the component inventoryitem. provided here: local assets = { Asset("ANIM", "anim/friskbandaid.zip"), Asset("ATLAS", "images/inventoryimages/friskbandaid.xml"), Asset("IMAGE", "images/inventoryimages/friskbandaid.tex"), } local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("friskbandaid") inst.AnimState:SetBuild("friskbandaid") inst.AnimState:PlayAnimation("idle") inst:AddTag("cattoy") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end MakeSmallBurnable(inst, TUNING.TINY_BURNTIME) MakeSmallPropagator(inst) MakeHauntableLaunchAndIgnite(inst) --------------------- inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "friskbandaid" inst.components.inventoryitem.atlasname = "images/inventoryimages/friskbandaid.xml" inst:AddComponent("stackable") inst:AddComponent("tradable") inst:AddComponent("healer") inst.components.healer:SetHealthAmount(TUNING.HEALING_LARGE * 1.2) return inst end STRINGS.NAMES.FRISKBANDAID = "Bandage" STRINGS.CHARACTERS.GENERIC.DESCRIBE.FRISKBANDAID = "*It has already been used many times." return Prefab("friskbandaid", fn, assets) If i try giving the item with onbecamehuman the game crashes before it even loads. onbecameghost it crashes when you become ghost Edited July 31, 2017 by rons0n Link to comment Share on other sites More sharing options...
Lumina Posted July 31, 2017 Share Posted July 31, 2017 And the item is working fine when you give it outside of this code ? Just to be sure. Link to comment Share on other sites More sharing options...
rons0n Posted July 31, 2017 Author Share Posted July 31, 2017 Yup, the item is craftable, starts with the characters starting inventory, and can be given by console. But alas doing it this way causes the game to crash and I have no idea why Link to comment Share on other sites More sharing options...
ZupaleX Posted August 1, 2017 Share Posted August 1, 2017 (edited) May we have the mod as a zip? Without seeing it is hard, but my guess is that you might not have included your item in the list of prefabs in your character lua script. Edited August 1, 2017 by ZupaleX Link to comment Share on other sites More sharing options...
rons0n Posted August 1, 2017 Author Share Posted August 1, 2017 (edited) Sorry for the late reply but here you go: Also an FYI, but i removed the giveitem line on onbecame human in the characters.lua inst.components.inventory:GiveItem("friskbandaid") I came to conclusion this ability isnt really necessary but I guess for people who want this ability they'd want an answer. Best of luck and thank you! Frisk(Undertale REVAMP).zip Edited August 1, 2017 by rons0n Link to comment Share on other sites More sharing options...
RedHairedHero Posted August 1, 2017 Share Posted August 1, 2017 (edited) 1 hour ago, rons0n said: Sorry for the late reply but here you go: Also an FYI, but i removed the giveitem line on onbecame human in the characters.lua inst.components.inventory:GiveItem("friskbandaid") I came to conclusion this ability isnt really necessary but I guess for people who want this ability they'd want an answer. Best of luck and thank you! Frisk(Undertale REVAMP).zip Well the error above is referencing onbecameghost ./mods/Frisk(Undertale OS4)/scripts/prefabs/frisk.lua:30 in (local) fn (Lua) <27-31> Have you tried the GiveItem only in the onbecamehuman function? Edited August 1, 2017 by RedHairedHero Link to comment Share on other sites More sharing options...
rons0n Posted August 1, 2017 Author Share Posted August 1, 2017 Yup I tried doing both only onbecamehuman and onbecameghost with the conclusion that onbecamehuman crashes before you even load in and onbecameghost crashing when turning into the ghost(as said a couple of posts ago). I can't possibly think of what im doing other than the game dislikes like giving custom prefabs while becoming human.  Link to comment Share on other sites More sharing options...
Lumina Posted August 1, 2017 Share Posted August 1, 2017 No real reason the game should dislike a function because the item is custom rather than base game. Also, does it works with a not custom prefab ? Link to comment Share on other sites More sharing options...
RedHairedHero Posted August 1, 2017 Share Posted August 1, 2017 (edited) You could call a function outside of onbecamehuman instead. local function onbecamehuman(inst) givebandaid(inst) end local function givebandaid(inst) inst.components.inventory:GiveItem("friskbandaid") end  or just call the function using the revive listener inst:ListenForEvent("ms_respawnedfromghost", givebandaid) Edited August 1, 2017 by RedHairedHero Link to comment Share on other sites More sharing options...
rons0n Posted August 1, 2017 Author Share Posted August 1, 2017 (edited) I tried doing it like so: local function givebandaid(inst) inst.components.inventory:GiveItem("friskbandaid") end -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when reviving from ghost (optional) givebandaid(inst) if inst:HasTag("frisk") then inst.components.locomotor:SetExternalSpeedMultiplier(inst, "frisk_speed_mod", 1.35) else inst.components.locomotor:SetExternalSpeedMultiplier(inst, "frisk_speed_mod", 2) end inst.components.talker:Say("*...But It Refused.", 2.5,true) end and local function givebandaid(inst) inst.components.inventory:GiveItem("friskbandaid") end local function onload(inst, data) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) inst:ListenForEvent("ms_respawnedfromghost", givebandaid) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end and it yielded the same component error Edited August 1, 2017 by rons0n Link to comment Share on other sites More sharing options...
RedHairedHero Posted August 1, 2017 Share Posted August 1, 2017 13 minutes ago, rons0n said: I tried doing it like so: local function givebandaid(inst) inst.components.inventory:GiveItem("friskbandaid") end -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when reviving from ghost (optional) givebandaid(inst) if inst:HasTag("frisk") then inst.components.locomotor:SetExternalSpeedMultiplier(inst, "frisk_speed_mod", 1.35) else inst.components.locomotor:SetExternalSpeedMultiplier(inst, "frisk_speed_mod", 2) end inst.components.talker:Say("*...But It Refused.", 2.5,true) end and local function givebandaid(inst) inst.components.inventory:GiveItem("friskbandaid") end local function onload(inst, data) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) inst:ListenForEvent("ms_respawnedfromghost", givebandaid) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end and it yielded the same component error Can you try changing the giveitem to another prefab like "spear" or another custom item you have to see where the issue lies? Link to comment Share on other sites More sharing options...
RedHairedHero Posted August 1, 2017 Share Posted August 1, 2017 Nevermind I found the issue, you have a spelling error inst:AddComponent("tradable") Link to comment Share on other sites More sharing options...
rons0n Posted August 1, 2017 Author Share Posted August 1, 2017 (edited) for my friskbandaid.lua? I checked the eel.lua in the games prefab files and its also spelt that way so i might be misunderstanding something here Also to add using spear using the method provided above also gives the same error component message. I really appreciate the help though, and thank you guys for looking into it. Edited August 1, 2017 by rons0n Link to comment Share on other sites More sharing options...
RedHairedHero Posted August 1, 2017 Share Posted August 1, 2017 7 minutes ago, rons0n said: for my friskbandaid.lua? I checked the eel.lua in the games prefab files and its also spelt that way so i might be misunderstanding something here Also to add using spear using the method provided above also gives the same error component message. I really appreciate the help though, and thank you guys for looking into it. I'm just bad at spelling ignore that last comment lol. Link to comment Share on other sites More sharing options...
rons0n Posted August 1, 2017 Author Share Posted August 1, 2017 It's all good! Well like I said before im content without having this ability I appreciate you guys looking into it, but im done seeking the answer for this problem. If you still wish to pursue have at it and post it here! As for me, ill continue tweaking on other things, cheers! Link to comment Share on other sites More sharing options...
DarkXero Posted August 1, 2017 Share Posted August 1, 2017 local item = SpawnPrefab("friskbandaid") inst.components.inventory:GiveItem(item) Â Link to comment Share on other sites More sharing options...
rons0n Posted August 1, 2017 Author Share Posted August 1, 2017 Tried both only onbecamehuman and onbecameghost and still yielded the component 637 error posted a few posts ago, but nice seeing you again Xero! Link to comment Share on other sites More sharing options...
DarkXero Posted August 2, 2017 Share Posted August 2, 2017 2 hours ago, rons0n said: still yielded the component 637 error posted a few posts ago Well then you didn't replace all instances correctly. I setup my code as local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_speed_mod") end local function onbecamehuman(inst) -- Set speed when reviving from ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "character_speed_mod", 2) end local function giveitem(inst) local item = SpawnPrefab("axe") inst.components.inventory:GiveItem(item) end local function OnLoad(inst, data) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) inst:ListenForEvent("ms_respawnedfromghost", giveitem) inst:ListenForEvent("ms_becameghost", giveitem) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end local function master_postinit(inst) inst.OnLoad = OnLoad inst.OnNewSpawn = OnLoad end which is what the template would look like. I kill myself and then revive and see I have two axes in my inventory. Link to comment Share on other sites More sharing options...
rons0n Posted August 2, 2017 Author Share Posted August 2, 2017 I see my silly mistake, thanks DarkXero. Basically I pulled a stupid and put the line inst.components.inventory:GiveItem(item) into the onbecame human rather than leaving it in giveitem. This is what I get for being dumb Well regardless, much thanks! 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