icantevenname Posted November 21, 2020 Share Posted November 21, 2020 I want to give a character a perk of having a higher damage multiplier when having certain weapons equipped and having it go back to normal when unequipped or not holding any of the weapons indicated in the code. The only thing I'm really stuck on is that I don't know what kind of line I use to get the game to check what my character has equipped in the hand slot. Link to comment Share on other sites More sharing options...
penguin0616 Posted November 21, 2020 Share Posted November 21, 2020 (edited) player.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS) player:ListenForEvent("equip", ...) player:ListenForEvent("unequip", ...) Edited November 21, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 21, 2020 Author Share Posted November 21, 2020 Okay, I overestimated my coding knowledge. I think the only thing I got right was what you told me and the table I made that lists the weapons that should cause the buff... Link to comment Share on other sites More sharing options...
penguin0616 Posted November 21, 2020 Share Posted November 21, 2020 Is that good or bad? 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 21, 2020 Author Share Posted November 21, 2020 1 minute ago, penguin0616 said: Is that good or bad? Bad, I now have no idea what to do. Link to comment Share on other sites More sharing options...
penguin0616 Posted November 21, 2020 Share Posted November 21, 2020 Well, what else is there that you are trying to accomplish? 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 21, 2020 Author Share Posted November 21, 2020 1 minute ago, penguin0616 said: Well, what else is there that you are trying to accomplish? No, I've done everything else I want to do with the character. All that's left is the weapon-specific buff. Link to comment Share on other sites More sharing options...
penguin0616 Posted November 21, 2020 Share Posted November 21, 2020 (edited) I do not know whether means this thread has been solved or not. Do you not know how to do the buff? Edited November 21, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 21, 2020 Author Share Posted November 21, 2020 14 hours ago, penguin0616 said: I do not know whether means this thread has been solved or not. Do you not know how to do the buff? No, I do not know how to cause the buff. Link to comment Share on other sites More sharing options...
penguin0616 Posted November 22, 2020 Share Posted November 22, 2020 (edited) something.components.combat.externaldamagemultipliers:SetModifier(inst, modifier) Above is used to add a damage multiplier to something. You could use the previous events and checks in combination with that. Edited November 22, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 22, 2020 Author Share Posted November 22, 2020 1 hour ago, penguin0616 said: something.components.combat.externaldamagemultipliers:SetModifier(inst, modifier) Above is used to add a damage multiplier to something. You could use the previous events and checks in combination with that. Just making sure, the "modifier" in the () is meant to be replaced by the value of the multiplier, right? Link to comment Share on other sites More sharing options...
penguin0616 Posted November 22, 2020 Share Posted November 22, 2020 (edited) @icantevenname Yep. Edit: I forgot to mention, you can also use :RemoveModifier(inst) to remove the modifier once you are done with it. Edited November 22, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 22, 2020 Author Share Posted November 22, 2020 15 hours ago, penguin0616 said: @icantevenname Yep. Edit: I forgot to mention, you can also use :RemoveModifier(inst) to remove the modifier once you are done with it. Think I did it wrong, it wouldn't stop loading. This is all in my master_postinit player.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS) player:ListenForEvent("equip", "blowdart_pipe") player:ListenForEvent("unequip", "blowdart_pipe") player.components.combat.externaldamagemultipliers:SetModifier(inst, 1.5) Link to comment Share on other sites More sharing options...
penguin0616 Posted November 22, 2020 Share Posted November 22, 2020 (edited) @icantevenname 1. The first line is meant for use in the events. 2. ListenForEvent requires a function as the second argument. Provides data in the form of {eslot = EQUIPSLOT} 3. Damage multipliers also belong in the events. Edited November 22, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 22, 2020 Author Share Posted November 22, 2020 2 hours ago, penguin0616 said: @icantevenname 1. The first line is meant for use in the events. 2. ListenForEvent requires a function as the second argument. Provides data in the form of {eslot = EQUIPSLOT} 3. Damage multipliers also belong in the events. Like this? local function gainsniperbuff(inst, data) if {eslot = "blowdart_pipe"} then player.components.combat.externaldamagemultipliers:SetModifier(inst, 1.5) end end local function losesniperbuff(inst, data) if not {eslot = "blowdart_pipe"} then player.components.combat.externaldamagemultipliers:SetModifier(inst, 1) end end ---------under master--------- inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS) inst:ListenForEvent("equip", gainsniperbuff) inst:ListenForEvent("unequip", losesniperbuff) Link to comment Share on other sites More sharing options...
penguin0616 Posted November 23, 2020 Share Posted November 23, 2020 @icantevenname Nope. local function OnEquipChanged(inst, data) -- inst = self explanatory --[[ data = { eslot = EQUIPSLOT.???, ... } --]] if data.eslot == GLOBAL.EQUIPSLOTS.HANDS then -- check if equipment change was from hands local held_item = inst.components.inventory:GetEquippedItem(data.eslot) -- figure out what we are holding if not held_item then -- not holding anything, remove modifier inst.components.combat.externaldamagemultipliers:RemoveModifier("somethingsomethingsourcekey") return end if held_item.prefab == "blowdart_pipe" then -- give modifier inst.components.combat.externaldamagemultipliers:SetModifier("somethingsomethingsourcekey", 1.5) else -- not an item we care about, remove modifier inst.components.combat.externaldamagemultipliers:RemoveModifier("somethingsomethingsourcekey") end end end inst:ListenForEvent("equip", OnEquipChanged) -- OnEquipChanged is a function inst:ListenForEvent("unequip", OnEquipChanged) -- OnEquipChanged is a function 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 23, 2020 Author Share Posted November 23, 2020 3 hours ago, penguin0616 said: @icantevenname Nope. local function OnEquipChanged(inst, data) -- inst = self explanatory --[[ data = { eslot = EQUIPSLOT.???, ... } --]] if data.eslot == GLOBAL.EQUIPSLOTS.HANDS then -- check if equipment change was from hands local held_item = inst.components.inventory:GetEquippedItem(data.eslot) -- figure out what we are holding if not held_item then -- not holding anything, remove modifier inst.components.combat.externaldamagemultipliers:RemoveModifier("somethingsomethingsourcekey") return end if held_item.prefab == "blowdart_pipe" then -- give modifier inst.components.combat.externaldamagemultipliers:SetModifier("somethingsomethingsourcekey", 1.5) else -- not an item we care about, remove modifier inst.components.combat.externaldamagemultipliers:RemoveModifier("somethingsomethingsourcekey") end end end inst:ListenForEvent("equip", OnEquipChanged) -- OnEquipChanged is a function inst:ListenForEvent("unequip", OnEquipChanged) -- OnEquipChanged is a function I see. But when I try to play the character, the game says that GLOBAL isn't declared. Is "somethingsomethingsourcekey" a place holder for me to replace or just an inconsequential name you made up? Link to comment Share on other sites More sharing options...
penguin0616 Posted November 23, 2020 Share Posted November 23, 2020 (edited) @icantevenname You can remove the GLOBAL part. It's both inconsequential, because I doubt anyone else has the same argument as that, and for you to replace, since whatever is provided for that argument is associated with the modifier. Edited November 23, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 23, 2020 Author Share Posted November 23, 2020 1 hour ago, penguin0616 said: @icantevenname You can remove the GLOBAL part. It's both inconsequential, because I doubt anyone else has the same argument as that, and for you to replace, since whatever is provided for that argument is associated with the modifier. It's still demanding a GLOBAL variable. I'd removed the only one left but it's the if data.eslot == GLOBAL.EQUIPSLOTS.HANDS then one. Do I make some sorta dummy GLOBAL variable? Link to comment Share on other sites More sharing options...
penguin0616 Posted November 23, 2020 Share Posted November 23, 2020 @icantevenname You need to provide the actual error. And no, you do not make a dummy GLOBAL variable. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 23, 2020 Author Share Posted November 23, 2020 10 hours ago, penguin0616 said: @icantevenname You need to provide the actual error. And no, you do not make a dummy GLOBAL variable. Link to comment Share on other sites More sharing options...
penguin0616 Posted November 23, 2020 Share Posted November 23, 2020 @icantevenname 12 hours ago, icantevenname said: 14 hours ago, penguin0616 said: @icantevenname You can remove the GLOBAL part. It's both inconsequential, because I doubt anyone else has the same argument as that, and for you to replace, since whatever is provided for that argument is associated with the modifier 1 1 Link to comment Share on other sites More sharing options...
icantevenname Posted November 23, 2020 Author Share Posted November 23, 2020 (edited) Ah, you wanted me to remove the words GLOBAL. I thought you wanted me to removed the lines with GLOBAL in them. Works like a charm now, thanks! Also thanks for putting up with me. I'm not exactly a smart man. Edited November 23, 2020 by icantevenname 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