Advertisement
NewbProgramming

Fake GMX restart

Apr 10th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.22 KB | None | 0 0
  1. // ----- DEFINES -----
  2.  
  3. #define FILTERSCRIPT
  4. #define DEBUG
  5.  
  6. // ----- INCLUDES -----
  7.  
  8. #include <a_samp>
  9.  
  10. // ----- GLOBAL VARIABLES -----
  11.  
  12. new IsRestarting = 0;
  13.  
  14. // ----- FUNCTIONS -----
  15.  
  16. SendMessage(message[])
  17. {
  18. #if defined DEBUG
  19.     print(message);
  20. #endif
  21.     return 1;
  22. }
  23.  
  24. // ----- CALLBACKS -----
  25.  
  26. #if defined FILTERSCRIPT
  27.  
  28. public OnFilterScriptInit()
  29. {
  30.     SendMessage("RESTART: OnFilterScriptInit");
  31.    
  32.     // Tell the script we are currently restarting.
  33.     IsRestarting = 1;
  34.    
  35.     // We're simulating what happens during /rcon gmx
  36.     new pVarCount = 0;
  37.     new pVarName[128];
  38.    
  39.     for(new playerid = 0, count = GetPlayerPoolSize(); playerid <= count; playerid++)
  40.     {
  41.         if(IsPlayerConnected(playerid) == 0) continue;
  42.  
  43.         // Tell them the server is restarting.
  44.         SendClientMessage(playerid, -1, "The server is restarting..");
  45.        
  46.         // De-spawn them from the world.
  47.         // When they respawn we want them in class selection.
  48.         ForceClassSelection(playerid);
  49.         // Hide the controls for now.
  50.         TogglePlayerSpectating(playerid, true);
  51.        
  52.         // Set their camera position.
  53.         // /save -- 1133.0504,-2038.4034,69.1000,270.0
  54.         SetPlayerCameraPos(playerid, 1133.0504, -2038.4034, 69.1000);
  55.        
  56.         // Reset the player variables.
  57.         pVarCount = GetPVarsUpperIndex(playerid);
  58.  
  59.         for(new i = 0; i <= pVarCount; i++)
  60.         {
  61.             strdel(pVarName, 0, strlen(pVarName));
  62.             GetPVarNameAtIndex(playerid, i, pVarName, 128);
  63.            
  64.             if(GetPVarType(playerid, pVarName) != PLAYER_VARTYPE_NONE)
  65.             {
  66.                 DeletePVar(playerid, pVarName);
  67.             }
  68.         }
  69.        
  70.         // Console output
  71.         SendMessage("RESTART: FAKE OnPlayerDisconnect");
  72.     }
  73.    
  74.     SetTimer("UnloadFilterScript", 1000, false);
  75.     return 1;
  76. }
  77.  
  78. forward UnloadFilterScript();
  79. public UnloadFilterScript()
  80. {
  81.     // This will crash the server, you'll have to manually unloadfs =[
  82.     // SendRconCommand("unloadfs restart");
  83.     return 1;
  84. }
  85.  
  86. public OnFilterScriptExit()
  87. {
  88.     SendMessage("RESTART: OnFilterScriptExit");
  89.  
  90.     // Tell the script we're no longer restarting.
  91.     IsRestarting = 0;
  92.    
  93.     // Get server information for connecting message.
  94.     new serverPort = GetConsoleVarAsInt("port");
  95.     new hostname[64];
  96.     new message1[144];
  97.     new message3[144];
  98.    
  99.     GetConsoleVarAsString("hostname", hostname, 64);
  100.     format(message1, 144, "Connecting to :%i...", serverPort);
  101.     format(message3, 144, "Connected to %s", hostname);
  102.    
  103.     // We're simulating OnPlayerConnect
  104.     for(new playerid = 0, count = GetPlayerPoolSize(); playerid <= count; playerid++)
  105.     {
  106.         if(IsPlayerConnected(playerid) == 0) continue;
  107.  
  108.         // Tell them they're "connected" to the server.
  109.         SendClientMessage(playerid, -1, message1);
  110.         SendClientMessage(playerid, -1, "Connected. Joining game...");
  111.         SendClientMessage(playerid, -1, message3);
  112.        
  113.         // Set the camera position to the class selection camera position.
  114.         // /save -- 50.0000,50.0000,70.0000,270.0000
  115.         SetPlayerCameraPos(playerid, 50.0000, 50.0000, 70.0000);
  116.        
  117.         // Show the controls for the player.
  118.         TogglePlayerSpectating(playerid, false);
  119.        
  120.         // Console output
  121.         SendMessage("RESTART: FAKE OnPlayerConnect");
  122.     }
  123.     return 1;
  124. }
  125.  
  126. #else
  127.  
  128. main() {}
  129.  
  130. #endif
  131.  
  132. public OnPlayerUpdate(playerid)
  133. {
  134.     return (IsRestarting == 0) ? 1 : 0;
  135. }
  136.  
  137. // ----- END OF CALLBACKS -----
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement