private void canCarryAmountWeapons(int source, int quantity, CallbackDelegate cb) { PlayerList pl = new PlayerList(); Player p = pl[source]; string identifier = "steam:" + p.Identifiers["steam"]; dynamic CoreUser = vorpinventory_sv.CORE.getUser(source).getUsedCharacter; int charIdentifier = CoreUser.charIdentifier; int totalcount = getUserTotalCountWeapons(identifier, charIdentifier) + quantity; if (Config.MaxWeapons != -1) { if (totalcount <= Config.MaxWeapons) { cb.Invoke(true); } else { cb.Invoke(false); } } else { cb.Invoke(true); } }
private void addComponent(int player, int weaponId, string component, CallbackDelegate function) { PlayerList pl = new PlayerList(); Player p = pl[player]; string identifier = "steam:" + p.Identifiers["steam"]; if (ItemDatabase.userWeapons.ContainsKey(weaponId)) { if (ItemDatabase.userWeapons[weaponId].getPropietary() == identifier) { ItemDatabase.userWeapons[weaponId].setComponent(component); Exports["ghmattimysql"] .execute( $"UPDATE loadout SET components = '{Newtonsoft.Json.JsonConvert.SerializeObject(ItemDatabase.userWeapons[weaponId].getAllComponents())}' WHERE id=?", new[] { weaponId }); function.Invoke(true); p.TriggerEvent("vorpCoreClient:addComponent", weaponId, component); } else { function.Invoke(false); } } }
private void getUserWeapon(int player, CallbackDelegate function, int weapId) { PlayerList pl = new PlayerList(); Player p = pl[player]; string identifier = "steam:" + p.Identifiers["steam"]; Dictionary <string, dynamic> weapons = new Dictionary <string, dynamic>(); bool found = false; foreach (KeyValuePair <int, WeaponClass> weapon in ItemDatabase.userWeapons) { if (weapon.Value.getId() == weapId && !found) { Debug.WriteLine("Entro a ver"); weapons.Add("name", weapon.Value.getName()); weapons.Add("id", weapon.Value.getId()); weapons.Add("propietary", weapon.Value.getPropietary()); weapons.Add("used", weapon.Value.getUsed()); weapons.Add("ammo", weapon.Value.getAllAmmo()); weapons.Add("components", weapon.Value.getAllComponents()); found = true; } } function.Invoke(weapons); }
private void getUserWeapons(int player, CallbackDelegate function) { PlayerList pl = new PlayerList(); Player p = pl[player]; string identifier = "steam:" + p.Identifiers["steam"]; Dictionary <string, dynamic> weapons; List <Dictionary <string, dynamic> > userWeapons = new List <Dictionary <string, dynamic> >(); foreach (KeyValuePair <int, WeaponClass> weapon in ItemDatabase.userWeapons) { if (weapon.Value.getPropietary() == identifier) { weapons = new Dictionary <string, dynamic> { ["name"] = weapon.Value.getName(), ["id"] = weapon.Value.getId(), ["propietary"] = weapon.Value.getPropietary(), ["used"] = weapon.Value.getUsed(), ["ammo"] = weapon.Value.getAllAmmo(), ["components"] = weapon.Value.getAllComponents() }; userWeapons.Add(weapons); } } function.Invoke(userWeapons); }
private void RegisterPluginPage(string name, CallbackDelegate callback) { var resourceName = GetInvokingResource(); m_pluginPages[$"{name}"] = Tuple.Create <Func <IDictionary <string, object>, string>, string>( attributes => { var invokeResult = callback.Invoke(attributes); string s; if (invokeResult is Task <object> t) { // TODO: lol blocking? s = (t.Result)?.ToString() ?? ""; } else { s = invokeResult?.ToString() ?? ""; } return(s); }, resourceName ); }
// Update is called once per frame void Update() { //Increase the current Time until it hits one if (time < 1 && Value != _valueTarget) { var divider = Duration; if (ScaleWithAmount) { divider *= (Mathf.Abs(_valueTarget - _valueOrigin) / (float)AmountPerDuration); } time += Time.deltaTime / divider; } else { time = 1; //Check if this is the frame in which it hits one and will call the Callback letting the if (_value != _valueTarget) { Callback?.Invoke(_valueTarget); } } // Update the current Value to Interpolate between the Origin and the Target if (_value != _valueTarget) { _value = Mathf.RoundToInt(Mathf.SmoothStep(_valueOrigin, _valueTarget, time)); } text.text = string.Format(Format, _value); }
private void getInventory(int source, CallbackDelegate cb) { PlayerList pl = new PlayerList(); Player p = pl[source]; string identifier = "steam:" + p.Identifiers["steam"]; if (ItemDatabase.usersInventory.ContainsKey(identifier)) { List <object> useritems = new List <object>(); foreach (var items in ItemDatabase.usersInventory[identifier]) { Dictionary <string, object> item = new Dictionary <string, object>() { { "label", items.Value.getLabel() }, { "name", items.Value.getName() }, { "type", items.Value.getType() }, { "count", items.Value.getCount() }, { "limit", items.Value.getLimit() }, { "usable", items.Value.getUsable() } }; useritems.Add(item); } cb.Invoke(useritems); } }
private async void ToolbarItem_Clicked(object sender, EventArgs e) { if (map.Pins.FirstOrDefault() == null) { return; } // Set location var result = await UserDialogs.Instance.PromptAsync(new PromptConfig() { InputType = InputType.Number, Title = AppResources.radius, Text = "300" }); if (result != null && result.Ok) { var name = txtAddress.Text; if (string.IsNullOrEmpty(name)) { name = await GetNameAsync(); } if (!string.IsNullOrEmpty(name)) { _Callback.Invoke(int.Parse(result.Value), name, map.Pins.First().Position); await Navigation.PopAsync(); } } }
private void Register(dynamic info, CallbackDelegate errors) { if (string.IsNullOrWhiteSpace(info.Assembly)) { errors.Invoke("type invalid"); return; } if (plugins.ContainsKey(info.Assembly)) { errors.Invoke("already registered"); return; } plugins[info.Assembly] = new PluginRegistration(info.Assembly, info.Title); }
public async void ExecuteAsync(string query, IDictionary <string, object> parameters, CallbackDelegate callback, bool debug = false) { TResult result = default(TResult); Stopwatch stopwatch = new Stopwatch(); try { stopwatch.Start(); using (var connection = new NpgsqlConnection(ConnectionString)) { await connection.OpenAsync(); var ConnectionTime = stopwatch.ElapsedMilliseconds; stopwatch.Restart(); using (var command = CreateCommand(query, parameters, connection)) { var QueryTime = stopwatch.ElapsedMilliseconds; stopwatch.Restart(); result = await ReaderAsync(command); stopwatch.Stop(); if (debug) { Console.WriteLine(string.Format("[{0}] [C: {1}ms, Q: {2}ms, R: {3}ms] {4}", "Postgres", ConnectionTime, QueryTime, stopwatch.ElapsedMilliseconds, QueryToString(query, parameters))); } await BaseScript.Delay(0); callback.Invoke(result); } } } catch (AggregateException aggregateException) { var firstException = aggregateException.InnerExceptions.First(); if (!(firstException is NpgsqlException)) { throw aggregateException; } CitizenFX.Core.Debug.Write(string.Format("[ERROR] [{0}] An error happens on Postgres for query \"{1}\": {2}\n", "Postgres", QueryToString(query, parameters), firstException.Message)); } catch (NpgsqlException NpgsqlException) { CitizenFX.Core.Debug.Write(string.Format("[ERROR] [{0}] An error happens on Postgres for query \"{1}\": {2}\n", "Postgres", QueryToString(query, parameters), NpgsqlException.Message)); } catch (ArgumentNullException) { CitizenFX.Core.Debug.Write(string.Format("[ERROR] [{0}] Check the error above, an error happens when executing the callback from the query : \"{1}\"\n", "Postgres", QueryToString(query, parameters))); } catch (Exception exception) { CitizenFX.Core.Debug.Write(string.Format("[ERROR] [{0}] An critical error happens on Postgres for query \"{1}\": {2} {3}\n", "Postgres", QueryToString(query, parameters), exception.Message, exception.StackTrace)); } }
private void QueryAsync(string query, dynamic parameters, CallbackDelegate callback = null) { Task <int> resultTask = _mysqlDb.Query(query, _mysqlDb.TryParseParameters(parameters)); #pragma warning disable CS4014 resultTask.ContinueWith((task) => callback?.Invoke(task.Result)); #pragma warning restore CS4014 }
private void canCarryAmountWeapons(int source, int quantity, CallbackDelegate cb) { PlayerList pl = new PlayerList(); Player p = pl[source]; string identifier = "steam:" + p.Identifiers["steam"]; int totalcount = getUserTotalCountWeapons(identifier) + quantity; if (totalcount <= Config.MaxWeapons || Config.MaxWeapons != -1) { cb.Invoke(true); } else { cb.Invoke(false); } }
private void ThreadPoolCallback(object context) { callback?.Invoke(context); lock (lockCounter) { counter--; } }
private void getItems(int source, CallbackDelegate funcion, string item) { PlayerList pl = new PlayerList(); Player p = pl[source]; string identifier = "steam:" + p.Identifiers["steam"]; if (ItemDatabase.usersInventory.ContainsKey(identifier)) { if (ItemDatabase.usersInventory[identifier].ContainsKey(item)) { funcion.Invoke(ItemDatabase.usersInventory[identifier][item].getCount()); } else { funcion.Invoke(0); } } }
public void HasItem([FromSource] Player player, string item, CallbackDelegate cb) { var playerKP = new KeyValuePair <string, string>("player", player.Identifiers["steam"]); var hotbarKP = new KeyValuePair <string, string>("hotbar", player.Identifiers["steam"]); var playerHas = LoadedInventories[playerKP].Inventory.Values.Any(value => value.Id == item); var hotbarHas = LoadedInventories[hotbarKP].Inventory.Values.Any(value => value.Id == item); cb.Invoke(playerHas || hotbarHas); }
/// <summary> /// Async Wrapper for Transactions /// </summary> /// <param name="querys">List of database queries</param> /// <param name="parameters">Parameters of the queries</param> /// <param name="callback">FiveM callback function</param> private async void TransactionAsync(dynamic querys, dynamic parameters, CallbackDelegate callback = null) { await Initialized(); Task <bool> resultTask = mysql.Transaction(Utility.TryParseTransactionQuerys(querys), Utility.TryParseParameters(parameters)); #pragma warning disable CS4014 resultTask.ContinueWith((task) => callback?.Invoke(task.Result)); #pragma warning restore CS4014 }
/// <summary> /// Async Implementation of the Scalar command. /// </summary> /// <param name="query">The mysql database query string</param> /// <param name="parameters">Ideally an IDictionary or table of parameters, can be null, will be parsed</param> /// <param name="callback">FiveM callback function</param> private async void QueryScalarAsync(string query, dynamic parameters, CallbackDelegate callback = null) { await Initialized(); Task <object> resultTask = mysql.QueryScalar(query, Utility.TryParseParameters(parameters, settings.Debug)); #pragma warning disable CS4014 resultTask.ContinueWith((task) => callback?.Invoke(task.Result)); #pragma warning restore CS4014 }
private void getLabelFromId(String id, CallbackDelegate cb) { foreach (dynamic item in svItems) { if (id.Equals(item.Value.item)) { cb.Invoke(item.Value.label); } } }
private void canCarryAmountItem(int source, int quantity, CallbackDelegate cb) { PlayerList pl = new PlayerList(); Player p = pl[source]; string identifier = "steam:" + p.Identifiers["steam"]; if (ItemDatabase.usersInventory.ContainsKey(identifier)) { int totalcount = getUserTotalCount(identifier) + quantity; if (totalcount <= Config.MaxItems) { cb.Invoke(true); } else { cb.Invoke(false); } } }
public TResult Execute(string query, IDictionary <string, object> parameters = null, CallbackDelegate callback = null, bool debug = false) { TResult result = default(TResult); Stopwatch stopwatch = new Stopwatch(); try { if (debug) { stopwatch.Start(); } using (var connection = new MySqlConnection(ConnectionString)) { connection.Open(); using (var command = CreateCommand(query, parameters, connection)) { result = Reader(command); if (debug) { stopwatch.Stop(); // @TODO Function.Call<string>(Hash.GET_INVOKING_RESOURCE) Console.WriteLine(string.Format("[{0}] [{1}ms] {2}", "", stopwatch.ElapsedMilliseconds, command.CommandText)); } if (callback != null) { callback.Invoke(result); } } } } catch (AggregateException aggregateException) { var firstException = aggregateException.InnerExceptions.First(); if (!(firstException is MySqlException)) { throw aggregateException; } // @TODO Function.Call<string>(Hash.GET_INVOKING_RESOURCE) CitizenFX.Core.Debug.Write(string.Format("[ERROR] [{0}] An error happens on MySQL : {1}\n", "", firstException.Message)); } catch (MySqlException mysqlException) { // @TODO Function.Call<string>(Hash.GET_INVOKING_RESOURCE) CitizenFX.Core.Debug.Write(string.Format("[ERROR] [{0}] An error happens on MySQL : {1}\n", "", mysqlException.Message)); } return(result); }
/// <summary> /// Async Implementation of the Execute command. This is way faster than using the Query method /// </summary> /// <param name="query">The mysql database query string</param> /// <param name="parameters">Ideally an IDictionary or table of parameters, can be null, will be parsed</param> /// <param name="callback">FiveM callback function</param> private async void QueryAsync(string query, dynamic parameters, CallbackDelegate callback = null) { await Initialized(); long result = await mysql.Query(query, Parameters.TryParse(parameters, settings.Debug)); if (callback != null) { await Delay(0); // need to wait for the next server tick before invoking, will error otherwise callback.Invoke(result); } }
/// <summary> /// Insert wrapper for multiple rows, should be able to do single rows too /// </summary> /// <param name="table">Name of the table where the data is inserted</param> /// <param name="parameters">List of dictionaries each representing a row to be inserted</param> /// <param name="callback">FiveM callback function</param> /// <param name="lastInsertId">return the last insert id if true, otherwise affected rows</param> private async void Insert(string table, dynamic parameters, CallbackDelegate callback = null, bool lastInsertId = false) { await Initialized(); MultiRowCommandBuilder multiRow = await ParseMultiRow(table, parameters); bool isInsert = (callback == null) ? false : lastInsertId; Task <long> resultTask = mysql.Query(multiRow.CommandText, multiRow.Parameters, isInsert); #pragma warning disable CS4014 resultTask.ContinueWith((task) => callback?.Invoke(task.Result)); #pragma warning restore CS4014 }
/// <summary> /// Async Implementation of the Scalar command. /// </summary> /// <param name="query">The mysql database query string</param> /// <param name="parameters">Ideally an IDictionary or table of parameters, can be null, will be parsed</param> /// <param name="callback">FiveM callback function</param> private async void QueryScalarAsync(string query, dynamic parameters, CallbackDelegate callback = null) { await Initialized(); object result = await mysql.QueryScalar(query, Parameters.TryParse(parameters, settings.Debug)); if (callback != null) { await Delay(0); callback.Invoke(result); } }
internal void WrapTask <TResult>(string query, Task <TResult> task, CallbackDelegate cb) { task.ContinueWith(t => { m_results.Enqueue(() => { cb.Invoke(false, t.Result); }); ScheduleTick(); }, TaskContinuationOptions.OnlyOnRanToCompletion); task.ContinueWith(t => { m_results.Enqueue(() => { cb.Invoke(ExceptionToMessage(t, query), false); }); ScheduleTick(); }, TaskContinuationOptions.OnlyOnFaulted); }
/// <summary> /// Async Wrapper for Transactions /// </summary> /// <param name="querys">List of database queries</param> /// <param name="parameters">Parameters of the queries</param> /// <param name="callback">FiveM callback function</param> private async void TransactionAsync(dynamic querys, dynamic parameters, CallbackDelegate callback = null) { await Initialized(); bool result = await mysql.Transaction(TryParseTransactionQuerys(querys), Parameters.TryParse(parameters)); if (callback != null) { await Delay(0); callback.Invoke(result); } }
public async Task <TResult> ExecuteAsync(string query, IDictionary <string, object> parameters = null, CallbackDelegate callback = null, bool debug = false) { TResult result = default(TResult); Stopwatch stopwatch = new Stopwatch(); try { if (debug) { stopwatch.Start(); } using (var connection = new MySqlConnection(ConnectionString)) { await connection.OpenAsync(); using (var command = CreateCommand(query, parameters, connection)) { result = await ReaderAsync(command); if (debug) { stopwatch.Stop(); Console.WriteLine(string.Format("[{0}ms] {1}", stopwatch.ElapsedMilliseconds, command.CommandText)); } if (callback != null) { callback.Invoke(result); } } } } catch (AggregateException aggregateException) { var firstException = aggregateException.InnerExceptions.First(); if (!(firstException is MySqlException)) { throw aggregateException; } CitizenFX.Core.Debug.Write(string.Format("An error happens on MySQL : {0}\n", firstException.Message)); } catch (MySqlException mysqlException) { CitizenFX.Core.Debug.Write(string.Format("An error happens on MySQL : {0}\n", mysqlException.Message)); } return(result); }
private void getWeaponComponents(int player, CallbackDelegate function, int weaponId) { PlayerList pl = new PlayerList(); Player p = pl[player]; string identifier = "steam:" + p.Identifiers["steam"]; if (ItemDatabase.userWeapons.ContainsKey(weaponId)) { if (ItemDatabase.userWeapons[weaponId].getPropietary() == identifier) { function.Invoke(ItemDatabase.userWeapons[weaponId].getAllComponents()); } } }
public void OnPointerClick(PointerEventData eventData) { if (eventData.clickCount == 2) { Debug.Log("CelestialClickable double click: " + eventData.pointerCurrentRaycast.gameObject.name); SetTargeted?.Invoke(eventData.pointerCurrentRaycast.gameObject); } else if (eventData.clickCount == 1) { Debug.Log("CelestialClickable single click: " + eventData.pointerCurrentRaycast.gameObject.name); SetSelected?.Invoke(eventData.pointerCurrentRaycast.gameObject); } }
/// <summary> /// Insert wrapper for multiple rows, should be able to do single rows too /// </summary> /// <param name="table">Name of the table where the data is inserted</param> /// <param name="parameters">List of dictionaries each representing a row to be inserted</param> /// <param name="callback">FiveM callback function</param> /// <param name="lastInsertId">return the last insert id if true, otherwise affected rows</param> private async void Insert(string table, dynamic parameters, CallbackDelegate callback = null, bool lastInsertId = false) { await Initialized(); MultiRow multiRow = await ParseMultiRow(table, parameters); bool isInsert = (callback == null) ? false : lastInsertId; long result = await mysql.Query(multiRow.CommandText, multiRow.Parameters, isInsert); if (callback != null) { await Delay(0); callback.Invoke(result); } }
/// <summary> /// save the beacon /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ToolbarItem_Clicked(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtUUID.Text)) { UserDialogs.Instance.Toast(AppResources.txt_beacon_UUID_error); } bool isValid = Guid.TryParse(txtUUID.Text, out Guid uuID); if (!isValid) { UserDialogs.Instance.Toast(AppResources.txt_beacon_UUID_error2); } else { if (string.IsNullOrEmpty(txtMajor.Text)) { txtMajor.Text = "0"; } if (string.IsNullOrEmpty(txtMinor.Text)) { txtMinor.Text = "0"; } if (ushort.TryParse(txtMinor.Text, out ushort minor)) { if (ushort.TryParse(txtMajor.Text, out ushort major)) { var name = await GetNameAsync(); if (!string.IsNullOrEmpty(name)) { var beacon = new BeaconModel() { UUID = uuID, Id = uuID.ToString(), Name = name, Enabled = true, Minor = minor, Major = major }; _Callback.Invoke(beacon); await Navigation.PopAsync(); } } await Navigation.PopAsync(); } } }