owlluna Posted July 20, 2021 Share Posted July 20, 2021 (edited) Hullo everyone! This is my first time posting on the forums despite reading a ton of threads, so please forgive my formatting if it's still a little rough! To cut to the chase, I'm creating a moleworm character that has a custom pair of sunglasses that negates his molevision. I have this code that functions as it should with the Equip/UnEquip listed under the spoiler. Spoiler local function SetMoleVision(inst, enable) if inst:HasTag("molehuman") then if not inst:HasTag("playerghost") then if TheWorld.state.isday and not TheWorld:HasTag("cave") then seasoncheck(inst) inst.components.playervision:ForceNightVision(true) inst.components.playervision:SetCustomCCTable("MOLEVISION_COLOURCUBES") end local item = inst.replica.inventory and inst.replica.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) if item and item.prefab == "spectamoles" then seasoncheck(inst) inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) else seasoncheck(inst) inst.components.playervision:ForceNightVision(true) inst.components.playervision:SetCustomCCTable(MOLEVISION_COLOURCUBES) return end end end end The image examples of what's happening in-game under this spoiler: Spoiler This is how the item is supposed to work - it changes the character vision to "normal" ---- This one is the source of my headaches. lol So far I've tried adding the "WatchWorld/Listen" events in the common_postinit, the master_postinit, as well as in the onload function. I was thinking my next option would be having it save the equipment data...so I tried this: Spoiler local function OnSave (inst, data) data.equip = inst.replica.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) print("data", data.equip) end And that resulted in this error: [00:02:02]: [string "scripts/dumper.lua"]:112: Cannot dump userdata (Transform (1D9C37B8) - unknown) LUA ERROR stack traceback: =[C]:-1 in (global) error (C) <-1--1> scripts/dumper.lua:112 in () ? (Lua) <98-113> =(tail call):-1 in () (tail) <-1--1> scripts/dumper.lua:151 in () ? (Lua) <141-159> =(tail call):-1 in () (tail) <-1--1> scripts/dumper.lua:151 in () ? (Lua) <141-159> =(tail call):-1 in () (tail) <-1--1> scripts/dumper.lua:151 in () ? (Lua) <141-159> =(tail call):-1 in () (tail) <-1--1> scripts/dumper.lua:225 in (global) DataDumper (Lua) <77-245> scripts/networking.lua:282 in (global) SerializeUserSession (Lua) <278-295> scripts/components/playerspawner.lua:92 in (field) fn (Lua) <81-101> scripts/scheduler.lua:177 in (method) OnTick (Lua) <155-207> scripts/scheduler.lua:371 in (global) RunScheduler (Lua) <369-377> scripts/update.lua:185 in () ? (Lua) <164-243> [00:02:02]: data 116935 - spectamoles(LIMBO) [00:02:02]: data 116935 - spectamoles(LIMBO) So at this point I've reached the extent of my noob LUA knowledge... I'm mainly an artist and this is my very first character mod project! My understanding of LUA is literally the age of this project at 2 weeks lol. I'm still growing and my codes could probably be written waaaay more efficiently, but I'm getting there! Thanks in advance for anyone who can help! Edited July 20, 2021 by owlluna Link to comment Share on other sites More sharing options...
Thomas Die Posted July 20, 2021 Share Posted July 20, 2021 in all honesty i would just uh local function onload(inst) inst:DoTaskInTime(math.random() , function(inst) inst.components.inventory:Equip(inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)) end) end Link to comment Share on other sites More sharing options...
owlluna Posted July 20, 2021 Author Share Posted July 20, 2021 (edited) 28 minutes ago, Thomas Die said: in all honesty i would just uh local function onload(inst) inst:DoTaskInTime(math.random() , function(inst) inst.components.inventory:Equip(inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)) end) end It worked!! Of course the solution would be the one of the many functions I understand the least lol Thank you so much @Thomas Die!! Edited July 20, 2021 by owlluna 1 Link to comment Share on other sites More sharing options...
owlluna Posted July 20, 2021 Author Share Posted July 20, 2021 (edited) I don't have the ability to change my thread title to solved yet, but if any mods see this, please change [HELP] to [SOLVED]! Thank you! Never mind, looks like I just needed to edit the first post. Edited July 20, 2021 by owlluna Link to comment Share on other sites More sharing options...
owlluna Posted July 20, 2021 Author Share Posted July 20, 2021 (edited) @Thomas Die Sorry for the ping! A little update since I did more testing. The first issue was resolved but after some more testing today, it brought on another. Spoiler local function onload(inst) inst:DoTaskInTime(math.random(), function(inst) inst.components.inventory:Equip(inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)) end) -- Functional inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if TheWorld.state.isday and not TheWorld:HasTag("cave") then local item = inst.replica.inventory and inst.replica.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) if item and item.prefab == "spectamoles" then inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) inst.components.talker:Say("Take that sun!") else inst.components.talker:Say("It's too bright! Where are my glasses?!") --[[ This one no longer triggers on spawn. :< It's supposed to indicate to the player to wear the glasses ASAP. just in case the blinding light wasn't enough lol.]]-- end end if TheWorld:HasTag("cave") then inst.components.talker:Say("Home sweet home...now where's Wufus?") end if TheWorld.state.isdusk or TheWorld.state.isnight and not TheWorld:HasTag("cave") then inst.components.talker:Say("Who needs the limelight when you got a nightlife?") end if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end My talker components aren't triggering onload, so I tried figuring it out on my own by adding a DoTaskInTime function like this: DoTaskInTime(0, function(inst) inst.components.talker:Say("It's too bright out! Where are my glasses?!") end) but I kept getting an error saying: variable 'DoTaskInTime' is not declared. I'm currently surfing through the Tutorials guide for how to use DoTaskInTime but I'm not having luck since the thread either doesn't specify how to use it or the thread was archived... Edited July 20, 2021 by owlluna Link to comment Share on other sites More sharing options...
Thomas Die Posted July 20, 2021 Share Posted July 20, 2021 inst:DoTaskInTime Object:DoTaskInTime ' : ' the colon calls the functions to start for the object inst basically is the object you are on. Happy modding 1 Link to comment Share on other sites More sharing options...
owlluna Posted July 20, 2021 Author Share Posted July 20, 2021 1 hour ago, Thomas Die said: inst:DoTaskInTime Object:DoTaskInTime ' : ' the colon calls the functions to start for the object inst basically is the object you are on. Happy modding Thank you for the clarification!! Okay so I've added in the inst:DoTaskInTime, but the talker component still doesn't trigger when the character is spawned in for the first time. But it does work when reloading from a saved state though. Any ideas? Link to comment Share on other sites More sharing options...
Thomas Die Posted July 21, 2021 Share Posted July 21, 2021 local function onnewspawn(inst) --epic code end inst.OnNewSpawn = onnewspawn I used this myself and it works, it only runs this function once you spawn in and never again. btdubs didn't say this before but you got an epic mod design. Put the inst.OnNewSpawn with the rest of your inst;onsave and inst.onload 1 Link to comment Share on other sites More sharing options...
owlluna Posted July 21, 2021 Author Share Posted July 21, 2021 22 minutes ago, Thomas Die said: local function onnewspawn(inst) --epic code end inst.OnNewSpawn = onnewspawn My original inst.OnNewSpawn was "onbecomehuman" and I tried placing the code there too...no luck I don't think I can add another inst.OnNewSpawn without creating another issue though. Thank you for the response anyways! I'll just be moving this talker problem lower on my priority list for now - might just need to put a disclaimer somewhere that the character will load in with blinding light. Link to comment Share on other sites More sharing options...
Thomas Die Posted July 21, 2021 Share Posted July 21, 2021 --place this function beneath onbecomehuman function so that it's already read the function local function onnewspawn(inst) onbecamehuman(inst) inst:DoTaskInTime(math.random(),function(inst) inst.components.talker:Say("these are words, no?") end) --epic code end inst.OnNewSpawn = onnewspawn try this if it doesn't work i don't mind looking at your file. 1 Link to comment Share on other sites More sharing options...
owlluna Posted July 21, 2021 Author Share Posted July 21, 2021 46 minutes ago, Thomas Die said: btdubs didn't say this before but you got an epic mod design. Thanks! It's definitely ambitious for my first character mod, but I'm pretty happy I was able to get the major perks to work. Also, the new dialogue code worked! I wasn't aware we could add another OnNewSpawn function. Thank you so much!! I'll definitely be adding your help to the list of credits when I compile all my assets for my eventual Mod Project thread. 1 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