mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-14 00:07:15 +00:00
players can specify model id for their ped or stalker
This commit is contained in:
parent
000a8a6cc9
commit
e21ef25835
2 changed files with 52 additions and 19 deletions
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SanAndreasUnity.Behaviours;
|
||||
using SanAndreasUnity.Behaviours.Vehicles;
|
||||
using SanAndreasUnity.Net;
|
||||
|
@ -63,19 +64,43 @@ namespace SanAndreasUnity.Commands
|
|||
m_perPlayerData.Remove(player);
|
||||
}
|
||||
|
||||
bool GetPedModelId(string[] arguments, int argumentIndex, out int modelId)
|
||||
{
|
||||
if (argumentIndex >= arguments.Length)
|
||||
{
|
||||
modelId = Ped.RandomPedId;
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = int.Parse(arguments[argumentIndex]);
|
||||
bool idExists = Ped.SpawnablePedDefs.Any(def => def.Id == id);
|
||||
if (!idExists)
|
||||
{
|
||||
modelId = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
modelId = id;
|
||||
return true;
|
||||
}
|
||||
|
||||
CommandManager.ProcessCommandResult ProcessCommand(CommandManager.ProcessCommandContext context)
|
||||
{
|
||||
string[] arguments = CommandManager.SplitCommandIntoArguments(context.command);
|
||||
int numArguments = arguments.Length;
|
||||
Player player = context.player;
|
||||
var pedNotAliveResult = CommandManager.ProcessCommandResult.Error("You must control a ped to run this command");
|
||||
var pedModelIdDoesNotExist = CommandManager.ProcessCommandResult.Error("Specified model id does not exist");
|
||||
|
||||
if (arguments[0] == "skin")
|
||||
{
|
||||
if (null == player.OwnedPed)
|
||||
return pedNotAliveResult;
|
||||
|
||||
player.OwnedPed.PlayerModel.Load(Ped.RandomPedId);
|
||||
if (!GetPedModelId(arguments, 1, out int modelId))
|
||||
return pedModelIdDoesNotExist;
|
||||
|
||||
player.OwnedPed.PlayerModel.Load(modelId);
|
||||
|
||||
return CommandManager.ProcessCommandResult.Success;
|
||||
}
|
||||
|
@ -84,7 +109,10 @@ namespace SanAndreasUnity.Commands
|
|||
if (null == player.OwnedPed)
|
||||
return pedNotAliveResult;
|
||||
|
||||
Ped.SpawnPedStalker(Ped.RandomPedId, player.OwnedPed.transform, player.OwnedPed);
|
||||
if (!GetPedModelId(arguments, 1, out int modelId))
|
||||
return pedModelIdDoesNotExist;
|
||||
|
||||
Ped.SpawnPedStalker(modelId, player.OwnedPed.transform, player.OwnedPed);
|
||||
|
||||
return CommandManager.ProcessCommandResult.Success;
|
||||
}
|
||||
|
|
|
@ -120,11 +120,9 @@ namespace SanAndreasUnity.UI {
|
|||
|
||||
// display button which will open additional options
|
||||
itemRect = GUIUtils.GetNextRectInARowPerc (rect, ref i, buttonSpacing, widthPercsButtons);
|
||||
if (NetUtils.IsServer)
|
||||
if (GUI.Button(itemRect, "..."))
|
||||
{
|
||||
if (GUI.Button (itemRect, "...")) {
|
||||
m_currentPedIdWithOptions = def.Id;
|
||||
}
|
||||
m_currentPedIdWithOptions = def.Id;
|
||||
}
|
||||
|
||||
if (m_currentPedIdWithOptions == def.Id) {
|
||||
|
@ -132,22 +130,24 @@ namespace SanAndreasUnity.UI {
|
|||
|
||||
if (playerExists) {
|
||||
|
||||
if (NetUtils.IsServer)
|
||||
itemRect = GUIUtils.GetNextRectInARowPerc(rect, ref i, buttonSpacing, widthPercsButtons);
|
||||
if (GUI.Button(itemRect, "Switch"))
|
||||
{
|
||||
itemRect = GUIUtils.GetNextRectInARowPerc (rect, ref i, buttonSpacing, widthPercsButtons);
|
||||
if (GUI.Button (itemRect, "Switch")) {
|
||||
Ped.Instance.PlayerModel.Load (def.Id);
|
||||
}
|
||||
SendCommand($"/skin {def.Id}");
|
||||
}
|
||||
|
||||
itemRect = GUIUtils.GetNextRectInARowPerc (rect, ref i, buttonSpacing, widthPercsButtons);
|
||||
if (GUI.Button (itemRect, "Spawn")) {
|
||||
Ped.SpawnPed (def.Id, Ped.Instance.transform);
|
||||
}
|
||||
itemRect = GUIUtils.GetNextRectInARowPerc(rect, ref i, buttonSpacing, widthPercsButtons);
|
||||
GUI.enabled = NetUtils.IsServer;
|
||||
if (GUI.Button(itemRect, "Spawn"))
|
||||
{
|
||||
Ped.SpawnPed(def.Id, Ped.Instance.transform);
|
||||
}
|
||||
GUI.enabled = true;
|
||||
|
||||
itemRect = GUIUtils.GetNextRectInARowPerc (rect, ref i, buttonSpacing, widthPercsButtons);
|
||||
if (GUI.Button (itemRect, "Spawn stalker")) {
|
||||
Ped.SpawnPedStalker (def.Id, Ped.Instance.transform, Ped.Instance);
|
||||
}
|
||||
itemRect = GUIUtils.GetNextRectInARowPerc(rect, ref i, buttonSpacing, widthPercsButtons);
|
||||
if (GUI.Button(itemRect, "Spawn stalker"))
|
||||
{
|
||||
SendCommand($"/stalker {def.Id}");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -179,6 +179,11 @@ namespace SanAndreasUnity.UI {
|
|||
}
|
||||
}
|
||||
|
||||
void SendCommand(string command)
|
||||
{
|
||||
Chat.ChatManager.SendChatMessageToAllPlayersAsLocalPlayer(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue