Scripting Weird Problem??
-
So i'm making a menu and it works fine and all but when i create a player menu i also wanted to add a modelmenu inside the playermenu option so i was thinking like this
playermenu.OnItemSelect += (sender, item, index) =>
playermodelmenu.OnItemSelect += (sender, item, index) =>}
if (item == healtharmor)
{
Game.Player.Character.Health = 1000;
Game.Player.Character.Armor = 100;
}
if (item == malecop)
{
Game.Player.ChangeModel("S_M_Y_COP_01");
}now they both dont work because it gives errors about:
playermodelmenu.OnItemSelect += (sender, item, index) =>
(they cant be used twice at once at that location)
does any1 know how to fix it?
i have been searching it up and none matches with this.it gives this error:
A local or parameter named 'sender' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
EDIT: i used an old version of the nativeui template i use and it allowed me to use OnItemSelect twice at the same location This is the script:
public class NativeUITemplate : Script
{
private Ped playerPed = Game.Player.Character;
private Player player = Game.Player;
private MenuPool _menuPool;//Here we will add the code to use a .INI file for your menu open key ScriptSettings config; Keys OpenMenu; //Now, we will add your sub menu, which in this case, will be player menu to change your player model. public void PlayerModelMenu(UIMenu menu) { var playermodelmenu = _menuPool.AddSubMenu(menu, "Player Menu"); for (int i = 0; i < 1; i++) ; //We will change our player model to the male LSPD officer var malecop = new UIMenuItem("Male LSPD Officer", ""); playermodelmenu.AddItem(malecop); playermodelmenu.OnItemSelect += (sender, item, index) => playermodelmenu.OnItemSelect += (sender, item, index) => { if (item == malecop) { Game.Player.ChangeModel("S_M_Y_COP_01"); } }; } //Now, we will add your sub menu, which in this case, will be vehicle menu to spawn a car public void VehicleMenu(UIMenu menu) { var vehiclemenu = _menuPool.AddSubMenu(menu, "Vehicle Spawning"); for (int i = 0; i < 1; i++) ; //For this example, we will be spawning the Adder var adder = new UIMenuItem("Adder", ""); var burrito = new UIMenuItem("Burrito", ""); vehiclemenu.AddItem(adder); vehiclemenu.AddItem(burrito); vehiclemenu.OnItemSelect += (sender, item, index) => vehiclemenu.OnItemSelect += (sender, item, index) => { if (item == adder) { Vehicle car = World.CreateVehicle("ADDER", Game.Player.Character.Position); Game.Player.Character.SetIntoVehicle(car, VehicleSeat.Driver); } if (item == burrito) { Vehicle car = World.CreateVehicle("BURRITO", Game.Player.Character.Position); Game.Player.Character.SetIntoVehicle(car, VehicleSeat.Driver); } }; } //Now, we will add your sub menu, which in this case, will be weapon menu to equip a weapon public void WeaponMenu(UIMenu menu) { var weapons = _menuPool.AddSubMenu(menu, "Weapon Menu"); for (int i = 0; i < 1; i++) ; //For this example, we will equipping a flashlight, combat pistol, and pump shotgun var newweapons = new UIMenuItem("Issue Weapons", ""); weapons.AddItem(newweapons); weapons.OnItemSelect += (sender, item, index) => { if (item == newweapons) { } }; } //Now we will add all of our sub menus into our main menu, and set the general information of the entire menu public NativeUITemplate() { _menuPool = new MenuPool(); var mainMenu = new UIMenu("~r~Police~w~Menu ~b~V", "~b~Mod by Abel Gaming! ~r~V 1.9"); _menuPool.Add(mainMenu); PlayerModelMenu(mainMenu); //Here we add the Player Model Sub Menu VehicleMenu(mainMenu); //Here we add the Vehicle Spawning Sub Menu WeaponMenu(mainMenu); //Here we add the Weapon Sub Menu _menuPool.RefreshIndex(); //We will now call from the .INI file for our controls config = ScriptSettings.Load("scripts\\settings.ini"); OpenMenu = config.GetValue<Keys>("Options", "OpenMenu", Keys.F7); //The F7 key will be set my default, but the user can change the key //This code will run with every ms tick Tick += (o, e) => _menuPool.ProcessMenus(); //This code will open the menu KeyDown += (o, e) => { if (e.KeyCode == OpenMenu && !_menuPool.IsAnyMenuOpen()) // Our menu on/off switch mainMenu.Visible = !mainMenu.Visible; }; }
}
there are no errors in that script
my script i use now and got error
I WILL NOT GIVE THE FULL SCRIPT FOR THIS ONE FOR COPY ISSUES:
public class NativeUITemplate : Script
{
private Ped playerPed = Game.Player.Character;
private Player player = Game.Player;
private MenuPool _menuPool;public void VehicleMenu(UIMenu menu)
{
var vehiclemenu = _menuPool.AddSubMenu(menu, "Vehicle Menu");
var vehicleoptions = _menuPool.AddSubMenu(vehiclemenu, "Vehicle Spawning");vehicleoptions.OnItemSelect += (sender, item, index) =>
vehicleoptions.OnItemSelect += (sender, item, index) =>{ if (item == adder) { Vehicle car = World.CreateVehicle("ADDER", Game.Player.Character.Position); Game.Player.Character.SetIntoVehicle(car, VehicleSeat.Driver); } }
this does gives me error about the
vehicleoptions.OnItemSelect += (sender, item, index) =>
for using it twice
-
What is the reason for :-
playermenu.OnItemSelect += (sender, item, index) =>
playermodelmenu.OnItemSelect += (sender, item, index) =>I cant think of a reason to do this.. if you want the playermodelmenu to do something when you select something in that menu, you only need to register to the playermodelmenu.OnItemSelect event.. No reason for
playermenu.OnItemSelect += (sender, item, index) => at all, as when you open a sub menu the playermenu is no longer open.
-
This post is deleted!
-
@mcal9909 if i dont use playermenu.OnItemSelect += (sender, item, index) => i will get errors about item not existing and if i do use playermenu.OnItemSelect += (sender, item, index) => i can only do if statements that have been connected with the playermenu
-
@ShadoFax said in Scripting Weird Problem??:
After you create playermodelmenu object, try
playermodelmenu.OnItemSelect += OnPlayerModelSelect;
then create a
void OnPlayerModelSelect(UIMenu sender, UIMenuItem item, int index)
{
if(item == YourItem)
{
PutcodeHere;
}
}Thats how i do all mine, for menus and sub menus.. I have One menu that has 4 sub menus and it works.
-
@mcal9909 so this would let my player menu and playermodelmenu work?