Banner
Kleptomaniac (Auto Pickup)
Thumbnail
39
Downloads1,618
Views11,748
Publish Date5 years ago
Last Updated4 years ago
Version3
Avatar

Obviously drunk when you made this

local mod_ids = Idstring(ModPath):key()
local delay = 0
local used_units = {}
local whitelist = {
	["money_wrap_single_bundle"] = true,
	["safe_loot_pickup"] = true,
	["gage_assignment"] = true,
	["cash_register"] = true,
	["requires_ecm_jammer_atm"] = true,
	["invisible_interaction_open"] = true,
	["diamond_pickup"] = true,
	["press_pick_up"] = true
}

local function kleptomaniac(self)
	local pickups = alive(self._unit) and World:find_units_quick("sphere", self._unit:movement():m_pos(), 300, 1, 14, 20)
	if type(pickups) == "table" then
		for _, unit in pairs(pickups) do
			local interaction = (alive(unit) and (unit['interaction'] ~= nil)) and unit:interaction()
			local tweak = interaction and interaction.tweak_data
			if type(tweak) == "string" and tweak_data.interaction[tweak] and not used_units[unit:key()] and interaction:active() and not interaction:disabled() then
				local equipment_name = interaction._special_equipment or not tweak_data.interaction[tweak].timer and tweak_data.interaction[tweak].special_equipment_block and true
				local can_pickup, has_max_quantity = managers.player:can_pickup_equipment(equipment_name)
				if (equipment_name and can_pickup or whitelist[tweak]) then
					used_units[unit:key()] = true
					return interaction:interact(self._unit)
				end
			end
		end
	end
end

local function delayed_pickup(self, t)
	if not delay or t - delay > 0.1 then
		delay = t
		kleptomaniac(self)
	end
end

Hooks:PostHook(PlayerStandard, "_check_action_interact", "1_"..Idstring(mod_ids):key(), function(self, t, ...)
	delayed_pickup(self, t)
end)

Hooks:PostHook(PlayerCarry, "_check_action_interact", "2_"..Idstring(mod_ids):key(), function(self, t, ...)
	delayed_pickup(self, t)
end)
Avatar

there's a good and a bad point about both versions.

his version:
good points - it can pick literally anything that has instant interaction including assets, loose loot, etc
bad points - it also auto interacts with keypads, dumpster lids and any other object with instant interaction function (some may even trigger the alarm like the border crossing tunnel keypad)

your version:
good points - get rid of the issue from dr_newbie's version about interacting with unwanted stuff
bad points - doesn't pick everything like his version, loose loot, thermite from asset briefcases are good exemples and might have more that I didn't found yet

Avatar

@Berk Rider Okay, well i updated the post, just add stuff you want in the whitelist

Avatar

@✌Playhouse✌ now it's interacting with stuff that's not even there. I opened invisible cash registers on four stores and there's a huge delay too

Avatar

@Berk Rider Just remove it from whitelist and edit the delay

Avatar

@✌Playhouse✌ the new version seems to work just fine so far, just where can I find the names to put on the whitelist?

Avatar

@✌Playhouse✌ thx

Avatar

@✌Playhouse✌ I made some tests and additions and so far it seems to work very well but best when it's a loose loot or equipment. can you make a function to allow the mod to reuse stuff after it auto interacts the first time with something?

some exemples:
panic room - I added the c4 bag to the mod's whitelist but it only takes the first batch of c4, if I try to get close to it to grab more the mod won't auto interact with it so I have to grab the next batch manually.
no mercy hospital - I added the blood samples but when I find the patient it only takes the first vial, the others I have to grab manually, same for reusing validation machines.
ukrainian prisoner - I added the defibrilator but it only charges and take the pads once, if vlad doesn't wake up on first try I have to recharge the defib but the mod won't do it automaticaly.

btw I've tried to add "money_wrap_single_bundle" that's supposed to be the loose money bundles from golden grin and slaughterhouse but it doesn't seem to work
"debug_interact_money_wrap_single_bundle_take_money" is the text_id pointed by stringidrevealer mod when I look at those money bundles

Avatar

@Berk Rider So i added the auto pickup code to this mod https://modworkshop.net/mod/33849, so we don't ahve to discuss it here. I'll take a look at what you said

36 772