Facebook
From 01Kiko, 1 Month ago, written in C.
Embed
Download Paste or View Raw
Hits: 157
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <functional>
  5.  
  6. using namespace std;
  7.  
  8. // Dummy Game namespace
  9. namespace Game
  10. {
  11.     struct Player
  12.     {
  13.         int WantedLevel = 0;
  14.         int Money = 0;
  15.  
  16.         bool IsInAnyVehicle() { return true; }
  17.     };
  18.  
  19.     struct Input
  20.     {
  21.         string GetInput() { return ""; }
  22.     };
  23.  
  24.     void ConsoleOutput(string message) { cout << message << endl; }
  25. }
  26.  
  27. int main()
  28. {
  29.     // Set up the admin commands
  30.     map<string, function<void()>> commands =
  31.     {
  32.         { "setrank", [] {
  33.             // Set the player's rank
  34.             if (Game::Player.IsInAnyVehicle())
  35.             {
  36.                 int rank = 0;
  37.  
  38.                 // Parse rank from input
  39.                 if (cin >> rank)
  40.                 {
  41.                     Game::Player.WantedLevel = rank;
  42.                     Game::ConsoleOutput("Rank set to " + to_string(rank) + ".");
  43.                 }
  44.                 else
  45.                 {
  46.                     Game::ConsoleOutput("Invalid rank value.");
  47.                 }
  48.  
  49.                 // Clear input buffer
  50.                 cin.clear();
  51.                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
  52.             }
  53.         }},
  54.         { "givemoney", [] {
  55.             // Give the player money
  56.             if (Game::Player.IsInAnyVehicle())
  57.             {
  58.                 int amount = 0;
  59.  
  60.                 // Parse amount from input
  61.                 if (cin >> amount)
  62.                 {
  63.                     Game::Player.Money = amount;
  64.                     Game::ConsoleOutput("Money set to " + to_string(amount) + ".");
  65.                 }
  66.                 else
  67.                 {
  68.                     Game::ConsoleOutput("Invalid money value.");
  69.                 }
  70.  
  71.                 // Clear input buffer
  72.                 cin.clear();
  73.                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
  74.             }
  75.         }},
  76.     };
  77.  
  78.     // Loop forever
  79.     while (true)
  80.     {
  81.         // Get the user's input
  82.         string input = "";
  83.         cout << "> ";
  84.         getline(cin, input);
  85.  
  86.         // Check if the input is an admin command
  87.         if (commands.count(input) > 0)
  88.         {
  89.             // Execute the command
  90.             commands[input]();
  91.         }
  92.     }
  93. }