private void getLoadout(dynamic loadout) { Debug.WriteLine(API.PlayerPedId().ToString()); foreach (var row in loadout) { JArray componentes = Newtonsoft.Json.JsonConvert.DeserializeObject(row.components.ToString()); JObject amunitions = Newtonsoft.Json.JsonConvert.DeserializeObject(row.ammo.ToString()); List <string> components = new List <string>(); Dictionary <string, int> ammos = new Dictionary <string, int>(); foreach (JToken componente in componentes) { components.Add(componente.ToString()); } foreach (JProperty amunition in amunitions.Properties()) { ammos.Add(amunition.Name, int.Parse(amunition.Value.ToString())); } Debug.WriteLine(row.used.ToString()); bool auused = false; if (row.used == 1) { auused = true; } WeaponClass auxweapon = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), ammos, components, auused); userWeapons.Add(auxweapon.getId(), auxweapon); if (auxweapon.getUsed()) { Utils.useWeapon(auxweapon.getId()); } } }
private void receiveWeapon(int id, string propietary, string name, ExpandoObject ammo, List<dynamic> components) { Dictionary<string, int> ammoaux = new Dictionary<string, int>(); foreach (KeyValuePair<string, object> amo in ammo) { ammoaux.Add(amo.Key, int.Parse(amo.Value.ToString())); } List<string> auxcomponents = new List<string>(); foreach (var comp in components) { auxcomponents.Add(comp.ToString()); } WeaponClass weapon = new WeaponClass(id, propietary, name, ammoaux, auxcomponents, false,false); if (!userWeapons.ContainsKey(weapon.getId())) { userWeapons.Add(weapon.getId(), weapon); } NUIEvents.LoadInv(); }