Advertisement
Guest User

TheClothes-multi.3.cs

a guest
Apr 19th, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 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. for (int slot = 0; slot <= 11; slot++)
  99. {
  100. string keyId = null;
  101. switch (slot)
  102. {
  103. case 0: keyId = "HEAD_ID"; break;
  104. case 1: keyId = "BEARD_ID"; break;
  105. case 2: keyId = "HAIR_ID"; break;
  106. case 3: keyId = "TORSO_ID"; break;
  107. case 4: keyId = "LEGS_ID"; break;
  108. case 5: keyId = "HANDS_ID"; break;
  109. case 6: keyId = "FOOT_ID"; break;
  110. case 7: keyId = "EXTRA_PART1_ID"; break;
  111. case 8: keyId = "EXTRA_PART2_ID"; break;
  112. case 9: keyId = "MASKS_ID"; break;
  113. case 10: keyId = "AUXILLIRAY_PARTS_ID"; break;
  114. }
  115.  
  116. if (keyId != null)
  117. {
  118. int drawable;
  119. if (cfg.TryGetValue(keyId, out drawable))
  120. {
  121. string texKey = keyId.Replace("_ID", "_TEXTURE_ID");
  122. int textureKey;
  123. if (cfg.TryGetValue(texKey, out textureKey))
  124. {
  125. Function.Call(
  126. Hash.SET_PED_COMPONENT_VARIATION,
  127. ped.Handle, slot, drawable, textureKey, 0
  128. );
  129. }
  130. }
  131. }
  132. }
  133.  
  134. string[] propKeys = new string[] { "HAT", "GLASSES", "EARS" };
  135. for (int i = 0; i < propKeys.Length; i++)
  136. {
  137. string key = propKeys[i];
  138. string idKey = key + "_ID";
  139. int drawable;
  140. if (cfg.TryGetValue(idKey, out drawable))
  141. {
  142. if (drawable < 0)
  143. {
  144. Function.Call(Hash.CLEAR_PED_PROP, ped.Handle, i);
  145. }
  146. else
  147. {
  148. string texKey = key + "_TEXTURE_ID";
  149. int textureKey;
  150. if (cfg.TryGetValue(texKey, out textureKey))
  151. {
  152. Function.Call(
  153. Hash.SET_PED_PROP_INDEX,
  154. ped.Handle, i, drawable, textureKey, true
  155. );
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement