AkaiNight Posted January 3, 2020 Share Posted January 3, 2020 i was trying to make a code that changes damage on level but it was working little broken it was does work but you must relogin for damage change so i tried to edit and make it work fine but now it won't even work and im not sure what is the problem im not getting any errors or something like it's like it's not even there here is code in master_postinit inst:ListenForEvent("equip", function() local equippedweb = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if equippedweb ~= nil and equippedweb:HasTag("shirayuki") then inst.components.combat.damagemultiplier = 1 else inst.components.combat.damagemultiplier = 0 end end) inst:ListenForEvent("unequip", function() local unequippedwep = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if unequippedwep ~= nil and unequippedwep:HasTag("shirayuki") then inst.components.combat.damagemultiplier = 0 else inst.components.combat.damagemultiplier = 0 end end) this is not working(and no error as well) and i tried this but when i use this you must relogin for damage change inst:ListenForEvent("equip", function() local equippedweb = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if equippedweb ~= nil and equippedweb:HasTag("shirayuki") then inst.components.combat.damagemultiplier = 1 + inst.level else inst.components.combat.damagemultiplier = 0 end end) inst:ListenForEvent("unequip", function() local unequippedwep = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if unequippedwep ~= nil and unequippedwep:HasTag("shirayuki") then inst.components.combat.damagemultiplier = 0 else inst.components.combat.damagemultiplier = 0 end end) and i tried this well inst:ListenForEvent("equip", function() local equippedweb = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if equippedweb ~= nil and equippedweb:HasTag("shirayuki") and inst.level == 0 then inst.components.combat.damagemultiplier = 1 else inst.components.combat.damagemultiplier = 0 elseif equippedweb ~= nil and equippedweb:HasTag("shirayuki") and inst.level == 1 then inst.components.combat.damagemultiplier = 2 else inst.components.combat.damagemultiplier = 0 . . . . end end) inst:ListenForEvent("unequip", function() local unequippedwep = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if unequippedwep ~= nil and unequippedwep:HasTag("shirayuki") then inst.components.combat.damagemultiplier = 0 else inst.components.combat.damagemultiplier = 0 end end) this one is not worked as well so im not sure what is wrong and im not sure what should i do Link to comment https://forums.kleientertainment.com/forums/topic/114745-damage-change-on-level/ Share on other sites More sharing options...
Ultroman Posted January 3, 2020 Share Posted January 3, 2020 (edited) It doesn't only recalculate on relogin. It recalculates whenever something is equipped or unqeuipped. Those are the events you have chosen to listen to. You should recalculate the damage whenever your character levels up. Since your character's damage multiplier is contingent on them having a certain set of HANDS equipment, you rightly also have to update when said item is equipped or unequipped. You have hooked up to two events which are fired whenever ANY item is equipped or unequipped. We can solve this by making them do the same job. The check will be roughly the same if we split it into separate equip/unequip versions, so unless this becomes more complex, this should be fine. local updateDamageMultiplier = function(inst) local equippedweb = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if equippedweb ~= nil and equippedweb:HasTag("shirayuki") then inst.components.combat.damagemultiplier = 1 + inst.level else inst.components.combat.damagemultiplier = 0 end end inst:ListenForEvent("equip", function(inst, data) -- Remember, you get both the inst (listener, so here it is the character) and data which -- has different data depending on which event you listen to. In this case, we are listening -- to "equip", which is pushed like this: -- self.inst:PushEvent("equip", { item = item, eslot = eslot }) -- and "unequip", which is pushed like this: -- self.inst:PushEvent("unequip", {item=item, eslot=equipslot, slip=slip}) -- You can access these like so: data.eslot -- So we can ask which type of item was equipped or unequipped. -- If there is no data (there always is) or the equipped item is for the HANDS-eslot. if not data or data.eslot == EQUIPSLOTS.HANDS then updateDamageMultiplier(inst) end -- If you have other items or things which influence this multiplier, -- just call updateDamageMultiplier instead of having the if-statement. end) inst:ListenForEvent("unequip", function(inst, data) -- Ditto above. -- If there is no data (there always is) or the unequipped item is for the HANDS-eslot. if not data or data.eslot == EQUIPSLOTS.HANDS then updateDamageMultiplier(inst) end -- If you have other items or things which influence this multiplier, -- just call updateDamageMultiplier instead of having the if-statement. end) -- Also call updateDamageMultiplier wherever you count up the level variable. Edited January 3, 2020 by Ultroman Link to comment https://forums.kleientertainment.com/forums/topic/114745-damage-change-on-level/#findComment-1296378 Share on other sites More sharing options...
AkaiNight Posted January 3, 2020 Author Share Posted January 3, 2020 (quick fix) this should be like if not data or data.eslot == EQUIPSLOT.HANDS then this if not data or data.eslot == EQUIPSLOTS.HANDS then thanks for help ultroman. Link to comment https://forums.kleientertainment.com/forums/topic/114745-damage-change-on-level/#findComment-1296399 Share on other sites More sharing options...
Ultroman Posted January 5, 2020 Share Posted January 5, 2020 You're welcome! I've fixed my code to your specifications Link to comment https://forums.kleientertainment.com/forums/topic/114745-damage-change-on-level/#findComment-1296694 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