. . . Posted November 10, 2016 Share Posted November 10, 2016 (edited) Hello, I have a question . So, like the title says is there a event for when a character starts & stops heavy lifting? Because I looked & couldn't tell. Edited November 11, 2016 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/71582-solved-is-there-a-event-for-heavy-lifting/ Share on other sites More sharing options...
blubuild Posted November 10, 2016 Share Posted November 10, 2016 If there isn't, there are probably functions that run when lifting that you can override and hook into. Haven't read that code. Link to comment https://forums.kleientertainment.com/forums/topic/71582-solved-is-there-a-event-for-heavy-lifting/#findComment-836075 Share on other sites More sharing options...
. . . Posted November 11, 2016 Author Share Posted November 11, 2016 1 hour ago, blubuild said: there are probably functions that run when lifting that you can override and hook into. Well what I want to specifically do is lower the speed penalty of heavy lifting for my character but I couldn't find a externalspeedmod or anything like that for heavylifting in the DST files either ... And I really don't want to make a perodictask to check if my character's heavylifting because my character already has enough periodictasks as is ... So, if anyone knows how I could do this that would be great ! Link to comment https://forums.kleientertainment.com/forums/topic/71582-solved-is-there-a-event-for-heavy-lifting/#findComment-836100 Share on other sites More sharing options...
blubuild Posted November 11, 2016 Share Posted November 11, 2016 (edited) I took a look around the files. Looks like just changing TUNING.HEAVY_SPEED_MULT (default = 0.15... damn low, indeed) will control it globally. From chesspieces.lua, which creates the chess pieces (I cut out many parts we don't care about): Spoiler local function makepiece(pieceid, materialid) local build = GetBuildName(pieceid, materialid) ... ... local function fn() local inst = CreateEntity() ... ... inst:AddTag("heavy") if PIECES[pieceid].moonevent then inst:AddTag("chess_moonevent") end inst:SetPrefabName("chesspiece_"..PIECES[pieceid].name) inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst.components.inspectable.getstatus = getstatus inst:AddComponent("lootdropper") inst:AddComponent("inventoryitem") inst.components.inventoryitem.cangoincontainer = false inst.components.inventoryitem:ChangeImageName("chesspiece_"..PIECES[pieceid].name) inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.BODY inst.components.equippable:SetOnEquip(onequip) inst.components.equippable:SetOnUnequip(onunequip) inst.components.equippable.walkspeedmult = TUNING.HEAVY_SPEED_MULT ... ... return Prefab(prefabname, fn, assets, prefabs) end As you can see, the speed multiplier for the heavy items is defined as TUNING.HEAVY_SPEED_MULT, the value of which is assigned to the heavy item's equippable component's walkspeedmult member variable. From then on, the component uses that value to alter the speed on equip and unequip, etc. You can also see here that heavy items are marked so by having the "heavy" tag added to them. We could make use of that. So, for character-specific speeds. I did it for you, by, as I said before, overriding a related, relevant function: one the game uses to get an equippable item's speed multiplier in order to use it: From Equippable.lua, which creates the 'equippable' component: function Equippable:GetWalkSpeedMult() return self.walkspeedmult or 1.0 end As you can see, it's a pretty simple function: it simply returns the multiplier already stored in the component's walkspeedmult field, or 1.0 if that is unspecified. But it's important and useful that this function does exist and is used by the game to get the multiplier (instead of simply directly accessing the walkspeedmult member var...), as we can hook into it to suit our purposes. This is extensibility. The best way I came up with to do it as of now is to add a postinit to the equippable component, and check if the item it's attached to is heavy (that way, you handle all of the heavy items which slow you down at once, rather than doing something like going specific prefab by specific prefab). If it is, do the function override (which returns a different speedmult depending on the owning character). I keep thinking that there may be a better way, without running on each prefab / component instance and creating new functions for each, but okay. It works fine and it's customary for mods to use postinits to do their stuff. My code (modmain.lua): Multiple characters have different carrying speeds; Wolfgang and WX are faster than default, Wendy and Wes are slower than default and all other characters will be slightly faster than Klei's default (they'll have x0.2 instead of x0.15): Spoiler - default klei: x0.15 (very slow...) local character_heavy_mults = {wolfgang = 0.60, wx78 = 0.40, wendy = 0.10, wes = 0.08,} function HeavyEquippablePostInit(equipcomp) equipcomp.inst:DoTaskInTime(0, function(inst) -- wait for complete item initialization if inst:HasTag("heavy") then print("caught heavy equip ", inst) assert(equipcomp == inst.components.equippable) -- should always be true, of course... local origfn = inst.components.equippable.GetWalkSpeedMult -- store the original function for later use, we're not ignoring it nor bypassing it completely inst.components.equippable.GetWalkSpeedMult = function(self) -- replace the existing function reference with a reference to a new function --shorthands (and multiple-indexing-savers) local inst = self.inst local inventoryitem = inst.components.inventoryitem local ret = origfn(self) if inventoryitem and inventoryitem.owner then local newspeed = character_heavy_mults[inventoryitem.owner.prefab] or 0.2 --printft("altering speedmult for %s held by %s --- from %s to %s.", inst, inventoryitem.owner, ret, newspeed) return newspeed else return ret end end end end) end AddComponentPostInit("equippable",HeavyEquippablePostInit) Or, if you just want to alter the speed of a single character... with the code below, only Wilson will have triple the normal heavylifting speed (but never more than regular walking speed, even if Klei raises the base speed in the future): Spoiler function HeavyEquippablePostInit(equipcomp) equipcomp.inst:DoTaskInTime(0, function(inst) -- wait for complete item initialization if inst:HasTag("heavy") then assert(equipcomp == inst.components.equippable) -- should always be true, of course... local origfn = inst.components.equippable.GetWalkSpeedMult -- store the original function for later use, we're not ignoring it nor bypassing it completely inst.components.equippable.GetWalkSpeedMult = function(self) -- replace the existing function reference with a reference to a new function --shorthands (and multiple-indexing-savers) local inst = self.inst local inventoryitem = inst.components.inventoryitem local ret = origfn(self) --call the original function, store what it returns. if inventoryitem and inventoryitem.owner and inventoryitem.owner.prefab == "wilson" then local newspeed = min(1, ret * 3) -- this is triple the usual heavylifting speed (but capped to a maximum of 1) --printft("altering speedmult for %s held by %s --- from %s to %s.", inst, inventoryitem.owner, ret, newspeed) return newspeed else return ret end end end end) end AddComponentPostInit("equippable",HeavyEquippablePostInit) Feel free to use this, I hope that you understand the code. =) EDIT: I think I've only tested this on a normal local player-hosted server, and not in a cave server or dedicated server. So perhaps there could still be some work left for you to do. Edited November 11, 2016 by blubuild Link to comment https://forums.kleientertainment.com/forums/topic/71582-solved-is-there-a-event-for-heavy-lifting/#findComment-836402 Share on other sites More sharing options...
blubuild Posted November 11, 2016 Share Posted November 11, 2016 (edited) Code is definitely more readable in a proper text editor than on here, so that could help understanding while reading...http://i65.tinypic.com/xlb7e9.jpg That's Notepad++. Edited November 11, 2016 by blubuild Link to comment https://forums.kleientertainment.com/forums/topic/71582-solved-is-there-a-event-for-heavy-lifting/#findComment-836405 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