Jump to content

Attack up when holding certain weapons


Recommended Posts

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

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

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

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

@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

 

  • Like 1
Link to comment
Share on other sites

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

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

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...