static async Task ReAttachWeapons() { WeaponDisplay.GetAllDisplayedWeaponObjects() .Where(d => !(d.Value is null) && d.Value.Exists()) .ToList() .ForEach(d => { var weaponDisplayGroup = d.Key; var weaponObject = d.Value; var weapon = WeaponDisplay.GetWeapon(weaponDisplayGroup); // Try sync API.NetworkRegisterEntityAsNetworked(API.ObjToNet(weaponObject.Handle)); weaponObject.IsPersistent = true; var netId = API.NetworkGetNetworkIdFromEntity(weaponObject.Handle); API.SetNetworkIdCanMigrate(netId, true); API.SetNetworkIdExistsOnAllMachines(netId, true); API.NetworkRequestControlOfEntity(weaponObject.Handle); AttachWeapon(weapon, weaponObject); Debug.WriteLine($"[{ResourceName}]ReAttachWeapon: weapon: {weapon.Hash}, model: {weaponObject.Model.Hash}, handle: {weaponObject.Handle}"); }); await Delay(1000 * 10); }
private void Start() { int index = 0; foreach (var display in weaponsDisplayObjects) { CharacterManager.instance.character.attackManager.AddWeapon(); WeaponDisplay newDisplay = new WeaponDisplay(); newDisplay.index = index; index++; newDisplay.totalHitBonusField = display.transform.Find(totalhit).GetComponent <TextMeshProUGUI>(); newDisplay.abilityModifierField = display.transform.Find(abilityModifier).GetComponent <TextMeshProUGUI>(); newDisplay.abilityType = display.transform.Find(abilityType).GetComponent <TMP_Dropdown>(); newDisplay.weaponBonus = display.transform.Find(weaponBonus).GetComponent <TMP_InputField>(); newDisplay.weaponBonus.onValueChanged.AddListener(newDisplay.ModifyWeaponBonus); newDisplay.abilityType.onValueChanged.AddListener(newDisplay.ModifyAbilityType); newDisplay.ModifyWeaponBonus(newDisplay.weaponBonus.text); newDisplay.ModifyAbilityType(newDisplay.abilityType.value); weaponDisplays.Add(newDisplay); } CharacterManager.instance.onValuesReset += DisplayValues; baseAttackBonusField.onValueChanged.AddListener(ModifyBaB); currentAttackAlterationField.onValueChanged.AddListener(ModifyAlteration); DisplayValues(); }
static async Task UpdateWeaponsOnBackAsync() { await Delay(100); var currentWeaponInHand = Game.PlayerPed.Weapons.Current; // is weapon in hand changed? var isWeaponInHandChanged = _previousWeaponInHand != currentWeaponInHand; if (!isWeaponInHandChanged) { return; } var previousWeaponDisplayGroup = WeaponDisplay.GetWeaponDisplayGroup(_previousWeaponInHand); var currentWeaponDisplayGroup = WeaponDisplay.GetWeaponDisplayGroup(currentWeaponInHand); // update WeaponDisplay.SetWeapon(currentWeaponInHand); // prevent duplicate weapon objects WeaponDisplay.DeleteWeaponObject(currentWeaponDisplayGroup); WeaponDisplay.DeleteWeaponObject(previousWeaponDisplayGroup); var weaponNeedToCreate = _previousWeaponInHand; // update previous weapon in hand _previousWeaponInHand = currentWeaponInHand; var isWeaponNeedToDisplay = weaponNeedToCreate.Model.IsValid && weaponNeedToCreate.Model.IsInCdImage && !WeaponGroupBlacklist.Contains(weaponNeedToCreate.Group) && !WeaponBlacklist.Contains(weaponNeedToCreate.Hash); if (!isWeaponNeedToDisplay) { return; } var weaponObject = await CreateWeaponObject(weaponNeedToCreate); if (weaponObject is null) { Debug.WriteLine($"[{ResourceName}]Create object {weaponNeedToCreate.Model.Hash} failed"); return; } AttachWeapon(weaponNeedToCreate, weaponObject); WeaponDisplay.SetWeapon(WeaponDisplay.GetWeaponDisplayGroup(weaponNeedToCreate), weaponNeedToCreate); WeaponDisplay.SetWeaponObject(WeaponDisplay.GetWeaponDisplayGroup(weaponNeedToCreate), weaponObject); _latestWeaponObjectOnBack = weaponObject; _latestWeaponOnBack = weaponNeedToCreate; }
static async Task UpdateWeaponsOnBackAsync() { await Delay(100); var currentWeaponInHand = Game.PlayerPed.Weapons.Current; // is weapon in hand changed? var isWeaponInHandChanged = _previousWeaponInHand != currentWeaponInHand; if (!isWeaponInHandChanged) { return; } var previousWeaponDisplayGroup = WeaponDisplay.GetWeaponDisplayGroup(_previousWeaponInHand); var currentWeaponDisplayGroup = WeaponDisplay.GetWeaponDisplayGroup(currentWeaponInHand); // update WeaponDisplay.SetWeapon(currentWeaponInHand); // prevent duplicate weapon objects WeaponDisplay.DeleteWeaponObject(currentWeaponDisplayGroup); WeaponDisplay.DeleteWeaponObject(previousWeaponDisplayGroup); var weaponNeedToCreate = _previousWeaponInHand; // update previous weapon in hand _previousWeaponInHand = currentWeaponInHand; var isWeaponNeedToDisplay = weaponNeedToCreate.Model.IsValid && weaponNeedToCreate.Model.IsInCdImage && !WeaponGroupsBlacklist.Contains(weaponNeedToCreate.Group) && !WeaponsBlacklist.Contains(weaponNeedToCreate.Hash); if (!isWeaponNeedToDisplay) { return; } var weaponObject = await CreateWeaponObject(weaponNeedToCreate); if (weaponObject is null) { Debug.WriteLine($"[{ResourceName}]Create object {weaponNeedToCreate.Model.Hash} failed"); return; } var info = WeaponsAttachDetails.Single(wad => wad.WeaponGroup == weaponNeedToCreate.Group); weaponObject.AttachTo(Game.PlayerPed.Bones[info.Bone], info.Position, info.Rotation); Debug.WriteLine($"[{ResourceName}]Attach {weaponNeedToCreate.Hash}({weaponNeedToCreate.Group}) to {info.Bone}, {info.Position}, {info.Rotation}"); WeaponDisplay.SetWeaponObject(WeaponDisplay.GetWeaponDisplayGroup(weaponNeedToCreate), weaponObject); }
private void OnEntityTracked(Entity entity) { if (!_entityToWeaponDisplaysMap.ContainsKey(entity)) { Weapon weapon = entity.GetEntityComponent <Weapon>(); WeaponDisplay weaponWheel = Instantiate(_weaponDisplayPrefab, _container); _entityToWeaponDisplaysMap.Add(entity, weaponWheel); weapon.SwitchedWeaponEvent += UpdateCurrentWeapon; // Initially Set values UpdateWheelItems(weapon); UpdateCurrentWeapon(weapon); } }
public WeaponOnBack() { _previousWeaponInHand = Game.PlayerPed.Weapons[WeaponHash.Unarmed]; Tick += UpdateWeaponsOnBackAsync; #if DEBUG API.RegisterCommand("wob-current", new Action(() => { var currentWeapon = Game.PlayerPed.Weapons.Current; var currentWeaponSlot = API.GetWeapontypeSlot((uint)currentWeapon.Hash); var currentWeapontypeInSlot = API.GetPedWeapontypeInSlot(Game.PlayerPed.Handle, (uint)currentWeaponSlot); Debug.WriteLine($"currentWeapon: {(uint)currentWeapon.Hash}"); Debug.WriteLine($"Game.PlayerPed.Weapons.Current.Group: {(uint)Game.PlayerPed.Weapons.Current.Group}"); Debug.WriteLine($"currentWeaponSlot: {(uint)currentWeaponSlot}"); Debug.WriteLine($"currentWeapontypeInSlot: {(uint)currentWeapontypeInSlot}"); }), false); API.RegisterCommand("wob-pos", new Action <int, List <object>, string>((source, args, raw) => { var weaponObject = Entity.FromHandle(int.Parse(args[0].ToString())); if (weaponObject is null || !weaponObject.Exists()) { return; } var pedBone = Game.PlayerPed.Bones[(Bone)int.Parse(args[1].ToString())]; var attachPos = new Vector3(float.Parse(args[2].ToString()), float.Parse(args[3].ToString()), float.Parse(args[4].ToString())); var attachRot = new Vector3(float.Parse(args[5].ToString()), float.Parse(args[6].ToString()), float.Parse(args[7].ToString())); weaponObject.AttachTo(pedBone, attachPos, attachRot); // CurrentWeaponsOnBack.Values.ForEach(weaponObject => { }); }), false); API.RegisterCommand("wob-view", new Action(() => { Debug.WriteLine("_weaponAttachedObject"); WeaponDisplay.GetAllDisplayedWeaponObjects().ForEach(kvp => { var weaponObject = kvp.Value; Debug.WriteLine($"weapon: {weaponObject?.Model}({weaponObject?.Model.Hash}), modelHandle: {weaponObject?.Handle}"); }); }), false); #endif }
// Use this for initialization void Start() { posCurrWeapon = 0; currentWeapon = weaponList[posCurrWeapon]; for (int i = 0; i < weaponList.Length; i++) weaponList[i].Init(); if(weapons[posCurrWeapon].unlock) { currentWeapon.Show(); } cannonTurn = 0; rb = gameObject.GetComponent<Rigidbody>(); }
public void BuildPlayerHUD() { int g0cnt = 0; int g1cnt = 0; int g2cnt = 0; // Foreach weapon in mechManager weaponSys build weaponDisplay prefab for (int i = 0; i < connectedSystem.weaponExecutables.Count; i++) { var group = (int)connectedSystem.weaponExecutables[i].weaponItemRef.weaponClass; WeaponDisplay display = Instantiate(weaponDisplayPrefab, group0DisplayParent.transform).GetComponent<WeaponDisplay>(); if (group == 0) { display.transform.parent = group0DisplayParent.transform; g0cnt++; } else if (group == 1) { display.transform.parent = group1DisplayParent.transform; g1cnt++; } else if (group == 2) { display.transform.parent = group2DisplayParent.transform; g2cnt++; } display.transform.localPosition = Vector3.zero; display.refExec = connectedSystem.weaponExecutables[i]; } if (g0cnt == 0) Instantiate(emptyDisplayPrefab, group0DisplayParent.transform); if (g1cnt == 0) Instantiate(emptyDisplayPrefab, group1DisplayParent.transform); if (g2cnt == 0) Instantiate(emptyDisplayPrefab, group2DisplayParent.transform); }
private void ShowCurrentWeapon(int currentWeaponInt) { posCurrWeapon = currentWeaponInt; currentWeapon.Hide(); if(weapons[posCurrWeapon].unlock) { currentWeapon = weaponList[posCurrWeapon]; currentWeapon.Show(); if (right) right = false; else right = true; } }
public WeaponOnBack() { _previousWeaponInHand = Game.PlayerPed.Weapons[WeaponHash.Unarmed]; Tick += UpdateWeaponsOnBackAsync; Tick += LoadWeaponAsset; Tick += ReAttachWeapons; API.RegisterCommand("wob", new Action <int, List <object>, string>((source, args, raw) => { try { var commandArg1 = args[0].ToString().ToLower(); var weapon = _latestWeaponOnBack; var weaponObject = _latestWeaponObjectOnBack; switch (commandArg1) { case "pos": case "position": var position = new Vector3( float.Parse(args[1].ToString()) / 100, float.Parse(args[2].ToString()) / 100, float.Parse(args[3].ToString()) / 100); WeaponOffset.Set(weapon.Hash, WeaponOffset.OffsetType.Position, position); AttachWeapon(weapon, weaponObject); Debug.WriteLine($"[{ResourceName}]{GameModeName}:{ResourceName}:CommandSucceed: {raw}"); TriggerEvent($"{GameModeName}:{ResourceName}:CommandSucceed", raw); break; case "rot": case "rotation": var rotation = new Vector3( float.Parse(args[1].ToString()), float.Parse(args[2].ToString()), float.Parse(args[3].ToString())); WeaponOffset.Set(weapon.Hash, WeaponOffset.OffsetType.Rotation, rotation); AttachWeapon(weapon, weaponObject); Debug.WriteLine($"[{ResourceName}]{GameModeName}:{ResourceName}:CommandSucceed: {raw}"); TriggerEvent($"{GameModeName}:{ResourceName}:CommandSucceed", raw); break; // case "reg": // // Sync // var handle = weaponObject.Handle; // // if (API.NetworkGetEntityIsNetworked(weaponObject.Handle)) // { // Debug.WriteLine($"not networked {weaponObject.Handle}"); // } // weaponObject.IsPersistent = true; // var netId = API.NetworkGetNetworkIdFromEntity(handle); // API.NetworkRegisterEntityAsNetworked(API.ObjToNet(handle)); // API.SetNetworkIdCanMigrate(netId, true); // API.SetNetworkIdExistsOnAllMachines(netId, true); // API.NetworkRequestControlOfEntity(handle); // Debug.WriteLine($"try set prop as networked {weaponObject.Handle}"); // break; default: Debug.WriteLine($"[{ResourceName}]{GameModeName}:{ResourceName}:CommandFailed: {raw}"); TriggerEvent($"{GameModeName}:{ResourceName}:CommandFailed", raw); break; } } catch (Exception e) { Debug.WriteLine($"[{ResourceName}][ERROR]{e.Message}"); // Debug.WriteLine($"[{ResourceName}]Usage: /wob pos [posX] [posY] [posZ]"); // Debug.WriteLine($"[{ResourceName}]Usage: /wob rot [rotX] [rotY] [rotZ]"); Debug.WriteLine($"[{ResourceName}]{GameModeName}:{ResourceName}:CommandFailed: {raw}"); TriggerEvent($"{GameModeName}:{ResourceName}:CommandFailed", raw); } }), false); #if DEBUG API.RegisterCommand("wob-current", new Action(() => { var currentWeapon = Game.PlayerPed.Weapons.Current; var currentWeaponSlot = API.GetWeapontypeSlot((uint)currentWeapon.Hash); var currentWeapontypeInSlot = API.GetPedWeapontypeInSlot(Game.PlayerPed.Handle, (uint)currentWeaponSlot); Debug.WriteLine($"currentWeapon: {(uint)currentWeapon.Hash}"); Debug.WriteLine($"Game.PlayerPed.Weapons.Current.Group: {(uint)Game.PlayerPed.Weapons.Current.Group}"); Debug.WriteLine($"currentWeaponSlot: {(uint)currentWeaponSlot}"); Debug.WriteLine($"currentWeapontypeInSlot: {(uint)currentWeapontypeInSlot}"); }), false); API.RegisterCommand("wob-pos", new Action <int, List <object>, string>((source, args, raw) => { var weaponObject = Entity.FromHandle(int.Parse(args[0].ToString())); if (weaponObject is null || !weaponObject.Exists()) { return; } var pedBone = Game.PlayerPed.Bones[(Bone)int.Parse(args[1].ToString())]; var attachPos = new Vector3(float.Parse(args[2].ToString()), float.Parse(args[3].ToString()), float.Parse(args[4].ToString())); var attachRot = new Vector3(float.Parse(args[5].ToString()), float.Parse(args[6].ToString()), float.Parse(args[7].ToString())); weaponObject.AttachTo(pedBone, attachPos, attachRot); // CurrentWeaponsOnBack.Values.ForEach(weaponObject => { }); }), false); API.RegisterCommand("wob-view", new Action(() => { Debug.WriteLine("_weaponAttachedObject"); WeaponDisplay.GetAllDisplayedWeaponObjects().ForEach(kvp => { var weaponObject = kvp.Value; Debug.WriteLine($"weapon: {weaponObject?.Model}({weaponObject?.Model.Hash}), modelHandle: {weaponObject?.Handle}"); }); }), false); #endif }
protected override void OnStop() { Debug.WriteLine($"[{ResourceName}]Stop."); WeaponDisplay.DeleteAllWeaponObjects(); }
void OnThisPlayerDead(ThisPlayerDeadEvent @event) { WeaponDisplay.DeleteAllWeaponObjects(); }
public void InitializeWeaponManager() { leftArm = GetComponent <Player>().LeftArm; weaponDisplay = leftArm.GetComponentInChildren <WeaponDisplay>(); }