mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-15 00:37:09 +00:00
add weapon to peds spawned with commands
This commit is contained in:
parent
66d0f5aec4
commit
adf3b7d31c
4 changed files with 61 additions and 8 deletions
|
@ -256,7 +256,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
return ai;
|
||||
}
|
||||
|
||||
private void AddWeaponToPed(Ped ped)
|
||||
public void AddWeaponToPed(Ped ped)
|
||||
{
|
||||
if (null == ped.PedDef)
|
||||
return;
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")]
|
||||
|
|
Loading…
Reference in a new issue