smoq2's brilliant The Faction War mod for Clear Sky features an ingenious method of making any weapon usable in either of the weapon slots in Clear Sky and Shadow of Chernobyl, even though the feature was only added in Call of Pripyat. This is an extraction of his code so it can be used elsewhere. All credit for the content here goes to smoq2, please be sure to credit them and The Faction War mod if you use the work here. More detail:
The Faction War's weapon slot swapper
smoq2's brilliant The Faction War mod for Clear Sky features an ingenious method of making any weapon usable in either of the weapon slots. This is an extraction of his code so it can be used elsewhere. All credit for the content here goes to smoq2, please be sure to credit them and The Faction War mod if you use the work here.
Overview
smoq2's method:
1. Every weapon in the game is given a twin that is the same in all respects except its slot is the other slot.
2. So a slot=1 weapon's mirror will have slot=2 and vice versa.
3. The mirror's name is the original's name with _slotted as a suffix. Eg., wpn_ak74 and wpn_ak74_slotted.
4. A new weapon swapper item is added to the inventory that is dropped when used or double clicked.
5. The drop is caught in bind_stalker's on_item_drop() callback and triggers the swapper code.
6. The swapper works by taking each weapon and exchanging it with its mirrored counterpart.
It's ingenious and simple. The code Just Works across both Shadow of Chernobyl and Clear Sky, a testament to smoq's skill and eye for detail.
Usage
The files included need to be merged into your mod. Here's a detailed look at what they do, though a merge will suffice.
1. The swapper item
Files: config/misc/items.ltx, textures/ui/ui_icon_equipment.dds
Both of these will need merging into your mod. The only item you need is wpn_swap_slot which is at the end of items.ltx. The icon is the bright green one near the middle of the icons dds file.
2. The mirrored weapons
Files: config/weapons/slotted_sections.ltx, config/weapons/weapons.ltx
There has to be a mirrored entry in slotted_sections.ltx for every weapon in your mod. The mirrored weapon must have the same name as its twin but with "_slotted" appended. It must inherit from its twin and have only two entries, as here:
[wpn_ak74_slotted]:wpn_ak74
slot = 1
script_binding = bind_slotted.bind
Here wpn_ak74's mirrored entry is wpn_ak74_slotted. Since the ak74 goes in slot 2, the mirror goes in slot 1.
The script_binding entry must be present and must point to bind_slotted.bind as above.
weapons.ltx must #include slotted_sections.ltx. Add an entry at the end of the file, like in the included example.
Add entries to the trader files for the mirrored variants of weapons. This is only needed for the trader's buy conditions to ensure the mirrored variant is treated exactly the same as the unmirrored variant. Here's an example:
[trader_generic_buy]
wpn_val ; NO TRADE
wpn_val_slotted ; NO TRADE
wpn_vintorez = 0.5, 0.7
wpn_vintorez_slotted = 0.5, 0.7
3. The scripts
Files: scripts/bind_stalker.script, bind_slotted.script, packet_utils21.script, TFWactor_inventory.script
bind_stalker.script needs to be merged with yours. There are only two lines to merge:
TFWactor_inventory.on_item_drop(obj) must be called from your actor_binder:on_item_drop (obj) function. If you don't have one, see the included example for how to add one.
TFWactor_inventory.update() must be called from your actor_binder:update() function. Again see the included example.
The other three files can be included as is.
4. The info portion
Files: config/system.ltx, config/gameplay/info_tfw_weapon_swap.xml
The code uses an info portion to track whether the swapper device has been added to the inventory. Copy the second file in as is and modify your system.ltx to refer to it: In the [info_portions] section, add info_tfw_weapon_swap to the end of the files line - be sure to separate it with a comma from the preceding entry.
Credits
smoq2 for the ingenious simplicity of the idea and for the robust code implementing it.
Changes
1.0 - v1ld - 2017-12-02 - First release, from The Faction War 3.8 beta by smoq2
1.1 - v1ld - 2018-01-13 - Comment out item ownership code, it's not needed outside of TFW
-v1ld
1.1 comments out some unnecessary code. Updated the description to point out that trader buy conditions should have entries for the slotted versions of weapons that mirror the unslotted version.
smoq2 was a hell of a modder :) i liked tfw back then, lots of work, lots of scripts x)
thanks for port, very good idea
This comment is currently awaiting admin approval, join now to view.
Nobody has done this for Autumn Aurora 2? I'm going to take a look, to see if I'm able to do it, I don't have much experience but I've already done something, let's see if I can do it xD
I have not been able to get this mod to work with SoC and AA2 together, has anyone gotten it to work like this, something is escaping me and I don't know what it is.