Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using GTA;
- using GTA.Native;
- public class TheClothes : Script
- {
- private bool applied = false;
- private readonly string iniPath;
- private int lastModelHash = 0;
- private int modelCheckTimer = 0;
- public TheClothes()
- {
- Interval = 100;
- Tick += OnTick;
- iniPath = Path.Combine(
- AppDomain.CurrentDomain.BaseDirectory,
- "TheCharacterClothesMod.ini"
- );
- }
- private void OnTick(object sender, EventArgs e)
- {
- if (!File.Exists(iniPath)) return;
- int currentHash = Game.Player.Character.Model.Hash;
- if (!applied)
- {
- Wait(200);
- ApplyClothesForModel(currentHash);
- lastModelHash = currentHash;
- applied = true;
- }
- modelCheckTimer += Interval;
- if (modelCheckTimer >= 5000)
- {
- modelCheckTimer = 0;
- if (currentHash != lastModelHash)
- {
- ApplyClothesForModel(currentHash);
- lastModelHash = currentHash;
- }
- }
- }
- private void ApplyClothesForModel(int hash)
- {
- string section = GetSectionFromHash(hash);
- if (section == null) return;
- string[] lines = File.ReadAllLines(iniPath);
- Dictionary<string, int> cfg = ParseIniSection(lines, section);
- ApplyOutfit(Game.Player.Character, cfg);
- }
- private string GetSectionFromHash(int hash)
- {
- if (hash == new Model("player_zero").Hash) return "MICHAEL";
- if (hash == new Model("player_one").Hash) return "FRANKLIN";
- if (hash == new Model("player_two").Hash) return "TREVOR";
- return null;
- }
- private Dictionary<string,int> ParseIniSection(string[] lines, string section)
- {
- Dictionary<string,int> map = new Dictionary<string,int>(StringComparer.OrdinalIgnoreCase);
- bool inSection = false;
- foreach (string raw in lines)
- {
- string line = raw.Trim();
- if (line.StartsWith("[") && line.EndsWith("]"))
- {
- string head = line.Substring(1, line.Length - 2);
- inSection = head.Equals(section, StringComparison.OrdinalIgnoreCase);
- }
- else if (inSection && line.IndexOf('=') > -1)
- {
- string[] parts = line.Split(new[]{'='}, 2);
- string key = parts[0].Trim();
- string valStr = parts[1].Trim();
- int val;
- if (int.TryParse(valStr, out val))
- {
- map[key] = val;
- }
- }
- }
- return map;
- }
- private void ApplyOutfit(Ped ped, Dictionary<string,int> cfg)
- {
- for (int slot = 0; slot <= 11; slot++)
- {
- string keyId = null;
- switch (slot)
- {
- case 0: keyId = "HEAD_ID"; break;
- case 1: keyId = "BEARD_ID"; break;
- case 2: keyId = "HAIR_ID"; break;
- case 3: keyId = "TORSO_ID"; break;
- case 4: keyId = "LEGS_ID"; break;
- case 5: keyId = "HANDS_ID"; break;
- case 6: keyId = "FOOT_ID"; break;
- case 7: keyId = "EXTRA_PART1_ID"; break;
- case 8: keyId = "EXTRA_PART2_ID"; break;
- case 9: keyId = "MASKS_ID"; break;
- case 10: keyId = "AUXILLIRAY_PARTS_ID"; break;
- }
- if (keyId != null)
- {
- int drawable;
- if (cfg.TryGetValue(keyId, out drawable))
- {
- string texKey = keyId.Replace("_ID", "_TEXTURE_ID");
- int textureKey;
- if (cfg.TryGetValue(texKey, out textureKey))
- {
- Function.Call(
- Hash.SET_PED_COMPONENT_VARIATION,
- ped.Handle, slot, drawable, textureKey, 0
- );
- }
- }
- }
- }
- string[] propKeys = new string[] { "HAT", "GLASSES", "EARS" };
- for (int i = 0; i < propKeys.Length; i++)
- {
- string key = propKeys[i];
- string idKey = key + "_ID";
- int drawable;
- if (cfg.TryGetValue(idKey, out drawable))
- {
- if (drawable < 0)
- {
- Function.Call(Hash.CLEAR_PED_PROP, ped.Handle, i);
- }
- else
- {
- string texKey = key + "_TEXTURE_ID";
- int textureKey;
- if (cfg.TryGetValue(texKey, out textureKey))
- {
- Function.Call(
- Hash.SET_PED_PROP_INDEX,
- ped.Handle, i, drawable, textureKey, true
- );
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement