Jump to content

Repairing amulets code


Recommended Posts

So I can now repair amulets, but there're two things I haven't figured out.  I want only a specific character to be able to perform this action, and I want it to be less effective.  Right now this code causes the amulet to be repaired by 50%, and all characters can do it..

--Test code.  Makes blue amulet refuel-able.
local AllRecipes = GLOBAL.AllRecipes
local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local STRINGS = GLOBAL.STRINGS
local TECH = GLOBAL.TECH
local FUELTYPE = GLOBAL.FUELTYPE

AddPrefabPostInit("blueamulet", function (inst)     
    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = FUELTYPE.NIGHTMARE
    inst.components.fueled:InitializeFuelLevel(TUNING.BLUEAMULET_FUEL)
    inst.components.fueled:SetDepletedFn(inst.Remove)
    inst.components.fueled:SetFirstPeriod(TUNING.TURNON_FUELED_CONSUMPTION, TUNING.TURNON_FULL_FUELED_CONSUMPTION)
    inst.components.fueled.accepting = true
end)

Edited by FurryEskimo
Link to comment
Share on other sites

local inst = ...
inst:AddComponents("fueled")
local oldTakeFuelItem = inst.components.fueled.TakeFuelItem

inst.components.fueled.TakeFuelItem = function(self, item, doer)
  if doer.prefab == "wilson" then
	print("I.. am Wilson.")
	return oldCanAcceptFuelItem(self, item)
  end

	return false
end

Here's a rough example of something you could do. You'll probably need to edit it though.

Edited by penguin0616
  • Like 2
Link to comment
Share on other sites

@penguin0616
Cool, so I did manage to get the code inserted and it's, sort of working.  When anyone other than Wilson tries to refuel the amulet they're told no, and drop the nightmare fuel, which is a little weird..  Obviously I tried replacing Wilson's name with my character's, but the game crashes when I try refueling it.  Next I tried checking the 'doer''s tags instead of prefab, but that also causes the game to crash when I try to refuel.  Hopefully I can get this working soon.

if doer:HasTag("furryeskimo") then

Edit:  I loaded up as wilson and when his name is the prefab, the game crashes, so it seems like there's some kind of issue when the player's prefab matches the condition.  I tried commenting out the Print code, but it still has a problem.  Thoughts?

if doer.prefab == "wilson" then
    --if doer:HasTag("furryeskimo") then
    --    print("I.. am Wilson.")
        return oldCanAcceptFuelItem(self, item)  --Note: Causes game to crash.
    end

    return false
    end

Edited by FurryEskimo
Link to comment
Share on other sites

Edit:  Figured it out.  You wrote 'oldTakeFuelItem' and 'oldCanAcceptFuelItem'.  I made these both 'oldTakeFuelItem' and now it's working.  It's still a little weird that characters unable to repair the amulet will drop fuel when attempting to repair, but it's not tragic.  Next on my list of things to do is nerf the repair ability from 50% to something closer to 10%.  No luck so far.

Edit:  Bad news..  I've been poking around the 'fueled' component file and I don't think I can change the 50% bonus via nightmare fuel.  All of the values that relate to it seem to be based on the nightmare fuel's fuel value.  If I change that value, All items that rely on nightmare fuel will be effected.  I'm going to try testing the 'bonusmult' value, but that's tied to Willow's mastery of fire and may do nothing.

self:DoDelta(item.components.fuel.fuelvalue * self.bonusmult * wetmult * masterymult, doer)

I can change the total durability of the amulet, and the rate at which it is used, creating the illusion of being repaired by less, but it caused all existing amulets to suddenly loose almost all of their durability..

Edit:  Haha!  It seems 'bonusmult' does work, though I'm not entirely sure yet if this edit has any far reaching consequences.  In the meantime, this value allows me to edit how much the amulet is refueled by.
Weirdly, I've never been able to get code like 'print("That's better.")' to work.  Is the character supposed to say that aloud?

Edited by FurryEskimo
Link to comment
Share on other sites

Yeah, I didn't fully complete the code. I hope that when you fixed it, you passed in doer as well for oldTakeFuelItem.

No, print does not make the character say anything aloud. The print function prints the string to the console and thus the corresponding log file.

  • Like 1
Link to comment
Share on other sites

@penguin0616
Passed in doer?  Sorry, I don't understand.  This is what it is now, and appears to work:

    --Test code.  Makes it so only this character can refuel Chilled Amulets.
    local oldTakeFuelItem = inst.components.fueled.TakeFuelItem

    inst.components.fueled.TakeFuelItem = function(self, item, doer)
        if doer.prefab == "furryeskimo" then
        --    print("That's better.")  --Note: Doesn't seem to work.
            return oldTakeFuelItem(self, item)  --Repair amulet, if refuel is performed by this character.
        end

        return false  --Unsure what this does.
    end

Edited by FurryEskimo
Link to comment
Share on other sites

Thanks.  The last bit of code I’m working on is 95% done.  The character can befriend hounds, but the hounds don’t stay trained once the game is saved and exited.  I’m trying to figure out how to save those traits, and reload them in when the game loads.

Link to comment
Share on other sites

@penguin0616
I think I might be able to do it.  My code is different than theirs.  I haven’t shared all the code yet, since it’s adapted from a few others I’m piecing together, but it seems like hounds have a component for loyalty time, and have a leader component, but it Seems, like the component that actually makes them follow an individual is saved to the player’s statistics, so unless that value is saved, I’m not sure it’ll work correctly.

 

Edited by FurryEskimo
Link to comment
Share on other sites

@penguin0616

You don’t have to do anything.  I felt silly quoting chunks of it each time, cluttering up the chat.

Also no?  I think I tried it a few different ways, and that was the only way I was able to get it to work.  I haven’t messed with it since because I’m not exactly sure how it works, but it appears to work.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...