Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- author: Aussiemon
- -----
- Copyright 2017 Aussiemon
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- -----
- When using a gamepad, your "_selected_consumable_slot" is checked against the slots of the target player (function InteractionDefinitions.give_item.client.can_interact).
- Unfortunately, this value only updates when that slot's consumable is lost/consumed/traded.
- This means that the "_selected_consumable_slot" will often differ from the item you are attempting to trade.
- For example, if a player with a gamepad:
- * Has no consumables, then picks up a bomb (setting "_selected_consumable_slot" to "slot_grenade")
- * Picks up a potion ("_selected_consumable_slot" is still on "slot_grenade" because the bomb is still present)
- * Attempts to trade that potion to a player that has a bomb, but no potion
- The "_selected_consumable_slot" of the interactor player, "slot_grenade" will be compared with the occupied "slot_grenade" of the target player.
- Because the target player already has a bomb, the interactor player won't be able to make the trade; even though they're only attempting to trade a potion.
- For whatever reason, when not using a gamepad, the check is made between the interactor player's currently equipped slot and the target player; not the "_selected_consumable_slot".
- Therefore, this bug does not exist for players on a mouse and keyboard. I don't have the console version, so I don't know if this bug affects them also.
- I can see two fixes to this issue:
- * Update "_selected_consumable_slot" whenever the wielded slot changes to a consumable.
- * Regardless of active gamepads, check the interactor player's wielded slot against the slots of the target player.
- The variable "_selected_consumable_slot" is used elsewhere in the game's source code, so the first fix might be best, but Fatshark is the best-equipped to tell if this would have unintended consequences.
- I can't see any reason to use "_selected_consumable_slot" in particular when a player is using a gamepad, so this might just be the result of legacy code.
- --]]
- local mod_name = "FixItemGive"
- -- ##########################################################
- -- ################## Variables #############################
- local consumable_slots = {
- slot_potion = true,
- slot_grenade = true,
- slot_healthkit = true
- }
- -- ##########################################################
- -- ################## Functions #############################
- -- ##########################################################
- -- #################### Hooks ###############################
- Mods.hook.set(mod_name, "SimpleInventoryExtension.wield", function (func, self, slot_name, ...)
- local orig_func = func(self, slot_name, ...)
- -- Update _selected_consumable_slot
- local equipment = self._equipment
- local slot_data = equipment.slots[slot_name]
- if slot_data ~= nil and consumable_slots[slot_name] then
- self._selected_consumable_slot = slot_name
- end
- -- Changes end
- return orig_func
- end)
- -- ##########################################################
- -- ################### Script ###############################
- -- ##########################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement