@DCass89
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GTA;
using GTA.Native;
using GTA.Math;
namespace MyFirstScript
{
public class Class1 : Script
{
public int listCount = 0;
List<Ped> myPeds = new List<Ped>();
public Class1()
{
Tick += onTick;
KeyDown += onKeyDown;
}
private void onTick(object sender, EventArgs e)
{
if (myPeds != null)
{
listCount = myPeds.Count();
}
else
{
UI.ShowSubtitle("myPeds is null");
}
}
private void onKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.L)
{
SpawnPed();
}
}
public void SpawnPed()
{
var myPed = World.CreatePed(PedHash.Miranda, Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 5, 0)));
myPeds.Add(myPed);
}
}
}
You never initialize the myPeds list, so it will always be null. You need to turn
List<Ped> myPeds;
into
List<Ped> myPeds = new List<Ped>();
like in the code I showed above.