Why not just use one function, e.g SpawnPed(Model model)
, and use that function for all of your spawns instead of individual functions for each model? Example:
public void SpawnPed(Model model)
{
Ped ped = World.CreatePed(model, Game.Player.Character.GetOffsetPosition(new Vector3(2, 1, 0)));
Function.Call(Hash.SET_PED_DEFAULT_COMPONENT_VARIATION, ped);
CurrentPed = ped;
EquipCurrentPed();
}
if (e.KeyCode == Keys.NumPad9)
{
if (spriteNum == 1) SpawnPed("RoninBrownModel");
else if (spriteNum == 2) SpawnPed("LaraWhiteModel");
else if (spriteNum == 3) SpawnPed("LaraBlack");
else if ...
...
}
Another improvement would be to use an array of models then use the spriteNum to get the model from the array.
public void SpawnPed(Model model)
{
Ped ped = World.CreatePed(model, Game.Player.Character.GetOffsetPosition(new Vector3(2, 1, 0)));
Function.Call(Hash.SET_PED_DEFAULT_COMPONENT_VARIATION, ped);
CurrentPed = ped;
EquipCurrentPed();
}
Model[] pedModels =
{
"model1",
"model2",
"model3"
};
if (e.KeyCode == Keys.NumPad9)
{
SpawnPed(pedModels[spriteNum]);
}
Keep in mind though that arrays are zero-indexed, meaning that to get the first item you have to use the number 0 (e.g. pedModels[0]
), so you would have to make sure spriteNum is zero-indexed as well, or just subtract 1 from it.