Advertisement
Guest User

TheClothes.3.cs

a guest
Apr 17th, 2025
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using GTA;
  5. using GTA.Native;
  6.  
  7. public class TheClothes : Script
  8. {
  9. private bool applied = false;
  10. private readonly string iniPath;
  11.  
  12. public TheClothes()
  13. {
  14. Interval = 100;
  15. Tick += OnTick;
  16. iniPath = Path.Combine(
  17. AppDomain.CurrentDomain.BaseDirectory,
  18. "TheCharacterClothesMod.ini"
  19. );
  20. }
  21.  
  22. private void OnTick(object sender, EventArgs e)
  23. {
  24. if (applied) return;
  25.  
  26. Wait(200);
  27.  
  28. if (!File.Exists(iniPath))
  29. {
  30. GTA.UI.Screen.ShowSubtitle("ClothesLoader: INI not found", 3000);
  31. applied = true;
  32. return;
  33. }
  34.  
  35. string[] lines = File.ReadAllLines(iniPath);
  36.  
  37. string section = GetSectionForCurrentPlayer();
  38. if (section == null)
  39. {
  40. applied = true;
  41. return;
  42. }
  43.  
  44. Dictionary<string,int> cfg = ParseIniSection(lines, section);
  45.  
  46. Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Game.Player.Character.Handle, 3, 22, 3, 0);
  47.  
  48. ApplyOutfit(Game.Player.Character, cfg);
  49. applied = true;
  50. }
  51.  
  52. private string GetSectionForCurrentPlayer()
  53. {
  54. int hash = Game.Player.Character.Model.Hash;
  55. if (hash == new Model("player_zero").Hash) return "MICHAEL";
  56. if (hash == new Model("player_one").Hash) return "FRANKLIN";
  57. if (hash == new Model("player_two").Hash) return "TREVOR";
  58. return null;
  59. }
  60.  
  61. private Dictionary<string,int> ParseIniSection(string[] lines, string section)
  62. {
  63. Dictionary<string,int> map = new Dictionary<string,int>(StringComparer.OrdinalIgnoreCase);
  64. bool inSection = false;
  65.  
  66. foreach (string raw in lines)
  67. {
  68. string line = raw.Trim();
  69. if (line.StartsWith("[") && line.EndsWith("]"))
  70. {
  71. string head = line.Substring(1, line.Length - 2);
  72. inSection = head.Equals(section, StringComparison.OrdinalIgnoreCase);
  73. }
  74. else if (inSection && line.IndexOf('=') > -1)
  75. {
  76. string[] parts = line.Split(new[]{'='}, 2);
  77. string key = parts[0].Trim();
  78. string valStr = parts[1].Trim();
  79. int val;
  80. if (int.TryParse(valStr, out val))
  81. {
  82. map[key] = val;
  83. }
  84. }
  85. }
  86. return map;
  87. }
  88.  
  89. private void ApplyOutfit(Ped ped, Dictionary<string,int> cfg)
  90. {
  91. for (int slot = 0; slot <= 11; slot++)
  92. {
  93. string keyId = null;
  94. switch (slot)
  95. {
  96. case 0: keyId = "HEAD_ID"; break;
  97. case 1: keyId = "BEARD_ID"; break;
  98. case 2: keyId = "HAIR_ID"; break;
  99. case 3: keyId = "TORSO_ID"; break;
  100. case 4: keyId = "LEGS_ID"; break;
  101. case 5: keyId = "HANDS_ID"; break;
  102. case 6: keyId = "FOOT_ID"; break;
  103. case 7: keyId = "EXTRA_PART1_ID"; break;
  104. case 8: keyId = "EXTRA_PART2_ID"; break;
  105. case 9: keyId = "MASKS_ID"; break;
  106. case 10: keyId = "AUXILLIRAY_PARTS_ID"; break;
  107. }
  108.  
  109. if (keyId != null)
  110. {
  111. int drawable;
  112. if (cfg.TryGetValue(keyId, out drawable))
  113. {
  114. string texKey = keyId.Replace("_ID", "_TEXTURE_ID");
  115. int textureKey;
  116. if (cfg.TryGetValue(texKey, out textureKey))
  117. {
  118. Function.Call(
  119. Hash.SET_PED_COMPONENT_VARIATION,
  120. ped.Handle, slot, drawable, textureKey, 0
  121. );
  122. }
  123. }
  124. }
  125. }
  126.  
  127. string[] propKeys = new string[] { "HAT", "GLASSES", "EARS" };
  128. for (int i = 0; i < propKeys.Length; i++)
  129. {
  130. string key = propKeys[i];
  131. string idKey = key + "_ID";
  132. int drawable;
  133. if (cfg.TryGetValue(idKey, out drawable))
  134. {
  135. if (drawable < 0)
  136. {
  137. Function.Call(Hash.CLEAR_PED_PROP, ped.Handle, i);
  138. }
  139. else
  140. {
  141. string texKey = key + "_TEXTURE_ID";
  142. int textureKey;
  143. if (cfg.TryGetValue(texKey, out textureKey))
  144. {
  145. Function.Call(
  146. Hash.SET_PED_PROP_INDEX,
  147. ped.Handle, i, drawable, textureKey, true
  148. );
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement