Jump to content
Sign in to follow this  
PirateCaptain

CarryStacker by harfatus

Recommended Posts

PirateCaptain

CarryStacker

The following code provides for fully-automated item carry stacking. You are free to redistribute it elsewhere providing credit for this code is stated in bold, on the first line of the post with at least equal font size to the rest of the post.

I recommend binding it to a key that you can access easily as it also acts as a push/pop key. Namely, if you are currently carrying something, it will push it to the stack, if you aren't carrying anything, it will pop whatever is pushed.

You do not need to push every time you pick something up, you are completely free to keep picking stuff up and whatever you are already carrying is pushed to the stack, same applies when dropping items, you can just spam G and watch the bags fly.

Along with this release goes a request to the Overkill devs who no doubt peruse this forum

OVERKILL folks: I understand the modding is getting out of hand, but there are those of us who use the ability to inject lua to improve our own personal game experience without impacting others. I welcome you implementing something to disallow unfettered hacks, but please at least provide an option to host a server that does permit mods so those of us who want to use them can, and those who wish to avoid it may choose to do so.

Code:

_debugEnabled = false

BagIcon = "pd2_loot"



if not CarryStackerSetupDone then

	CarryStackerSetupDone = true

	managers.player.carry_stack = {}

	managers.player.carrystack_lastpress = 0

	managers.player.drop_all_bags = false

	function NetworkMember:place_bag() return true end

	ofuncs = {

	  managers_player_set_carry = managers.player.set_carry,

	  managers_player_drop_carry = managers.player.drop_carry,

	  IntimitateInteractionExt__interact_blocked = IntimitateInteractionExt._interact_blocked,

	}

	

	function managers.player:refresh_stack_counter()

		local count = #self.carry_stack + (self:is_carrying() and 1 or 0)

		managers.hud:remove_special_equipment("carrystacker")

		if count > 0 then

			managers.hud:add_special_equipment({id = "carrystacker", icon = BagIcon, amount = count})

		end

	end

	

	function managers.player:rotate_stack(dir)

		if #managers.player.carry_stack  0 then

			local cdata = table.remove(self.carry_stack)

			if cdata then

				self:set_carry(cdata.carry_id, cdata.value or 100, cdata.dye_initiated, cdata.has_dye_pack, cdata.dye_value_multiplier)

			end

		end

		self:refresh_stack_counter()

		if self.drop_all_bags then

			if #self.carry_stack > 0 or self:is_carrying() then

				self:drop_carry()

			end

			self.drop_all_bags = false

		end

	end



	-- saves the current item to the stack if we're already carrying something

	function managers.player:set_carry( carry_id, carry_value, dye_initiated, has_dye_pack, dye_value_multiplier )

		if self:is_carrying() and self:get_my_carry_data() then

			table.insert(self.carry_stack, self:get_my_carry_data())

		end

		ofuncs.managers_player_set_carry(self, carry_id, carry_value, dye_initiated, has_dye_pack, dye_value_multiplier)

		self:refresh_stack_counter()

	end



	-- new function to discard the currently carried item

	function managers.player:carry_discard()

		managers.hud:remove_teammate_carry_info( HUDManager.PLAYER_PANEL )

		managers.hud:temp_hide_carry_bag()

		self:update_removed_synced_carry_to_peers()

		if self._current_state == "carry" then

			managers.player:set_player_state( "standard" )

		end

	end



	-- overridden to prevent blocking us from picking up a dead body

	function IntimitateInteractionExt:_interact_blocked( player )

		if self.tweak_data == "corpse_dispose" then

			if not managers.player:has_category_upgrade( "player", "corpse_dispose" ) then

				return true

			end

			return not managers.player:can_carry( "person" )

		end

		return ofuncs.IntimitateInteractionExt__interact_blocked(self, player)

	end



	-- overridden to always allow us to pick up a carry item

	function CarryInteractionExt:_interact_blocked( player )

		return not managers.player:can_carry( self._unit:carry_data():carry_id() )

	end



	-- overridden to always allow us to select a carry item

	function CarryInteractionExt:can_select( player )

		return CarryInteractionExt.super.can_select( self, player )

	end



	-- custom function. Pushes a carried item to stack and discards it or pops one if we're not carrying anything.

	-- this function is called every time the script gets run.

	function managers.player:carry_stacker()

		if _debugEnabled then

			io.stderr:write("current stack size: ".. tostring(#managers.player.carry_stack) .. "

")

			if #managers.player.carry_stack > 0 then

				for _,v in pairs(managers.player.carry_stack) do

					io.stderr:write("item: ".. v.carry_id .. "

")

				end

			end

		end

		local cdata = self:get_my_carry_data()

		if self:is_carrying() and cdata then

			table.insert(self.carry_stack, self:get_my_carry_data())

			self:carry_discard()

			managers.hud:present_mid_text( { title = "Carry Stack", text = cdata.carry_id .. " Pushed", time = 1 } )

		elseif #self.carry_stack > 0 then

			cdata = table.remove(self.carry_stack)

			self:set_carry(cdata.carry_id, cdata.value, cdata.dye_initiated, cdata.has_dye_pack, cdata.dye_value_multiplier)

			managers.hud:present_mid_text( { title = "Carry Stack", text = cdata.carry_id .. " Popped", time = 1 } )

		else

			managers.hud:present_mid_text( { title = "Carry Stack", text = "Empty", time = 1 } )

		end

		if (Application:time() - self.carrystack_lastpress)  0) then

			self.drop_all_bags = true

			self:drop_carry()

		end

		self.carrystack_lastpress = Application:time()

		self:refresh_stack_counter()

	end

end



managers.player:carry_stacker()

Oh and a small mention... if you disconnect from a game, your stacked items are of course lost forever.

Last, but certainly not least, A massive thank you to @v00d00 for his fantastic work in keeping the Lua source updated - so much of the inventive code on here would not exist were it not for his efforts

Last edited by Harfatus; 3rd January 2014 at 03:26 PM.

Last edited by Harfatus; 31st May 2014 at 20:00 approx :D

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×