Barotrauma

Barotrauma

THG Armory - 'Vanilla' Throwing Weapon Pack
Code Enhance+Optimize+Fix
As with the original mod, the throwing knife is both a projectile and a launcher.
Enhance Simulate throwing actions
Enhance SFX of throwing and hitting
Optimization When holding a throwing knife, spawn a throwing knife only once in its container, fps will no longer suddenly dropped.
Optimization All codes will only be processed when necessary, and the cpu resources it usually occupies are no different from materials (iron, copper...)
Fix Equip and unequip stacked throwing knifes will drops and ate them in Multiplayer

You can check the changed code here: OTFX
Test: 1) Host a server with the OTFX mod enabled. 2) Start a game. 3) Type in "spawnitem otfx_throwingknife inventory 100"

Compare the xml before and after for quickly previewing
Before
<Item name="Throwing Dagger" identifier="thg_throwingknife" category="weapon,Material" cargocontaineridentifier="explosivecrate" maxstacksize="6" scale="0.5" tags="weapon,smallitem" impacttolerance="8" description="A lightweight, double-edged dagger balanced for throwing. It deals deep, devastating wounds, but can be easily deterred by armor." impactsoundtag="impact_metal_light"> <Upgrade gameversion="0.15.22.1" Tags="weapon,smallitem" /> <Price baseprice="8" minavailable="1"> <Price storeidentifier="merchantoutpost" sold="false" /> <Price storeidentifier="merchantcity" sold="false" /> <Price storeidentifier="merchantresearch" multiplier="1.15" /> <Price storeidentifier="merchantmilitary" sold="false" multiplier="1.1" /> <Price storeidentifier="merchantmine" multiplier="0.9" /> </Price> <PreferredContainer primary="wrecksecarmcab" amount="1" spawnprobability="0.05" /> <Deconstruct time="20"> <Item identifier="steel" /> </Deconstruct> <Fabricate suitablefabricators="fabricator" requiredtime="5" amount="3"> <RequiredItem identifier="steel" amount="1" /> </Fabricate> <InventoryIcon texture="%ModDir%/throwingknife.png" sourcerect="0,0,74,14" origin="0.5,0.5" /> <Sprite texture="%ModDir%/throwingknife.png" depth="0.7" sourcerect="0,0,74,14" origin="0.4,0.5" /> <Body width="74" height="12" density="15" /> <Holdable slots="Any,RightHand" controlpose="true" holdpos="36,-25" aimpos="30,8" handle1="12,-6" holdangle="-50" aimangle="5" msg="ItemMsgPickUpSelect" canBeCombined="false"> <StatusEffect type="OnActive" target="This"> <SpawnItem identifiers="thg_throwingknife" spawnposition="ThisInventory" /> </StatusEffect> </Holdable> <RangedWeapon barrelpos="10,5" spread="1" unskilledspread="20" reload="0.65" combatPriority="25" drawhudwhenequipped="true" crosshairscale="0.2"> <Crosshair texture="Content/Items/Weapons/Crosshairs.png" sourcerect="0,256,256,256" /> <StatusEffect type="OnUse" target="This" condition="-100" disabledeltatime="true"> <Explosion range="150.0" force="5" shockwave="false" smoke="false" flames="false" flash="false" sparks="false" underwaterbubble="false" camerashake="0" /> </StatusEffect> <StatusEffect type="OnBroken" target="This" delay="0.06" disabledeltatime="true" stackable="false" checkconditionalalways="true"> <Remove /> </StatusEffect> <RequiredSkill identifier="weapons" level="45" /> </RangedWeapon> <Projectile characterusable="false" launchimpulse="15" sticktocharacters="true" sticktoitems="true" sticktostructures="true" sticktodoors="true"> <Attack targetimpulse="3.5" severlimbsprobability="0.55" itemdamage="10"> <Affliction identifier="bleeding" strength="25" /> <Affliction identifier="lacerations" strength="58" /> <Affliction identifier="stun" strength="1.35" /> </Attack> <StatusEffect type="OnActive" target="This" setvalue="true" condition="100" disabledeltatime="true" /> <StatusEffect type="OnActive" target="This"> <SpawnItem identifiers="thg_throwingknife" spawnposition="ThisInventory" /> </StatusEffect> </Projectile> <ItemContainer itempos="0,0" autofill="False" hideitems="true" capacity="1" drawinventory="false" canbeselected="false" removecontaineditemsondeconstruct="true"> <Containable items="thg_throwingknife" /> <ContainedStateIndicator texture="Content/UI/ContainerIndicators.png" sourcerect="0,0,1,1" /> </ItemContainer> </Item>
After
<?xml version="1.0" encoding="utf-8"?> <Items> <Item name="" identifier="otfx_throwingknife" category="Weapon" tags="smallitem,weapon" maxstacksize="12" scale="0.5" cargocontaineridentifier="metalcrate" impacttolerance="8" impactsoundtag="impact_metal_light"> <Price baseprice="15"> <Price storeidentifier="merchantoutpost" sold="false" multiplier="1.35" /> <Price storeidentifier="merchantcity" multiplier="1.25" minavailable="2" /> <Price storeidentifier="merchantresearch" sold="false" multiplier="1.25" /> <Price storeidentifier="merchantmilitary" multiplier="0.9" minavailable="4" /> <Price storeidentifier="merchantmine" sold="false" multiplier="1.25" /> <Price storeidentifier="merchantarmory" multiplier="0.9" minavailable="4" /> </Price> <Deconstruct time="10"> <Item identifier="steel" /> <Item identifier="plastic" /> </Deconstruct> <Fabricate suitablefabricators="fabricator" requiredtime="20" amount="12"> <RequiredSkill identifier="weapons" level="45" /> <RequiredItem identifier="steel" amount="2" /> <RequiredItem identifier="plastic" amount="2" /> </Fabricate> <InventoryIcon texture="%ModDir%/OTFX/Items/Weapons/weapons.png" sourcerect="256,192,59,17" origin="0.5,0.5" /> <Sprite texture="%ModDir%/OTFX/Items/Weapons/weapons.png" sourcerect="256,192,59,17" depth="0.55" origin="0.5,0.5" /> <Body width="59" height="17" density="25" /> <Holdable slots="Any,LeftHand,RightHand" controlpose="true" aimpos="-10,30" handle1="10,0" holdangle="-150" aimable="true" msg="ItemMsgPickUpSelect" canbecombined="false"> <!-- simulate throwing actions --> <StatusEffect type="OnSecondaryUse" target="This" aimpos="50,10" setvalue="true"> <Conditional targetitemcomponent="RangedWeapon" reloadtimer="gt 0.6" /> </StatusEffect> <StatusEffect type="OnSecondaryUse" target="This" aimpos="-10,30" setvalue="true"> <Conditional targetitemcomponent="RangedWeapon" reloadtimer="lt 0.6" /> </StatusEffect> <StatusEffect type="OnUse" target="This" aimpos="50,10" setvalue="true" comparison="And"> <Conditional targetitemcomponent="RangedWeapon" reloadtimer="lt 0.1" /> </StatusEffect> <!-- clone self only once --> <StatusEffect type="OnActive" target="This" oneshot="true"> <SpawnItem identifier="otfx_throwingknife" spawnposition="ThisInventory" spawnifinventoryfull="true" /> </StatusEffect> </Holdable> <RangedWeapon barrelpos="0,0" spread="1" unskilledspread="20" reload="0.7" combatpriority="40" drawhudwhenequipped="true" crosshairscale="0.2"> <Crosshair texture="Content/Items/Weapons/Crosshairs.png" sourcerect="0,256,256,256" /> <Sound file="%ModDir%/OTFX/Items/Weapons/throwingknife_toss1.ogg" type="OnUse" range="500" selectionmode="Random" /> <Sound file="%ModDir%/OTFX/Items/Weapons/throwingknife_toss2.ogg" type="OnUse" range="500" /> <StatusEffect type="OnUse" target="This"> <Explosion range="50" force="5" showeffects="false" /> <Remove /> </StatusEffect> <RequiredItems identifier="otfx_throwingknife" type="Contained" /> <RequiredSkill identifier="weapons" level="45" /> </RangedWeapon> <Projectile characterusable="false" launchimpulse="15" impulsespread="0.01" sticktocharacters="true" sticktoitems="true" sticktostructures="true" sticktodoors="true"> <Attack targetimpulse="3" severlimbsprobability="0.1" itemdamage="3" structuredamage="2" structuresoundtype="StructureSlash"> <Affliction identifier="lacerations" strength="10" /> <Affliction identifier="bleeding" strength="6" /> <Affliction identifier="bleeding" strength="3" probability="0.5" /> <Affliction identifier="stun" strength="0.2" /> </Attack> <StatusEffect type="OnImpact" target="UseTarget"> <Conditional entitytype="Character" /> <Sound file="Content/Sounds/Damage/LimbSlash1.ogg" selectionmode="random" range="1000" /> <Sound file="Content/Sounds/Damage/LimbSlash2.ogg" range="1000" /> <Sound file="Content/Sounds/Damage/LimbSlash3.ogg" range="1000" /> <Sound file="Content/Sounds/Damage/LimbSlash4.ogg" range="1000" /> <Sound file="Content/Sounds/Damage/LimbSlash5.ogg" range="1000" /> <Sound file="Content/Sounds/Damage/LimbSlash6.ogg" range="1000" /> </StatusEffect> </Projectile> <ItemContainer characterusable="false" canbeselected="false" capacity="0" /> <!-- secondary ItemContainer prevents characters from accessing itself --> <ItemContainer characterusable="false" canbeselected="false" capacity="1" maxstacksize="1" hideitems="true" allowaccess="false" allowdraganddrop="false" allowswappingcontaineditems="false" autofill="false" removecontaineditemsondeconstruct="true"> <Containable items="otfx_throwingknife" /> </ItemContainer> <SkillRequirementHint identifier="weapons" level="45" /> </Item> </Items>
Last edited by whosyourdaddy; 8 Jun, 2023 @ 11:07pm