Guest User

TheClothes-multi.3.cs

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