private void setParamValue_scriptCmd(GTA.Script sender, GTA.ObjectCollection parameters) { if (parameters.Count < 5) { // Error code 1: invalid parameter count SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 1); return; } string structName = parameters.Convert <string>(1); int index = 0; if (!int.TryParse(parameters.Convert <string>(2), out index)) { // Error code 2: invalid index SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 2); return; } CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName); if (tempStruct == null) { // Error code 3: invalid struct name SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 3); return; } string paramName = parameters.Convert <string>(3); SParameter tempParam = new SParameter(); if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0) { // Error code 4: invalid param name SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 4); return; } if (tempParam.Type == typeof(int)) { int newVal = parameters.Convert <int>(4); int retVal = tempStruct.SetParamValue <int>(index, paramName, newVal); if (retVal == -1) { // Error code 5: invalid param index number SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5); return; } } else if (tempParam.Type == typeof(string)) { string newVal = parameters.Convert <string>(4); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { // Error code 5: invalid param index number SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5); return; } else if (retVal == -3) { // Error code 6: input string too long SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 6); return; } } else if (tempParam.Type == typeof(char)) { string newValString = parameters.Convert <string>(4); char newVal = '\0'; int retVal = 0; if (newValString != string.Empty) { newVal = newValString[0]; if (retVal == -1) { // Error code 5: invalid param index number SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5); return; } } else { // Error code 6: invalid character entered SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 6); return; } } else if (tempParam.Type == typeof(float)) { float newVal = parameters.Convert <float>(4); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { // Error code 5: invalid param index number SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5); return; } } else if (tempParam.Type == typeof(double)) { double newVal = parameters.Convert <float>(4); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { // Error code 5: invalid param index number SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5); return; } } else if (tempParam.Type == typeof(short)) { short newVal = parameters.Convert <short>(4); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { // Error code 5: invalid param index number SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5); return; } } else if (tempParam.Type == typeof(long)) { long newVal = parameters.Convert <long>(4); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { // Error code 5: invalid param index number SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5); return; } } // Success! :D SendScriptCommand(sender, "si_setparamvalue_respons", parameters[0], 0); }
/// <summary> /// Edits a structure's parameter value, using the console input. /// </summary> /// <param name="parameters">The console input..</param> private void editStructureParam_console(ParameterCollection parameters) { if (parameters.Count < 4) { Game.Console.Print("usage: si_editparam <structure name> <element index> <param name> <new value>"); return; } string structName = parameters.ToString(0); int index = 0; if (!int.TryParse(parameters.ToString(1), out index)) { Game.Console.Print("Invalid index specified!"); return; } CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName); if (tempStruct == null) { Game.Console.Print("No struct found with name \"" + structName + "\"!"); return; } string paramName = parameters.ToString(2); SParameter tempParam = new SParameter(); if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0) { Game.Console.Print("No parameter found with name \"" + paramName + "\"!"); return; } if (tempParam.Type == typeof(int)) { int newVal = parameters.ToInteger(3); int retVal = tempStruct.SetParamValue <int>(index, paramName, newVal); if (retVal == -1) { Game.Console.Print("Invalid parameter index number"); return; } else { Game.Console.Print("Parameter changed"); } } else if (tempParam.Type == typeof(uint)) { uint newVal = uint.Parse(parameters.ToString(3)); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { Game.Console.Print("Invalid parameter index number"); return; } else { Game.Console.Print("Parameter changed"); } } else if (tempParam.Type == typeof(string)) { string newVal = parameters.ToString(3); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { Game.Console.Print("Invalid parameter index number"); return; } else if (retVal == -3) { Game.Console.Print("Input string too long! Max size: " + tempParam.StringSize.ToString() + ", your input: " + newVal.Length); return; } } else if (tempParam.Type == typeof(char)) { string newValString = parameters.ToString(3); char newVal = '\0'; int retVal = 0; if (newValString != string.Empty) { newVal = newValString[0]; if (retVal == -1) { Game.Console.Print("Invalid parameter index number"); return; } else { Game.Console.Print("Parameter changed"); } } else { Game.Console.Print("Invalid char entered!"); return; } } else if (tempParam.Type == typeof(float)) { float newVal = parameters.ToFloat(3); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { Game.Console.Print("Invalid parameter index number"); return; } else { Game.Console.Print("Parameter changed"); } } else if (tempParam.Type == typeof(double)) { double newVal = parameters.ToFloat(3); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { Game.Console.Print("Invalid parameter index number"); return; } else { Game.Console.Print("Parameter changed"); } } else if (tempParam.Type == typeof(short)) { short newVal = (short)parameters.ToInteger(3); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { Game.Console.Print("Invalid parameter index number"); return; } else { Game.Console.Print("Parameter changed"); } } else if (tempParam.Type == typeof(long)) { long newVal = parameters.ToInteger(3); int retVal = tempStruct.SetParamValue(index, paramName, newVal); if (retVal == -1) { Game.Console.Print("Invalid parameter index number"); return; } else { Game.Console.Print("Parameter changed"); } } }
private void getParamValue_scriptCmd(GTA.Script sender, GTA.ObjectCollection parameters) { // si_getparamvalue <call identifier> <structure name> <element index> <parameter name> if (parameters.Count < 4) { // Error code 1: invalid parameter count SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 1); return; } string structName = parameters.Convert <string>(1); int index = 0; if (!int.TryParse(parameters.Convert <string>(2), out index)) { // Error code 2: invalid index SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 2); return; } CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName); if (tempStruct == null) { // Error code 3: invalid struct name SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 3); return; } string paramName = parameters.Convert <string>(3); SParameter tempParam = new SParameter(); if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0) { // Error code 4: invalid param name SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 4); return; } if (tempParam.Type == typeof(int)) { int retVal = 0; tempStruct.GetParamValue(index, paramName, ref retVal); SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal); } else if (tempParam.Type == typeof(string)) { string retVal = string.Empty; tempStruct.GetParamValue(index, paramName, ref retVal); SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal); } else if (tempParam.Type == typeof(char)) { char retVal = char.MinValue; tempStruct.GetParamValue(index, paramName, ref retVal); SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal); } else if (tempParam.Type == typeof(float)) { float retVal = 0f; tempStruct.GetParamValue(index, paramName, ref retVal); SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal); } else if (tempParam.Type == typeof(double)) { double retVal = 0f; tempStruct.GetParamValue(index, paramName, ref retVal); SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal); } else if (tempParam.Type == typeof(short)) { short retVal = 0; tempStruct.GetParamValue(index, paramName, ref retVal); SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal); } else if (tempParam.Type == typeof(long)) { long retVal = 0; tempStruct.GetParamValue(index, paramName, ref retVal); SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal); } return; }