need to know something with creating menu's
-
For example:
//Here i give the player godmode var godmode = new UIMenuItem("Godmode", ""); playermenu.AddItem(godmode); playermenu.OnItemSelect += (sender, item, index) => { if (item == godmode) { Game.Player.IsInvincible = true; UI.Notify("Godmode Enabled"); } }; }
the script above enables godmode but how am i able to disable the godmode via the same option in the menu
-
@ShadoFax I believe u can use boolean to be the switch..
u can use this code below :
make boolean for example isActive, then inside if (item == godmode) put that boolean as an if..
Example :
if (item == godmode)
{
if (isActive)
{
Game.Player.IsInvincible = false;
isActive = !isActive;
UI.Notify("Godmode Disabled");
}
else
{
Game.Player.IsInvincible = true;
isActive = !isActive;
UI.Notify("Godmode Enabled");
}
}
-
thx but it says isActive; doesnt exists
-
IsActive is a global variable you would have to create.
Instead of that, use a UIMenuCheckboxItem.
-
@Jitnaught I just tried it but dind't work, could you show an example?
-
@ShadoFax bool isActive = false;
var godmode = new UIMenuItem("Godmode", "");
playermenu.AddItem(godmode);
playermenu.OnItemSelect += (sender, item, index) =>
{
if (item == godmode)
{
if (isActive)
{
Game.Player.IsInvincible = false;
isActive = !isActive;
UI.Notify("Godmode Disabled");
}
else
{
Game.Player.IsInvincible = true;
isActive = !isActive;
UI.Notify("Godmode Enabled");
}
}
};
}
-
var godModeItem = new UIMenuCheckboxItem("God Mode", false); //false = disabled by default godModeItem.CheckboxEvent += (item, state) => { Game.Player.IsInvincible = state; UI.Notify($"Godmode {(state ? "enabled" : "disabled")}"); }; playermenu.AddItem(godModeItem);
-
@Jitnaught yo ik this topic is old but when i use this it works and all but i got lots of var so if i do this only this godModeItem would work. But what if i got
var godModeItem = new UIMenuCheckboxItem("God mode", false);
var lol = new UIMenuCheckboxItem("lol", false);
? cuz then: lol.CheckboxEvent += (item, state) => wouldnt work
-
Why wouldn't it work? It should be the exact same process for each item.
-
@Jitnaught cuz otherwise it gives errors
playermenu.OnItemSelect += (sender, item, index) => (This is what i need for the kind of options such as Add money.
name.CheckboxEvent += (item, state) => (this is what i need to get the checkbox)i cant use
var addwanted = new UIMenuItem("Add Wanted Level", "Adds A Wanted Level");
var godmode = new UIMenuCheckboxItem("God Mode", false);playermenu.AddItem(addwanted);
playermenu.AddItem(godmode);playermenu.OnItemSelect += (sender, item, index) =>
if (item == addwanted)
{
if (Game.Player.WantedLevel < 5) { Game.Player.WantedLevel += 1; }
UI.Notify("Added A Wanted Level");
}godmode.CheckboxEvent += (item, state) =>
{
if (item == godmode)
{
Game.Player.IsInvincible = true;
UI.Notify("godmode on");
}