> For the complete documentation index, see [llms.txt](https://wiki.redmodding.org/scripting-cyberpunk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.redmodding.org/scripting-cyberpunk/scripting/snippets-and-examples/entities/weapons.md).

# Weapons

How to do stuff with weapons, the Redscript way

### Weapon damage debugging

{% hint style="info" %}
You can find a list of weapon damage effects next door on the [yellow wiki.](https://wiki.redmodding.org/cyberpunk-2077-modding/for-mod-creators-theory/references-lists-and-overviews/cheat-sheet-tweak-ids/weapons/cheat-sheet-weapon-damage-effects)
{% endhint %}

To see damage types and damage proccs, you can use AngeVil's script ([gist](https://gist.github.com/Berdagon/6ae42e4ff6b0964808a91d32951c52e4)) and copy it to e.g. [`Cyberpunk 2077`](https://wiki.redmodding.org/cyberpunk-2077-modding/for-mod-users/users-modding-cyberpunk-2077/the-cyberpunk-2077-game-directory)`/r6/scripts/debug_damage_types.reds`:

{% hint style="warning" %}
You have to include the [Logging](/scripting-cyberpunk/redscript/common-patterns/logging.md) functions for this to work!
{% endhint %}

```swift
@replaceMethod(DamageSystem)
private final func ApplyStatusEffectByApplicationRate(hitEvent: ref<gameHitEvent>, statType: gamedataStatType, effect: TweakDBID) -> Void {
  let rand: Float;
  let ss: ref<StatsSystem> = GameInstance.GetStatsSystem(hitEvent.target.GetGame());
  let ses: ref<StatusEffectSystem> = GameInstance.GetStatusEffectSystem(hitEvent.target.GetGame());
  let weapon: wref<WeaponObject> = hitEvent.attackData.GetWeapon();
  let value: Float = ss.GetStatValue(Cast<StatsObjectID>(weapon.GetEntityID()), statType) / 100.00;
  if hitEvent.target.IsPlayer() {
    return;
  };
  if !FloatIsEqual(value, 0.00) {
    rand = RandRangeF(0.00, 1.00);
    if rand <= value {
      if !this.IsImmune(hitEvent.target, effect, hitEvent.attackData) {
        ses.ApplyStatusEffect(hitEvent.target.GetEntityID(), effect,GameObject.GetTDBID(hitEvent.attackData.GetInstigator()), hitEvent.attackData.GetInstigator().GetEntityID());
        LogChannel(n"DEBUG",s"StatusEffect Applied: \(TDBID.ToStringDEBUG(effect))");
        hitEvent.attackData.AddFlag(Equals(statType, gamedataStatType.StunApplicationRate) ? hitFlag.StunApplied : hitFlag.DotApplied, n"SETriggered");
      };
    };
  };
}

@wrapMethod(DamageSystem)
private final func ProcessPipeline(hitEvent: ref<gameHitEvent>, cache: ref<CacheData>) -> Void {
  let elecDmg: Float = hitEvent.attackComputed.GetAttackValue(gamedataDamageType.Electric);
  let thermDmg: Float = hitEvent.attackComputed.GetAttackValue(gamedataDamageType.Thermal);
  let chemDmg: Float = hitEvent.attackComputed.GetAttackValue(gamedataDamageType.Chemical);
  let physDmg: Float = hitEvent.attackComputed.GetAttackValue(gamedataDamageType.Physical);
  LogChannel(n"DEBUG",s"ProcessPipeline elecdmg: \(elecDmg), chemdmg: \(chemDmg), thermdmg: \(thermDmg), physdmg: \(physDmg)");
  wrappedMethod(hitEvent,cache);
}
```

### Hiding (Parts of) a component when a weapon is equipped

<pre class="language-swift"><code class="lang-swift">module TutorialHidingComponentPartsModule

private func hideComponent(componentName: String) -> Void {
  let player = GetPlayer(GetGameInstance());

  let component: ref&#x3C;IComponent> = player.FindComponentByName(t(componentName))
  // or cast the component to a different type 
  // by using "as entSkinnedMeshComponent" / changing e.g. ref&#x3C;entSkinnedMeshComponent>
  if IsDefined(component) {
    component.Toggle(false);
  }
}

<strong>
</strong>// If you don't know the component name, you can iterate over the components
private func showComponent(componentName: String) -> Void {
  let player = GetPlayer(GetGameInstance());
  let components = player.GetComponents();

  for component in components {
    if StrContains(s"\(component.GetName())", componentName) {
      component.Toggle(true);
    }
  }
}

@wrapMethod(PlayerPuppet)
protected cb func OnWeaponEquipEvent(event: ref&#x3C;WeaponEquipEvent>) -> Bool {
  let weaponRecord: wref&#x3C;ItemObject> = event.item;

  if !IsDefined(weaponRecord) {
    return wrappedMethod(event);
  }
  let id = weaponRecord.GetItemID();
  let id_str = TDBID.ToStringDEBUG(ItemID.GetTDBID(id));

  if StrContains(id_str, "Items.your_weapon") {
    hideComponent("your_component_name");
  }
  wrappedMethod(event);
}

private func OnItemUnequipped(slot: TweakDBID, item: ItemID) -> Void {

 if StrContains(TDBID.ToStringDEBUG(ItemID.GetTDBID(item)), "Items.your_weapon") {
    showComponent("your_component_name");
  }
}

private class PlayerPuppetAttachmentSlotsCallbackVenuzdnor extends PlayerPuppetAttachmentSlotsCallback {

  public let m_player: wref&#x3C;PlayerPuppet>;

  public func OnItemUnequipped(slot: TweakDBID, item: ItemID) -> Void {
    OnItemUnequipped(slot, item);
  }
}

@wrapMethod(EquipmentSystemPlayerData)
func OnRestored() -> Void {
  if IsDefined(this.m_owner as PlayerPuppet) {
    let attachmentSlotCallback: ref&#x3C;PlayerPuppetAttachmentSlotsCallback> = new PlayerPuppetAttachmentSlotsCallbackVenuzdnor();
    attachmentSlotCallback.m_player = (this.m_owner as PlayerPuppet);
    attachmentSlotCallback.slotID = t"AttachmentSlots.WeaponRight";
    GameInstance.GetTransactionSystem((this.m_owner as PlayerPuppet).GetGame()).RegisterAttachmentSlotListener(this.m_owner, attachmentSlotCallback);
  }
  wrappedMethod();
}

</code></pre>
