Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using CitizenFX.Core;
  4. using static CitizenFX.Core.Native.API;
  5.  
  6. namespace FiveMLifeClient
  7. {
  8. class Commands
  9. {
  10. async private void SpawnCar(int source, List<object> args, string raw)
  11. {
  12. // account for the argument not being passed
  13. var model = "adder";
  14. if (args.Count > 0)
  15. {
  16. model = args[0].ToString();
  17. }
  18.  
  19. // Check if the model actually exists and if not
  20. // write out a message
  21. var hash = (uint)GetHashKey(model);
  22. if (!IsModelInCdimage(hash) || !IsModelAVehicle(hash))
  23. {
  24. this.ChatAddMessage($"Failed to spawn {model}");
  25. return;
  26. }
  27.  
  28. // Create the vehicle
  29. var vehicle = await World.CreateVehicle(model, Game.PlayerPed.Position, Game.PlayerPed.Heading);
  30.  
  31. // Set the player ped into the vehicle and driver seat
  32. Game.PlayerPed.SetIntoVehicle(vehicle, VehicleSeat.Driver);
  33.  
  34. // Give message
  35. this.ChatAddMessage($"Spawned the {model} at your position. You are now also in the driver seat.");
  36. }
  37. }
  38.  
  39. class ChatMessage
  40. {
  41. private int[] Color { get; }
  42. private string[] Message { get; }
  43.  
  44. public ChatMessage(int[] color, string[] message)
  45. {
  46. this.Color = color;
  47. this.Message = message;
  48. }
  49. }
  50.  
  51. static class Chat
  52. {
  53. static void SendChatMessage(string message)
  54. {
  55. int[] color = { 255, 0, 0 };
  56. string[] messageArgs = { "Client", message };
  57.  
  58. ChatMessage chatMessage = new ChatMessage(color, messageArgs);
  59. TriggerEvent("chat:addMessage", chatMessage);
  60. }
  61. }
  62.  
  63. public class Client : BaseScript
  64. {
  65. /// <summary>
  66. /// Constructor for class 1
  67. /// Does not return anything
  68. /// </summary>
  69. public Client()
  70. {
  71. EventHandlers["onClientResourceStart"] += new Action<string>(this.OnClientResourceStart);
  72. }
  73.  
  74. /// <summary>
  75. /// When the client starts
  76. /// Does not return anything
  77. /// </summary>
  78. /// <param name="resourceName"></param>
  79. private void OnClientResourceStart(string resourceName)
  80. {
  81. // What is this??
  82. if (GetCurrentResourceName() != resourceName) return;
  83.  
  84. RegisterCommand("car", new Action<int, List<object>, string>(this.SpawnCar), false);
  85. }
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement