Weapons

How to do stuff with weapons, the Redscript way

Weapon damage debugging

You can find a list of weapon damage effects next door on the yellow wiki.

To see damage types and damage proccs, you can useAngeVil's script (gist) and copy it to e.g. Cyberpunk 2077/r6/scripts/debug_damage_types.reds:

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

module TutorialHidingComponentPartsModule

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

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


// 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<WeaponEquipEvent>) -> Bool {
  let weaponRecord: wref<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<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<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();
}

Last updated

Was this helpful?