Hector1324

  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

3 Neutral

About Hector1324

  • Rank
    Junior Member
...

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Enable
  1. I did something about the 4) How can I add a durability-restore item to my custom tool? I would like to make gems restore said tool's durability to 100%. for a mod i'm working on right now where there is a gem that give it one more use, what i did was that the gems were an edible item, --this function adds durability to the item local function PushMana(inst, eater) if eater.components.inventory then --this function looks for the item on your inventory or your equipslots (thaks to Combustiblemon he helped me with this part) local itemfound = function(func) for k,v in pairs(eater.components.inventory.itemslots) do if func(v) then return v end end for k,v in pairs(eater.components.inventory.equipslots) do if func(v) then return v end end if eater.components.inventory.activeitem and fn(eater.components.inventory.activeitem) then return eater.components.inventory.activeitem end local overflow = eater.components.inventory:GetOverflowContainer() return overflow ~= nil and overflow:FindItem(fn) or nil end --here you use the function we just created to look for the item(your sword) local item = itemfound(function(item) return item.prefab == "name of yor item prefab" end) if item ~= nil then local uses = item.components.finiteuses.current item.components.finiteuses:SetUses(uses+1) -- here i add one use, if you want to add more change the part uses+1 end end end ----------------------- ----------------------- inst:AddComponent("edible") inst.components.edible.oneaten = PushMana -- this is to make the function work
  2. Thanks man, i really appreciate your help Edit: I tried using the code you gave me, and i got the error: attempting to index itemfound (a funtion value) i searched about what it meant and found that the part of itemfound wasn't being executed, so i modified it a little bit by first creating the function, and then calling it to get the item, and i also took the final part of the function FindItem() on inventory.lua Here is the code local function PushMana(inst, eater) if eater.components.inventory then local itemfound = function(func) for k,v in pairs(eater.components.inventory.itemslots) do if func(v) then return v end end for k,v in pairs(eater.components.inventory.equipslots) do if func(v) then return v end end if eater.components.inventory.activeitem and fn(eater.components.inventory.activeitem) then return eater.components.inventory.activeitem end local overflow = eater.components.inventory:GetOverflowContainer() return overflow ~= nil and overflow:FindItem(fn) or nil end local item = itemfound(function(item) return item.prefab == "megumin_staff" end) if item ~= nil then local uses = item.components.finiteuses.current item.components.finiteuses:SetUses(uses+1) end end end Thanks a lot for the help Combustiblemon
  3. I want to know if there is any function i can call to check if an item is on the players inventory or if it's equipped and then return the item prefab, im using FindItem(), but that only checks if the item is in the inventoryslots. i want to make an object that after being eaten gives durability to a weapon what im doing is the following local function PushMana(inst, eater) if eater.components.inventory then local item = eater.components.inventory:FindItem(function(item) return item.prefab == "megumin_staff" end) if item ~= nil then local uses = item.components.finiteuses.current item.components.finiteuses:SetUses(uses+1) end end end -------------------------------------------------------------------------- -------------------------------------------------------------------------- so i was wondering if there is a function that do the same but for que equipslots
  4. 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?
  5. 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