Advertisement
Y_Less

gmxfix

Apr 23rd, 2011
1,629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.85 KB | None | 0 0
  1. /*----------------------------------------------------------------------------*\
  2.                     =====================================
  3.                      gmxfix - Consistent callback orders
  4.                     =====================================
  5. Description:
  6.     Provides six new RCON commands to end modes with OnGameModeExit and
  7.     OnPlayerDisconnect called in consistent orders:
  8.    
  9.     gmx1
  10.     exit1
  11.     changemode1
  12.    
  13.     All have OnGameModeExit called first.
  14.    
  15.     gmx2
  16.     exit2
  17.     changemode2
  18.    
  19.     All have OnGameModeExit called second.
  20.    
  21.     Note that ALL scripts must include this if you want it to work.
  22.    
  23.     The new disconnect reasons are:
  24.    
  25.     101 - gmx called
  26.     102 - exit called
  27.     103 - changemode called
  28.    
  29.     If you want to treat them all the same then fair enough.
  30. Legal:
  31.     Version: MPL 1.1
  32.    
  33.     The contents of this file are subject to the Mozilla Public License Version
  34.     1.1 (the "License"); you may not use this file except in compliance with
  35.     the License. You may obtain a copy of the License at
  36.     http://www.mozilla.org/MPL/
  37.    
  38.     Software distributed under the License is distributed on an "AS IS" basis,
  39.     WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  40.     for the specific language governing rights and limitations under the
  41.     License.
  42.    
  43.     The Original Code is the SA:MP gmxfix script
  44.    
  45.     The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  46.     Portions created by the Initial Developer are Copyright (C) 2008
  47.     the Initial Developer. All Rights Reserved.
  48.    
  49.     Very special thanks to:
  50.         Thiadmer - PAWN.
  51.         Kye/Kalcor - SA:MP.
  52.         SA:MP Team past, present and future - SA:MP.
  53. Version:
  54.     1.0
  55. Changelog:
  56.     24/04/11:
  57.         First version
  58. \*----------------------------------------------------------------------------*/
  59.  
  60. // These two are mutually exclusive.
  61. //#tryinclude <YSI\y_amx>
  62. //#tryinclude <YSI\y_scripting>
  63.  
  64. //#if defined _inc_y_amx
  65.  
  66.  
  67. //#elseif defined _inc_y_scripting
  68.  
  69. // No YSI, do this the slow way.  Technically you could copy all the relevant
  70. // code from the YSI scripting libraries, but then what's the point of making
  71. // and releasing powerful libraries?
  72. static
  73.     YSI_g_sDisableCalls = 0,
  74.     YSI_g_sCallbackFlags = 0;
  75.  
  76. #if defined _ALS_OnGameModeExit || defined _ALS_OnPlayerDisconnect || defined _ALS_OnRconCommand || defined _ALS_OnGameModeInit || defined _inc_a_samp
  77.     #error gmxfix.inc must be your FIRST include!
  78. #endif
  79.  
  80. #include <a_samp>
  81. //#include <foreach>
  82.  
  83. public OnGameModeExit()
  84. {
  85.     //printf("ogme called");
  86.     if (YSI_g_sDisableCalls & 1)
  87.     {
  88.         return 0;
  89.     }
  90.     else
  91.     {
  92.         return CallLocalFunction("gmxfix_OnGameModeExit", "");
  93.     }
  94. }
  95.  
  96. #define OnGameModeExit gmxfix_OnGameModeExit
  97. #define _ALS_OnGameModeExit
  98.  
  99. forward OnGameModeExit();
  100.  
  101. public OnGameModeInit()
  102. {
  103.     YSI_g_sCallbackFlags |= (funcidx("gmxfix_OnPlayerDisconnect") == -1) ? 0 : 1;
  104.     YSI_g_sCallbackFlags |= (funcidx("gmxfix_OnRconCommand") == -1) ? 0 : 2;
  105.     return CallLocalFunction("gmxfix_OnGameModeInit", "");
  106. }
  107.  
  108. #define OnGameModeInit gmxfix_OnGameModeInit
  109. #define _ALS_OnGameModeInit
  110.  
  111. forward OnGameModeInit();
  112.  
  113. public OnPlayerDisconnect(playerid, reason)
  114. {
  115.     //printf("opdc called");
  116.     if (YSI_g_sDisableCalls & 2)
  117.     {
  118.         return 0;
  119.     }
  120.     else if (YSI_g_sCallbackFlags & 1)
  121.     {
  122.         return CallLocalFunction("gmxfix_OnPlayerDisconnect", "ii", playerid, reason);
  123.     }
  124.     else
  125.     {
  126.         return 1;
  127.     }
  128. }
  129.  
  130. #define OnPlayerDisconnect gmxfix_OnPlayerDisconnect
  131. #define _ALS_OnPlayerDisconnect
  132.  
  133. forward OnPlayerDisconnect(playerid, reason);
  134.  
  135. public OnRconCommand(cmd[])
  136. {
  137.     if (!strcmp(cmd, "gmx1"))
  138.     {
  139.         //printf("OGME");
  140.         CallRemoteFunction("OnGameModeExit", "");
  141.         //printf("OPDC");
  142.         for (new playerid = 0; playerid != MAX_PLAYERS; ++playerid) if (IsPlayerConnected(playerid))
  143.         {
  144.             // Special leave reason.
  145.             CallRemoteFunction("OnPlayerDisconnect", "ii", playerid, 101);
  146.         }
  147.         CallRemoteFunction("gmxfix_BlockAll", "");
  148.         GameModeExit();
  149.         CallRemoteFunction("gmxfix_UnblockAll", "");
  150.         return 1;
  151.     }
  152.     else if (!strcmp(cmd, "gmx2"))
  153.     {
  154.         //printf("OPDC");
  155.         for (new playerid = 0; playerid != MAX_PLAYERS; ++playerid) if (IsPlayerConnected(playerid))
  156.         //foreach (Players, playerid)
  157.         {
  158.             // Special leave reason.
  159.             CallRemoteFunction("OnPlayerDisconnect", "ii", playerid, 101);
  160.         }
  161.         //printf("OGME");
  162.         CallRemoteFunction("OnGameModeExit", "");
  163.         CallRemoteFunction("gmxfix_BlockAll", "");
  164.         GameModeExit();
  165.         CallRemoteFunction("gmxfix_UnblockAll", "");
  166.         return 1;
  167.     }
  168.     else if (!strcmp(cmd, "exit1"))
  169.     {
  170.         //printf("OGME");
  171.         CallRemoteFunction("OnGameModeExit", "");
  172.         //printf("OPDC");
  173.         for (new playerid = 0; playerid != MAX_PLAYERS; ++playerid) if (IsPlayerConnected(playerid))
  174.         {
  175.             // Special leave reason.
  176.             CallRemoteFunction("OnPlayerDisconnect", "ii", playerid, 102);
  177.         }
  178.         CallRemoteFunction("gmxfix_BlockAll", "");
  179.         //CallRemoteFunction("gmxfix_BlockAll", "");
  180.         SendRconCommand("exit");
  181.         CallRemoteFunction("gmxfix_UnblockAll", "");
  182.         return 1;
  183.     }
  184.     else if (!strcmp(cmd, "exit2"))
  185.     {
  186.         //printf("OPDC");
  187.         for (new playerid = 0; playerid != MAX_PLAYERS; ++playerid) if (IsPlayerConnected(playerid))
  188.         //foreach (Players, playerid)
  189.         {
  190.             // Special leave reason.
  191.             CallRemoteFunction("OnPlayerDisconnect", "ii", playerid, 102);
  192.         }
  193.         //printf("OGME");
  194.         CallRemoteFunction("OnGameModeExit", "");
  195.         CallRemoteFunction("gmxfix_BlockAll", "");
  196.         SendRconCommand("exit");
  197.         CallRemoteFunction("gmxfix_UnblockAll", "");
  198.         return 1;
  199.     }
  200.     else if (!strcmp(cmd, "changemode1 ", false, 12))
  201.     {
  202.         //printf("OGME");
  203.         CallRemoteFunction("OnGameModeExit", "");
  204.         //printf("OPDC");
  205.         for (new playerid = 0; playerid != MAX_PLAYERS; ++playerid) if (IsPlayerConnected(playerid))
  206.         {
  207.             // Special leave reason.
  208.             CallRemoteFunction("OnPlayerDisconnect", "ii", playerid, 103);
  209.         }
  210.         CallRemoteFunction("gmxfix_BlockAll", "");
  211.         format(cmd, strlen(cmd), "changemode %s", cmd[12]);
  212.         SendRconCommand(cmd);
  213.         CallRemoteFunction("gmxfix_UnblockAll", "");
  214.         return 1;
  215.     }
  216.     else if (!strcmp(cmd, "changemode2 ", false, 12))
  217.     {
  218.         //printf("OPDC");
  219.         for (new playerid = 0; playerid != MAX_PLAYERS; ++playerid) if (IsPlayerConnected(playerid))
  220.         //foreach (Players, playerid)
  221.         {
  222.             // Special leave reason.
  223.             CallRemoteFunction("OnPlayerDisconnect", "ii", playerid, 103);
  224.         }
  225.         //printf("OGME");
  226.         CallRemoteFunction("OnGameModeExit", "");
  227.         CallRemoteFunction("gmxfix_BlockAll", "");
  228.         format(cmd, strlen(cmd), "changemode %s", cmd[12]);
  229.         SendRconCommand(cmd);
  230.         CallRemoteFunction("gmxfix_UnblockAll", "");
  231.         return 1;
  232.     }
  233.     else if (YSI_g_sCallbackFlags & 2)
  234.     {
  235.         return CallLocalFunction("gmxfix_OnRconCommand", "s", cmd);
  236.     }
  237.     else
  238.     {
  239.         return 0;
  240.     }
  241. }
  242.  
  243. #define OnRconCommand gmxfix_OnRconCommand
  244. #define _ALS_OnRconCommand
  245.  
  246. forward OnRconCommand(cmd[]);
  247.  
  248. forward gmxfix_BlockAll();
  249.  
  250. public gmxfix_BlockAll()
  251. {
  252.     YSI_g_sDisableCalls = 3;
  253. }
  254.  
  255. forward gmxfix_UnblockAll();
  256.  
  257. public gmxfix_UnblockAll()
  258. {
  259.     YSI_g_sDisableCalls = 0;
  260. }
  261.  
  262. //#endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement