add weapon to peds spawned with commands

This commit is contained in:
in0finite 2021-09-13 00:54:56 +02:00
parent 66d0f5aec4
commit adf3b7d31c
4 changed files with 61 additions and 8 deletions

View file

@ -256,7 +256,7 @@ namespace SanAndreasUnity.Behaviours
return ai;
}
private void AddWeaponToPed(Ped ped)
public void AddWeaponToPed(Ped ped)
{
if (null == ped.PedDef)
return;

View file

@ -422,15 +422,20 @@ namespace SanAndreasUnity.Behaviours {
}
public void AddRandomWeapons ()
public void AddRandomWeapons()
{
if (!NetStatus.IsServer)
return;
int[] slots = new int[] { WeaponSlot.Pistol, WeaponSlot.Shotgun, WeaponSlot.Submachine,
WeaponSlot.Machine, WeaponSlot.Rifle, WeaponSlot.Heavy
};
AddRandomWeapons(slots);
}
public void AddRandomWeapons (int[] slots)
{
if (!NetStatus.IsServer)
return;
var groups = WeaponData.LoadedWeaponsData.Where( wd => slots.Contains( wd.weaponslot ) )
.DistinctBy( wd => wd.weaponType )
.GroupBy( wd => wd.weaponslot );

View file

@ -1,4 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@ -119,7 +119,8 @@ namespace SanAndreasUnity.Commands
if (!GetPedModelId(arguments, 1, out int modelId))
return pedModelIdDoesNotExist;
Ped.SpawnPedStalker(modelId, player.OwnedPed.transform, player.OwnedPed);
var pedAI = Ped.SpawnPedStalker(modelId, player.OwnedPed.transform, player.OwnedPed);
AddWeaponToSpawnedPed(pedAI.MyPed, false);
return CommandManager.ProcessCommandResult.Success;
}
@ -132,7 +133,7 @@ namespace SanAndreasUnity.Commands
return pedModelIdDoesNotExist;
var pedAI = Ped.SpawnPedAI(modelId, player.OwnedPed.transform, 15f, 30f);
// add weapon ...
AddWeaponToSpawnedPed(pedAI.MyPed, true);
pedAI.StartChasing(player.OwnedPed);
return CommandManager.ProcessCommandResult.Success;
@ -262,5 +263,42 @@ namespace SanAndreasUnity.Commands
return CommandManager.ProcessCommandResult.UnknownCommand;
}
void AddWeaponToSpawnedPed(Ped ped, bool force)
{
this.StartCoroutine(this.AddWeaponToSpawnedPedCoroutine(ped, force));
}
IEnumerator AddWeaponToSpawnedPedCoroutine(Ped ped, bool force)
{
yield return null;
yield return null;
if (ped.PedDef == null)
yield break;
//int[] weaponIds = new[] {WeaponId.Pistol, WeaponId.DesertEagle, WeaponId.Shotgun, WeaponId.SPAS12, WeaponId.SawnOff};
int[] slots = new int[]
{
WeaponSlot.Pistol, WeaponSlot.Shotgun, WeaponSlot.Submachine, WeaponSlot.Machine,
};
if (force)
{
int chosenSlot = slots.RandomElement();
ped.WeaponHolder.AddRandomWeapons(new[] {chosenSlot});
ped.WeaponHolder.SwitchWeapon(chosenSlot);
yield break;
}
/*var type = ped.PedDef.DefaultType;
if (type.IsGangMember() || type.IsCriminal() || type.IsCop())
{
ped.WeaponHolder.AddWeapon(WeaponId.Pistol);
}*/
NPCPedSpawner.Singleton.AddWeaponToPed(ped);
}
}
}

View file

@ -37,6 +37,16 @@ namespace SanAndreasUnity.Importing.Items.Definitions
{
return (pedestrianType & PedestrianType.GangMember) != 0;
}
public static bool IsCriminal(this PedestrianType pedestrianType)
{
return pedestrianType == PedestrianType.Criminal;
}
public static bool IsCop(this PedestrianType pedestrianType)
{
return pedestrianType == PedestrianType.Cop;
}
}
[Section("peds")]