Skip to content

Latest commit

 

History

History
93 lines (70 loc) · 3.31 KB

File metadata and controls

93 lines (70 loc) · 3.31 KB
description How to do stuff with weapons, the Redscript way

Weapons

Weapon damage debugging

{% hint style="info" %} You can find a list of weapon damage effects next door on the yellow wiki. {% endhint %}

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:

{% hint style="warning" %} You have to include the logging.md functions for this to work! {% endhint %}

{% embed url="https://gist.github.com/Berdagon/6ae42e4ff6b0964808a91d32951c52e4" %}

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();
}