Hector1324 3 Report post Posted February 9 (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 by Hector1324 Share this post Link to post Share on other sites
Combustiblemon 44 Report post Posted February 9 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 Share this post Link to post Share on other sites
Hector1324 3 Report post Posted February 9 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? Share this post Link to post Share on other sites
Combustiblemon 44 Report post Posted February 10 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. Share this post Link to post Share on other sites