Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Cayo Perico Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

      1. Frontier Pursuits
      2. Find Lobbies & Outlaws
      3. Help & Support
    3. Crews

    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA VI

      1. St. Andrews Cathedral
    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

[C#] Help organizing my code?


Colata

Recommended Posts

    void MainMenu()    {        CloseMenu();        var menuItems = new List<IMenuItem> { new MenuLabel("Main Menu", true) };        var button = new MenuButton("Weapon Shop", "Enter the weapon shop!");        button.Activated += (sender, args) => this.WeaponMenu();             //Pistols        menuItems.Add(button);        button = new MenuButton("Car Shop", "Enter the showroom!");        button.Activated += (sender, args) => this.CarMenu();             //Pistols        menuItems.Add(button);        button = new MenuButton("Exit", "Exit the menu");        button.Activated += (sender, args) => this.CloseMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Main Menu", menuItems.ToArray()));    }    void WeaponMenu() //WEAPON MAIN MENU    {        var menuItems = new List<IMenuItem> { new MenuLabel("Weapon Shop", true) };        var button = new MenuButton("Pistols", "View the selection of pistols");        button.Activated += (sender, args) => this.OpenPistolMenu();             //Pistols        menuItems.Add(button);        button = new MenuButton("Shotguns", "View the selection of shotguns");        button.Activated += (sender, args) => this.OpenShotgunMenu();            //Shotguns        menuItems.Add(button);        button = new MenuButton("Sub Machine Guns", "View the selection of Sub Machine Guns"); //SMGs        button.Activated += (sender, args) => this.OpenSMGMenu();                    menuItems.Add(button);        button = new MenuButton("Sniper Rifles", "View the selection of Sniper Rifles"); //Snipers        button.Activated += (sender, args) => this.OpenSRMenu();                    menuItems.Add(button);        button = new MenuButton("Assault Rifles", "View the selection of Assault Rifles"); //ARs        button.Activated += (sender, args) => this.OpenARMenu();                    menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.MainMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Weapon Shop", menuItems.ToArray()));    }     void CarMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("Car Shop", true) };        var button = new MenuButton("Cars", "View the selection of Car Categories");        button.Activated += (sender, args) => this.CarMenus();                    menuItems.Add(button);        button = new MenuButton("Bikes", "View the selection of Bike Categories");        button.Activated += (sender, args) => this.BikeMenu();                   menuItems.Add(button);        button = new MenuButton("Aircraft", "View the selection of Aircraft Categories");        button.Activated += (sender, args) => this.AircraftMenu();                    menuItems.Add(button);        button = new MenuButton("Boats", "View the selection of Boat Categories");        button.Activated += (sender, args) => this.BoatMenu();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.MainMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Weapon Shop", menuItems.ToArray()));    }    //CAR MENU    void CarMenus() //CAR MAIN MENU    {        var menuItems = new List<IMenuItem> { new MenuLabel("Car Shop", true) };        var button = new MenuButton("Super", "View the selection of Super Cars");        button.Activated += (sender, args) => this.OpenSuperMenu();                     menuItems.Add(button);        button = new MenuButton("Sports", "View the selection of Sports Cars");        button.Activated += (sender, args) => this.OpenSportMenu();                  menuItems.Add(button);        button = new MenuButton("Sport Classic", "View the selection of Sport Classic Cars");         button.Activated += (sender, args) => this.OpenSportClassicMenu();        menuItems.Add(button);        button = new MenuButton("Coupes", "View the selection of Coupes");         button.Activated += (sender, args) => this.OpenCoupeMenu();        menuItems.Add(button);        button = new MenuButton("Muscles", "View the selection of Muscle Cars");         button.Activated += (sender, args) => this.OpenMuscleMenu();        menuItems.Add(button);        button = new MenuButton("Sedans", "View the selection of Sedan Cars");         button.Activated += (sender, args) => this.OpenSedanMenu();        menuItems.Add(button);        button = new MenuButton("Compacts", "View the selection of Compact Cars");         button.Activated += (sender, args) => this.OpenCompactMenu();        menuItems.Add(button);        button = new MenuButton("SUVs", "View the selection of SUVs");         button.Activated += (sender, args) => this.OpenSUVMenu();        menuItems.Add(button);        button = new MenuButton("Off-Road", "View the selection of Off-Road Cars");         button.Activated += (sender, args) => this.OpenOffRoadMenu();        menuItems.Add(button);        button = new MenuButton("Vans", "View the selection of Vans");         button.Activated += (sender, args) => this.OpenVanMenu();        menuItems.Add(button);        button = new MenuButton("Emergency", "View the selection of Emergency Vehicles");         button.Activated += (sender, args) => this.OpenEmergencyMenu();        menuItems.Add(button);        button = new MenuButton("Utility", "View the selection of Utility Vehicles");         button.Activated += (sender, args) => this.OpenUtilityMenu();        menuItems.Add(button);        button = new MenuButton("Service", "View the selection of Service Vehicles");        button.Activated += (sender, args) => this.OpenServiceMenu();        menuItems.Add(button);        button = new MenuButton("Industrial", "View the selection of Industrial Vehicles");         button.Activated += (sender, args) => this.OpenIndustrialMenu();        menuItems.Add(button);        button = new MenuButton("Commercial", "View the selection of Commercial Vehicles");         button.Activated += (sender, args) => this.OpenCommercialMenu();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.MainMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Weapon Shop", menuItems.ToArray()));    }    //CAR LIST    void BikeMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("Bike Shop", true) };        var button = new MenuButton("Motorcycles", "View the selection of Motorbikes");        button.Activated += (sender, args) => this.OpenMotorcycleMenu();                     menuItems.Add(button);        button = new MenuButton("Cycles", "View the selection of Cycle Bikes");        button.Activated += (sender, args) => this.OpenCycleMenu();                     menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.MainMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Weapon Shop", menuItems.ToArray()));    }    //BIKE LIST    void AircraftMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("Aircraft Shop", true) };        var button = new MenuButton("Helicopters", "View the selection of Helicopters");        button.Activated += (sender, args) => this.OpenHelicopterMenu();                   menuItems.Add(button);        button = new MenuButton("Planes", "View the selection of Planes");        button.Activated += (sender, args) => this.OpenPlaneMenu();                   menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.MainMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Aircraft Shop", menuItems.ToArray()));    }    //AIRCRAFT LIST    void BoatMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("Boat Shop", true) };        var button = new MenuButton("Yachts", "View the selection of Yachts");        button.Activated += (sender, args) => this.OpenYachtMenu();                    menuItems.Add(button);        button = new MenuButton("Boats", "View the selection of Boats");        button.Activated += (sender, args) => this.OpenBoatsMenu();        menuItems.Add(button);        button = new MenuButton("submarine", "View the selection of submarine");        button.Activated += (sender, args) => this.OpenSubmarineMenu();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.MainMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Aircraft Shop", menuItems.ToArray()));    }    //BOAT LIST    //WEAPON MENU    void OpenPistolMenu()    {        //Pistol Selection        var menuItems = new List<IMenuItem> { new MenuLabel("Pistol Selection", true) };        var button = new MenuButton("9mm", "$750"); //works        button.Activated += (sender, args) => this.ninemil();        menuItems.Add(button);        button = new MenuButton("Combat", "$1000"); //works        button.Activated += (sender, args) => this.Combat();        menuItems.Add(button);        button = new MenuButton("Automatic", "$1500"); //works        button.Activated += (sender, args) => this.Auto();        menuItems.Add(button);        button = new MenuButton("Deagle", "$1750");        button.Activated += (sender, args) => this.Deagle();        menuItems.Add(button);        button = new MenuButton("Stun", "$200"); // works        button.Activated += (sender, args) => this.Stun();        menuItems.Add(button);        button = new MenuButton("Heavy", "$1000");        button.Activated += (sender, args) => this.Heavy();        menuItems.Add(button);        button = new MenuButton("S N S", "$750");        button.Activated += (sender, args) => this.SNS();        menuItems.Add(button);                button = new MenuButton("Vintage", "$250"); //works        button.Activated += (sender, args) => this.Vintage();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.WeaponMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Pistol Selection", menuItems.ToArray()));    }    void OpenShotgunMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("Shotgun Selection", true) };        var button = new MenuButton("Pump", "$2500");        button.Activated += (sender, args) => this.Pump();        menuItems.Add(button);        button = new MenuButton("Sawn-Off", "$2000");        button.Activated += (sender, args) => this.SawnOff();        menuItems.Add(button);        button = new MenuButton("Assault", "$4500");        button.Activated += (sender, args) => this.Assault();        menuItems.Add(button);        button = new MenuButton("Bullpup", "$5000");        button.Activated += (sender, args) => this.Bullpup();        menuItems.Add(button);        button = new MenuButton("Heavy", "$7500");        button.Activated += (sender, args) => this.HeavyS();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.WeaponMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Shotgun Selection", menuItems.ToArray()));    }    void OpenSMGMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("SMG Selection", true) };        var button = new MenuButton("Mirco SMG", "$2500");        button.Activated += (sender, args) => this.Micro();        menuItems.Add(button);        button = new MenuButton("SMG", "$3500");        button.Activated += (sender, args) => this.MP5k();        menuItems.Add(button);        button = new MenuButton("Assault", "5000");        button.Activated += (sender, args) => this.AssaultSMG();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.WeaponMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("SMG Selection", menuItems.ToArray()));    }    void OpenARMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("Assault Rifle Selection", true) };        var button = new MenuButton("AK47", "$10000");        button.Activated += (sender, args) => this.AK47();        menuItems.Add(button);        button = new MenuButton("M4", "$12500");        button.Activated += (sender, args) => this.M4();        menuItems.Add(button);        button = new MenuButton("TAR-21", "$11500");        button.Activated += (sender, args) => this.TAR21();        menuItems.Add(button);        button = new MenuButton("Thompson", "$8000");        button.Activated += (sender, args) => this.Thompson();        menuItems.Add(button);        button = new MenuButton("G36C", "$15000");        button.Activated += (sender, args) => this.G36C();        menuItems.Add(button);        button = new MenuButton("Bullpup", "$14000");        button.Activated += (sender, args) => this.BullpupR();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.WeaponMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Assault Rifle Selection", menuItems.ToArray()));    }    void OpenSRMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("Sniper Rifle Selection", true) };        var button = new MenuButton("L96A1", "$20000");        button.Activated += (sender, args) => this.L96A1();        menuItems.Add(button);        button = new MenuButton("Heavy Sniper", "$23000");        button.Activated += (sender, args) => this.HeavySniper();        menuItems.Add(button);        button = new MenuButton("Musket", "$9000");        button.Activated += (sender, args) => this.Musket();        menuItems.Add(button);        button = new MenuButton("Marksman Rifle", "$17000");        button.Activated += (sender, args) => this.AutoSniper();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.WeaponMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Sniper Rifle Selection", menuItems.ToArray()));    }    void OpenEquipMenu()    {        var menuItems = new List<IMenuItem> { new MenuLabel("Equipment Selection", true) };        var button = new MenuButton("Tear Gas", "$150");        button.Activated += (sender, args) => this.Tear();        menuItems.Add(button);        button = new MenuButton("FireBomb", "$20");        button.Activated += (sender, args) => this.FireBomb();        menuItems.Add(button);        button = new MenuButton("Back", "Return to the main menu");        button.Activated += (sender, args) => this.WeaponMenu();        menuItems.Add(button);        this.View.AddMenu(new GTA.Menu("Equipment Selection", menuItems.ToArray()));    }    //PISTOL LIST //Prices complete    void ninemil()    {        if(Game.Player.Money >= 750)        {            current_player.Weapons.Give(WeaponHash.Pistol, 24, true, false);            Game.Player.Money -= 750;        }                else if(Game.Player.Money >= 750)        {            UI.ShowSubtitle("Insufficient Funds");        }           }    void Combat()    {        if (Game.Player.Money >= 1000)        {            current_player.Weapons.Give(WeaponHash.CombatPistol, 24, true, false);            Game.Player.Money -= 1000;        }        else if (Game.Player.Money >= 1000)        {            UI.ShowSubtitle("Insufficient Funds");        }             }        void Auto()    {        if (Game.Player.Money >= 1500)        {            current_player.Weapons.Give(WeaponHash.APPistol, 60, true, false);            Game.Player.Money -= 1500;        }        else if (Game.Player.Money >= 1500)        {            UI.ShowSubtitle("Insufficient Funds");        }               }    void Deagle()    {        if (Game.Player.Money >= 1750)        {            current_player.Weapons.Give(WeaponHash.Pistol50, 24, true, false);            Game.Player.Money -= 1750;        }        else if (Game.Player.Money >= 1750)        {            UI.ShowSubtitle("Insufficient Funds");        }               }    void Stun()    {        if (Game.Player.Money >= 200)        {            current_player.Weapons.Give(WeaponHash.StunGun, 1, true, false);            Game.Player.Money -= 200;        }        else if (Game.Player.Money >= 200)        {            UI.ShowSubtitle("Insufficient Funds");        }            }    void Heavy()    {        if (Game.Player.Money >= 1000)        {            current_player.Weapons.Give(WeaponHash.HeavyPistol, 60, true, false);            Game.Player.Money -= 1000;        }        else if (Game.Player.Money >= 1000)        {            UI.ShowSubtitle("Insufficient Funds");        }               }    void SNS()    {        if (Game.Player.Money >= 750)        {            current_player.Weapons.Give(WeaponHash.SNSPistol, 24, true, false);            Game.Player.Money -= 750;        }        else if (Game.Player.Money >= 750)        {            UI.ShowSubtitle("Insufficient Funds");        }           }        void Vintage()    {        if (Game.Player.Money >= 250)        {            current_player.Weapons.Give(WeaponHash.VintagePistol, 24, true, false);            Game.Player.Money -= 250;        }        else if (Game.Player.Money >= 250)        {            UI.ShowSubtitle("Insufficient Funds");        }          }    //SHOTGUN LIST //Prices complete    void Pump()    {        if (Game.Player.Money >= 2500)        {            current_player.Weapons.Give(WeaponHash.PumpShotgun, 30, true, false);            Game.Player.Money -= 2500;        }        else if (Game.Player.Money >= 2500)        {            UI.ShowSubtitle("Insufficient Funds");        }          }    void SawnOff()    {        if (Game.Player.Money >= 2000)        {            current_player.Weapons.Give(WeaponHash.SawnOffShotgun, 30, true, false);            Game.Player.Money -= 2000;        }        else if (Game.Player.Money >= 2000)        {            UI.ShowSubtitle("Insufficient Funds");        }            }    void Assault()    {        if (Game.Player.Money >= 4500)        {            current_player.Weapons.Give(WeaponHash.AssaultShotgun, 30, true, false);            Game.Player.Money -= 4500;        }        else if (Game.Player.Money >= 4500)        {            UI.ShowSubtitle("Insufficient Funds");        }        }    void Bullpup()    {        if (Game.Player.Money >= 5000)        {            current_player.Weapons.Give(WeaponHash.BullpupShotgun, 30, true, false);            Game.Player.Money -= 5000;        }        else if (Game.Player.Money >= 5000)        {            UI.ShowSubtitle("Insufficient Funds");        }            }    void HeavyS()    {        if (Game.Player.Money >= 7500)        {            current_player.Weapons.Give(WeaponHash.HeavyShotgun, 30, true, false);            Game.Player.Money -= 7500;        }        else if (Game.Player.Money >= 7500)        {            UI.ShowSubtitle("Insufficient Funds");        }           }    //SMG LIST //Prices complete    void Micro()    {        if (Game.Player.Money >= 2500)        {            current_player.Weapons.Give(WeaponHash.MicroSMG, 120, true, false);            Game.Player.Money -= 2500;        }        else if (Game.Player.Money >= 2500)        {            UI.ShowSubtitle("Insufficient Funds");        }      }    void MP5k()    {        if (Game.Player.Money >= 3500)        {            current_player.Weapons.Give(WeaponHash.SMG, 120, true, false);            Game.Player.Money -= 3500;        }        else if (Game.Player.Money >= 3500)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void AssaultSMG()    {        if (Game.Player.Money >= 5000)        {            current_player.Weapons.Give(WeaponHash.AssaultSMG, 120, true, false);            Game.Player.Money -= 5000;        }        else if (Game.Player.Money >= 5000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    //AR List //Prices complete    void AK47()    {        if (Game.Player.Money >= 10000)        {            current_player.Weapons.Give(WeaponHash.AssaultRifle, 60, true, false);            Game.Player.Money -= 10000;        }        else if (Game.Player.Money >= 10000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void M4()    {        if (Game.Player.Money >= 12500)        {            current_player.Weapons.Give(WeaponHash.CarbineRifle, 60, true, false);            Game.Player.Money -= 12500;        }        else if (Game.Player.Money >= 12500)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void TAR21()    {        if (Game.Player.Money >= 11500)        {            current_player.Weapons.Give(WeaponHash.AdvancedRifle, 60, true, false);            Game.Player.Money -= 11500;        }        else if (Game.Player.Money >= 11500)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void Thompson()    {        if (Game.Player.Money >= 8000)        {            current_player.Weapons.Give(WeaponHash.Gusenberg, 60, true, false);            Game.Player.Money -= 8000;        }        else if (Game.Player.Money >= 8000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void G36C()    {        if (Game.Player.Money >= 15000)        {            current_player.Weapons.Give(WeaponHash.SpecialCarbine, 60, true, false);            Game.Player.Money -= 15000;        }        else if (Game.Player.Money >= 15000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void BullpupR()    {        if (Game.Player.Money >= 14000)        {            current_player.Weapons.Give(WeaponHash.BullpupRifle, 60, true, false);            Game.Player.Money -= 14000;        }        else if (Game.Player.Money >= 14000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    //SR List //Prices complete    void L96A1()    {        if (Game.Player.Money >= 20000)        {            current_player.Weapons.Give(WeaponHash.SniperRifle, 40, true, false);            Game.Player.Money -= 20000;        }        else if (Game.Player.Money >= 20000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void HeavySniper()    {        if (Game.Player.Money >= 23000)        {            current_player.Weapons.Give(WeaponHash.HeavySniper, 40, true, false);            Game.Player.Money -= 23000;        }        else if (Game.Player.Money >= 23000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void Musket()    {        if (Game.Player.Money >= 9000)        {            current_player.Weapons.Give(WeaponHash.Musket, 30, true, false);            Game.Player.Money -= 9000;        }        else if (Game.Player.Money >= 9000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void AutoSniper()    {        if (Game.Player.Money >= 17000)        {            current_player.Weapons.Give(WeaponHash.MarksmanRifle, 80, true, false);            Game.Player.Money -= 17000;        }        else if (Game.Player.Money >= 17000)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    //Equipment List //Prices    void Tear()    {        if (Game.Player.Money >= 150)        {            current_player.Weapons.Give(WeaponHash.BZGas, 1, true, false);            Game.Player.Money -= 150;        }        else if (Game.Player.Money >= 150)        {            UI.ShowSubtitle("Insufficient Funds");        }    }    void FireBomb()    {        if (Game.Player.Money >= 20)        {            current_player.Weapons.Give(WeaponHash.Molotov, 1, true, false);            Game.Player.Money -= 20;        }        else if (Game.Player.Money >= 20)        {            UI.ShowSubtitle("Insufficient Funds");        }    }

Is anyone able to offer me some ways i can simplify complexities in my code? Unless this is the best it can be organized of course.

(I'd just like to prevent myself from being overwhelmed with code. :) )

Link to post
Share on other sites

Wow dude that's a whole lot of code... Read up on the Single Responsibility Principle, you'd benefit from having a few more classes but anyway, here's perhaps a couple small refactors that'll shorten your code.

 

Please excuse if I have any small syntax errors I'm just writing this out without looking at it in VS.

 

1. Give yourself a "create menu button" function

private IMenuItem CreateMenuItem(string name, string description, Action handler){  MenuButton result = new MenuButton(name, description);  result.Activated += (sender, args) => handler();  return result;}

2. You can then replace all your menu creations with say just:

void MainMenu(){  CloseMenu();  var menuItems = new List<IMenuItem> { new MenuLabel("Main Menu", true) };  menuItems.Add("Weapon Shop", "Enter the weapon shop!", this.WeaponMenu);  //... the rest of them  this.View.AddMenu(new GTA.Menu("Main Menu", menuItems.ToArray());}

3. You could ditch pretty much every copy of a weapon function and replace it with a more generic method

private void PurcahseWeapon(int weaponCost, WeaponHash weaponHash){  if(Game.Player.Money >= weaponCost){    //is 24 the amount of ammo? You could also take that as a third parameter    Game.Player.Weapons.Give(weaponHash, 24, true, false);    Game.Player.Money -= weaponCost;  }  else {    UI.ShowSubtitle("Insufficient Funds");  }}

4. Replace anything calling that with

menuItems.Add("Deagle", "$1750", () => { PurchaseWeapon(1750, WeaponHash.Pistol50);});

Hope this helps! You should be able to reduce 80% of your code :) and make it super easy to add new weapons to your mod as they come out with DLC. And again I apologize if there are any small syntax errors, I just wrote it out here.

Edited by amg-argh
Link to post
Share on other sites

Wow dude that's a whole lot of code... Read up on the Single Responsibility Principle, you'd benefit from having a few more classes but anyway, here's perhaps a couple small refactors that'll shorten your code.

 

Please excuse if I have any small syntax errors I'm just writing this out without looking at it in VS.

 

1. Give yourself a "create menu button" function

private IMenuItem CreateMenuItem(string name, string description, Action handler){  MenuButton result = new MenuButton(name, description);  result.Activated += (sender, args) => handler();  return result;}

2. You can then replace all your menu creations with say just:

void MainMenu(){  CloseMenu();  var menuItems = new List<IMenuItem> { new MenuLabel("Main Menu", true) };  menuItems.Add("Weapon Shop", "Enter the weapon shop!", this.WeaponMenu);  //... the rest of them  this.View.AddMenu(new GTA.Menu("Main Menu", menuItems.ToArray());}

3. You could ditch pretty much every copy of a weapon function and replace it with a more generic method

private void PurcahseWeapon(int weaponCost, WeaponHash weaponHash){  if(Game.Player.Money >= weaponCost){    //is 24 the amount of ammo? You could also take that as a third parameter    Game.Player.Weapons.Give(weaponHash, 24, true, false);    Game.Player.Money -= weaponCost;  }  else {    UI.ShowSubtitle("Insufficient Funds");  }}

4. Replace anything calling that with

menuItems.Add("Deagle", "$1750", () => { PurchaseWeapon(1750, WeaponHash.Pistol50);});

Hope this helps! You should be able to reduce 80% of your code :) and make it super easy to add new weapons to your mod as they come out with DLC. And again I apologize if there are any small syntax errors, I just wrote it out here.

 

 

Don't apologize! That's exactly what i'm looking for!

Thanks heaps! :D

Link to post
Share on other sites

If my junior developers were more like you and asked how to simplify their code more often, I would be so happy.

  • Like 1
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.