Hector1324 Posted February 9, 2021 Share Posted February 9, 2021 (edited) As i said in the title i want to make a weapon that is limited to 1 use per day, i tough of doing it by making its durability 1, and every morning restoring it back, but i cant seem to find a way to get that to happen every morning, i thought of using ListenForEvent() but i don't really know how it works, and i don't know if there's an event for that, the part of restoring the durability i tried to doing it with local function Morning("inst","dont know if i should add other variable") if inst.components.finiteuses.current == 0 and TheWorld.state.isday then inst.components.finiteuses:SetUses(1) end end but i don't understand event listeners very well, im kinda new to coding thanks in advance Edited February 13, 2021 by Hector1324 Link to comment https://forums.kleientertainment.com/forums/topic/126893-solvedneed-some-help-with-event-listeners-item-that-restores-its-durability-every-morning/ Share on other sites More sharing options...
Combustiblemon Posted February 9, 2021 Share Posted February 9, 2021 local function Morning(inst) if inst.components.finiteuses.current == 0 and TheWorld.state.isday then inst.components.finiteuses:SetUses(1) end end You need this function, inst:ListenForEvent("phasechanged", Morning) --this ================================ inst:WatchWorldState("isday", Morning) --or this one and add one line in your item's main function. I don't know below one would work but upper one should be work. 1 Link to comment https://forums.kleientertainment.com/forums/topic/126893-solvedneed-some-help-with-event-listeners-item-that-restores-its-durability-every-morning/#findComment-1427282 Share on other sites More sharing options...
Hector1324 Posted February 9, 2021 Author Share Posted February 9, 2021 Thanks, it worked with WatchWorldState. I checked worldstate.lua and i wondered if it was that event, thanks, so i need to write the events in lowercase, i have another question, can i create a custom event, for example i want to make an item that, after being used, grants the weapon another use, so can i create an event on the item that gets activated after being used and place somethting like: local function Mana(inst) inst.components.finiteuses:DoDelta(1) end =================================== inst:ListenForEvent("eaten", Mana) with eaten being a new event created for my item? Link to comment https://forums.kleientertainment.com/forums/topic/126893-solvedneed-some-help-with-event-listeners-item-that-restores-its-durability-every-morning/#findComment-1427369 Share on other sites More sharing options...
Combustiblemon Posted February 10, 2021 Share Posted February 10, 2021 Yes, you can make custom events. but inst:ListenForEvent, will only 'listen' to event, so you have to push the event first, inst:PushEvent("eventname", value_to_send, can_be_more_than_one) Like this one. In this case, you have to make consumable(edible I guess?) item coded like: local function PushEvent(inst, eater) if eater.components.inventory then local item = eater.components.inventory:FindItem(function(item) return item.prefab == "youritemprefabname" end) if item ~= nil then item:PushEvent("eaten") end end end ============================ inst:AddComponent("edible") inst.components.edible.oneaten = PushEvent wow what a mess It will find your item is in your inventory, then will push event to that item. Link to comment https://forums.kleientertainment.com/forums/topic/126893-solvedneed-some-help-with-event-listeners-item-that-restores-its-durability-every-morning/#findComment-1427654 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