VyTurtle Posted May 17, 2019 Share Posted May 17, 2019 Hey, I am trying to add a glow effect to a custom saddle when it's equipped on a Beefalo, I've tried adding many things in the custom saddle.lua, but most of the time the item WILL glow, but only when it's dropped on the ground. I'm trying to make it glow when it's equipped on the beefalo / when the beefalo is being ridden. Does anyone know how to add an effect like this? Link to comment Share on other sites More sharing options...
Ultroman Posted May 17, 2019 Share Posted May 17, 2019 I've looked into it, and the saddle itself doesn't really know anything about who is using it or which animal it is connected to. Only the beefalo push events in regards to changing the saddles. This is the game code for putting on a saddle from the "rideable" component: Spoiler function Rideable:SetSaddle(doer, newsaddle) --print("setting saddle to "..(newsaddle.prefab or 'nil')) if self.saddle ~= nil then self.inst.AnimState:ClearOverrideSymbol("swap_saddle") self.inst:RemoveChild(self.saddle) self.saddle:ReturnToScene() local pt = self.inst:GetPosition() pt.y = 3 self.inst.components.lootdropper:FlingItem(self.saddle, pt, doer == nil and self.saddle.components.saddler.discardedcb or nil) self.canride = false self.saddle = nil self.inst:PushEvent("saddlechanged", { saddle = nil }) end if newsaddle ~= nil then if self.saddleable then self.inst:AddChild(newsaddle) newsaddle.Transform:SetPosition(0,0,0) -- make sure we're centered, so poop lands in the right spot! newsaddle:RemoveFromScene() self.saddle = newsaddle self.inst:PushEvent("saddlechanged", { saddle = newsaddle }) self.inst.AnimState:OverrideSymbol("swap_saddle", self.saddle.components.saddler.swapbuild, self.saddle.components.saddler.swapsymbol) self.canride = true if doer ~= nil then self.inst.SoundEmitter:PlaySound("dontstarve/beefalo/saddle/dismount") end else self.inst.components.lootdropper:FlingItem(newsaddle) if self.inst.components.combat then self.inst.components.combat:SuggestTarget(doer) end end end end As you can see, "saddlechanged" is pushed separately for removing any existing saddle, and then later when setting the new saddle. This means that you can listen to this event on all beefalos (use AddPrefabPostInit("beefalo", function blabla...to add the listener), and the function you give to the listener will have two parameters: the first is "inst" which is the beefalo, and the second parameter is "data" which has the variable "saddle"; if data.saddle is nil, then a saddle was taken off and we can turn off the special light. But if it is not nil, then a new saddle is being put on, and we can check if it is our saddle, and if so turn on the special light. The problem there, though, is that when a saddle is removed we receive nil, so we do not have a reference to the saddle that was removed, and thus cannot turn off the glow. To get around this, we must find a way to react where we have access to the previous saddle...and there is one place: the saddler component. It has this function: function Saddler:SetDiscardedCallback(cb) self.discardedcb = cb end which the saddle prefab calls during its initialization, like so: inst.components.saddler:SetDiscardedCallback(ondiscarded) ...giving it this function: local function ondiscarded(inst) inst.components.finiteuses:Use() end If you scroll up to the big chunk of code above, you will see the "discardedcb" function is used just before the event is pushed, and the inst parameter it gets is the saddle! So if you extend (not just overwrite!) the self.discardedcb function on the saddle, then you can turn off the glow at the same time the use it actually counted (which is when the saddle is taken off) Link to comment Share on other sites More sharing options...
Developer bizziboi Posted May 17, 2019 Developer Share Posted May 17, 2019 I don't know much about DST modding, but in ACTIONS.SADDLE, you know who puts what saddle on what entity. Alternatively in Rideable:SetSaddle. Maybe that's an entrypoint? 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