Advertisement
xNos

Untitled

Apr 2nd, 2013
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 27.83 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5. #include <cstrike>
  6. #include <adminmenu>
  7. #include <smlib/arrays>
  8. #include <timer>
  9. #include <timer-logging>
  10.  
  11. #undef REQUIRE_PLUGIN
  12. #include <timer-physics>
  13. #include <timer-worldrecord>
  14. #include <updater>
  15.  
  16. #define UPDATE_URL "http://dl.dropbox.com/u/16304603/timer/updateinfo-timer-mapzones.txt"
  17.  
  18. /**
  19. * Global Enums
  20. */
  21. enum MapZoneEditor
  22. {
  23.     Step,
  24.     Float:Point1[3],
  25.     Float:Point2[3]
  26. }
  27.  
  28. /**
  29. * Global Variables
  30. */
  31. new Handle:g_hSQL;
  32.  
  33. new Handle:g_hCvarStartMapZoneColor = INVALID_HANDLE;
  34. new Handle:g_hCvarEndMapZoneColor = INVALID_HANDLE;
  35. new Handle:g_hCvarStopPrespeed = INVALID_HANDLE;
  36. new Handle:g_hCvarDrawMapZones = INVALID_HANDLE;
  37.  
  38. new g_startColor[4] = {0, 255, 0, 255};
  39. new g_endColor[4] = {0, 0, 255, 255};
  40. new bool:g_bStopPrespeed = false;
  41. new bool:g_bDrawMapZones = true;
  42.  
  43. new String:g_sCurrentMap[MAX_MAPNAME_LENGTH];
  44. new g_iReconnectCounter = 0;
  45.  
  46. new g_mapZones[64][MapZone];
  47. new g_mapZonesCount = 0;
  48.  
  49. new Handle:hTopMenu = INVALID_HANDLE;
  50. new TopMenuObject:oMapZoneMenu;
  51.  
  52. new g_mapZoneEditors[MAXPLAYERS+1][MapZoneEditor];
  53.  
  54. new g_precacheLaser;
  55.  
  56. new bool:g_bTimerPhysics = false;
  57. new bool:g_bTimerWorldRecord = false;
  58.  
  59. new Float:checkpoint[MAXPLAYERS+1][3];
  60. new tele[MAXPLAYERS+1];
  61. new save[MAXPLAYERS+1];
  62. new Handle:sm_maxsave = INVALID_HANDLE;
  63. new maxsave = 0;
  64. new Handle:sm_maxtele = INVALID_HANDLE;
  65. new maxtele = 0;
  66.  
  67. public Plugin:myinfo =
  68. {
  69.     name        = "[Timer] MapZones",
  70.     author      = "alongub | Glite",
  71.     description = "Map Zones component for [Timer]",
  72.     version     = PL_VERSION,
  73.     url         = "https://github.com/alongubkin/timer"
  74. };
  75.  
  76. public OnPluginStart()
  77. {
  78.     ConnectSQL();
  79.    
  80.     g_bTimerPhysics = LibraryExists("timer-physics");
  81.     g_bTimerWorldRecord = LibraryExists("timer-worldrecord");  
  82.     LoadTranslations("timer.phrases");
  83.  
  84.     g_hCvarStartMapZoneColor = CreateConVar("timer_startcolor", "0 255 0 255", "The color of the start map zone.");
  85.     g_hCvarEndMapZoneColor = CreateConVar("timer_endcolor", "0 0 255 255", "The color of the end map zone.");
  86.     g_hCvarStopPrespeed = CreateConVar("timer_stopprespeeding", "0", "If enabled players won't be able to prespeed in start zone.");
  87.     g_hCvarDrawMapZones = CreateConVar("timer_drawzones", "1", "If enabled map zones will be drawn.");
  88.    
  89.     HookConVarChange(g_hCvarStartMapZoneColor, Action_OnSettingsChange);
  90.     HookConVarChange(g_hCvarEndMapZoneColor, Action_OnSettingsChange)
  91.     HookConVarChange(g_hCvarStopPrespeed, Action_OnSettingsChange);
  92.     HookConVarChange(g_hCvarDrawMapZones, Action_OnSettingsChange);
  93.    
  94.     AutoExecConfig(true, "timer-mapzones");
  95.    
  96.     g_bStopPrespeed = GetConVarBool(g_hCvarStopPrespeed);
  97.     g_bDrawMapZones = GetConVarBool(g_hCvarDrawMapZones);
  98.    
  99.     LoadTranslations("checkpoints.phrases.txt");
  100.     RegConsoleCmd("sm_save", cmd_save);
  101.     RegConsoleCmd("sm_tele", cmd_tele);
  102.     RegConsoleCmd("sm_clean", cmd_clean);
  103.     sm_maxsave = CreateConVar("sm_maxsave", "1", "The maximum number of stored");
  104.     maxsave = GetConVarInt(sm_maxsave);
  105.     HookConVarChange(sm_maxsave, Setting);
  106.     sm_maxtele = CreateConVar("sm_maxtele", "1", "The maximum number of teleportation");
  107.     maxtele = GetConVarInt(sm_maxtele);
  108.     HookConVarChange(sm_maxtele, Setting);
  109.     HookEvent("player_spawn", OnPlayer_Spawn);
  110.        
  111.     new Handle:topmenu;
  112.     if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
  113.     {
  114.         OnAdminMenuReady(topmenu);
  115.     }
  116.    
  117.     if (LibraryExists("updater"))
  118.     {
  119.         Updater_AddPlugin(UPDATE_URL);
  120.     }
  121. }
  122.  
  123. public OnMapStart()
  124. {
  125.     GetCurrentMap(g_sCurrentMap, sizeof(g_sCurrentMap));
  126.     StringToLower(g_sCurrentMap);
  127.    
  128.     g_precacheLaser = PrecacheModel("materials/sprites/laserbeam.vmt");
  129.    
  130.     LoadMapZones();
  131. }
  132.  
  133. public OnLibraryAdded(const String:name[])
  134. {
  135.     if (StrEqual(name, "timer-physics"))
  136.     {
  137.         g_bTimerPhysics = true;
  138.     }
  139.     else if (StrEqual(name, "timer-worldrecord"))
  140.     {
  141.         g_bTimerWorldRecord = true;
  142.     }
  143.     else if (StrEqual(name, "updater"))
  144.     {
  145.         Updater_AddPlugin(UPDATE_URL);
  146.     }  
  147. }
  148.  
  149. public OnLibraryRemoved(const String:name[])
  150. {
  151.     if (StrEqual(name, "adminmenu"))
  152.     {
  153.         hTopMenu = INVALID_HANDLE;
  154.     }
  155.     else if (StrEqual(name, "timer-physics"))
  156.     {
  157.         g_bTimerPhysics = false;
  158.     }
  159.     else if (StrEqual(name, "timer-worldrecord"))
  160.     {
  161.         g_bTimerWorldRecord = false;
  162.     }
  163. }
  164.  
  165. public Action_OnSettingsChange(Handle:cvar, const String:oldvalue[], const String:newvalue[])
  166. {
  167.     if (cvar == g_hCvarStartMapZoneColor)
  168.     {
  169.         ParseColor(newvalue, g_startColor);
  170.     }
  171.     else if (cvar == g_hCvarEndMapZoneColor)
  172.     {
  173.         ParseColor(newvalue, g_endColor);
  174.     }
  175.     else if (cvar == g_hCvarStopPrespeed)
  176.     {
  177.         g_bStopPrespeed = bool:StringToInt(newvalue);
  178.     }
  179.     else if (cvar == g_hCvarDrawMapZones)
  180.     {
  181.         g_bDrawMapZones = bool:StringToInt(newvalue);
  182.        
  183.         if (g_bDrawMapZones)
  184.         {
  185.             CreateTimer(2.0, DrawZones, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  186.         }
  187.     }
  188. }
  189.  
  190. public OnAdminMenuReady(Handle:topmenu)
  191. {
  192.     // Block this from being called twice
  193.     if (topmenu == hTopMenu)
  194.     {
  195.         return;
  196.     }
  197.  
  198.     // Save the Handle
  199.     hTopMenu = topmenu;
  200.    
  201.     if ((oMapZoneMenu = FindTopMenuCategory(topmenu, "Timer Management")) == INVALID_TOPMENUOBJECT)
  202.     {
  203.         oMapZoneMenu = AddToTopMenu(hTopMenu,
  204.         "Timer Management",
  205.         TopMenuObject_Category,
  206.         AdminMenu_CategoryHandler,
  207.         INVALID_TOPMENUOBJECT);
  208.     }
  209.  
  210.     AddToTopMenu(hTopMenu,
  211.     "timer_mapzones_add",
  212.     TopMenuObject_Item,
  213.     AdminMenu_AddMapZone,
  214.     oMapZoneMenu,
  215.     "timer_mapzones_add",
  216.     ADMFLAG_RCON);
  217.  
  218.     AddToTopMenu(hTopMenu,
  219.     "timer_mapzones_remove",
  220.     TopMenuObject_Item,
  221.     AdminMenu_RemoveMapZone,
  222.     oMapZoneMenu,
  223.     "timer_mapzones_remove",
  224.     ADMFLAG_RCON);
  225.  
  226.     AddToTopMenu(hTopMenu,
  227.     "timer_mapzones_remove_all",
  228.     TopMenuObject_Item,
  229.     AdminMenu_RemoveAllMapZones,
  230.     oMapZoneMenu,
  231.     "timer_mapzones_remove_all",
  232.     ADMFLAG_RCON);
  233.  
  234. }
  235.  
  236. AddMapZone(String:map[], MapZoneType:type, Float:point1[3], Float:point2[3])
  237. {
  238.     decl String:sQuery[512];
  239.    
  240.     if (type == Start || type == End)
  241.     {
  242.         decl String:sDeleteQuery[128];
  243.         FormatEx(sDeleteQuery, sizeof(sDeleteQuery), "DELETE FROM mapzone WHERE map = '%s' AND type = %d;", map, type);
  244.  
  245.         SQL_TQuery(g_hSQL, AddMapZoneCallback, sDeleteQuery, _, DBPrio_High);  
  246.     }
  247.  
  248.     FormatEx(sQuery, sizeof(sQuery), "INSERT INTO mapzone (map, type, point1_x, point1_y, point1_z, point2_x, point2_y, point2_z) VALUES ('%s', '%d', %f, %f, %f, %f, %f, %f);", map, type, point1[0], point1[1], point1[2], point2[0], point2[1], point2[2]);
  249.  
  250.     SQL_TQuery(g_hSQL, AddMapZoneCallback, sQuery, _, DBPrio_Normal);  
  251. }
  252.  
  253. public AddMapZoneCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
  254. {
  255.     if (hndl == INVALID_HANDLE)
  256.     {
  257.         Timer_LogError("SQL Error on AddMapZone: %s", error);
  258.         return;
  259.     }
  260.    
  261.     LoadMapZones();
  262. }
  263.  
  264. LoadMapZones()
  265. {
  266.     if (g_hSQL == INVALID_HANDLE)
  267.     {
  268.         ConnectSQL();
  269.     }
  270.     else
  271.     {  
  272.         decl String:sQuery[384];
  273.         FormatEx(sQuery, sizeof(sQuery), "SELECT id, type, point1_x, point1_y, point1_z, point2_x, point2_y, point2_z FROM mapzone WHERE map = '%s'", g_sCurrentMap);
  274.  
  275.         SQL_TQuery(g_hSQL, LoadMapZonesCallback, sQuery, _, DBPrio_High);
  276.     }
  277. }
  278.  
  279. public LoadMapZonesCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
  280. {
  281.     if (hndl == INVALID_HANDLE)
  282.     {
  283.         Timer_LogError("SQL Error on LoadMapZones: %s", error);
  284.         return;
  285.     }
  286.  
  287.     g_mapZonesCount = 0;
  288.  
  289.     while (SQL_FetchRow(hndl))
  290.     {
  291.         strcopy(g_mapZones[g_mapZonesCount][Map], MAX_MAPNAME_LENGTH, g_sCurrentMap);
  292.        
  293.         g_mapZones[g_mapZonesCount][Id] = SQL_FetchInt(hndl, 0);
  294.         g_mapZones[g_mapZonesCount][Type] = MapZoneType:SQL_FetchInt(hndl, 1);
  295.        
  296.         g_mapZones[g_mapZonesCount][Point1][0] = SQL_FetchFloat(hndl, 2);
  297.         g_mapZones[g_mapZonesCount][Point1][1] = SQL_FetchFloat(hndl, 3);
  298.         g_mapZones[g_mapZonesCount][Point1][2] = SQL_FetchFloat(hndl, 4);
  299.        
  300.         g_mapZones[g_mapZonesCount][Point2][0] = SQL_FetchFloat(hndl, 5);
  301.         g_mapZones[g_mapZonesCount][Point2][1] = SQL_FetchFloat(hndl, 6);
  302.         g_mapZones[g_mapZonesCount][Point2][2] = SQL_FetchFloat(hndl, 7);
  303.        
  304.         g_mapZonesCount++;
  305.     }
  306.    
  307.     if (g_bDrawMapZones)
  308.     {
  309.         CreateTimer(2.0, DrawZones, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  310.     }
  311.    
  312.     CreateTimer(0.1, PlayerTracker, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  313. }
  314.  
  315. public OnTimerRestart(client)
  316. {
  317.     for (new mapZone = 0; mapZone < g_mapZonesCount; mapZone++)
  318.     {
  319.         if (g_mapZones[mapZone][Type] == Start)
  320.         {      
  321.             new Float:vCenter[3];
  322.             vCenter[0] = (g_mapZones[mapZone][Point1][0] + g_mapZones[mapZone][Point2][0]) / 2.0;
  323.             vCenter[1] = (g_mapZones[mapZone][Point1][1] + g_mapZones[mapZone][Point2][1]) / 2.0;
  324.             vCenter[2] = ((g_mapZones[mapZone][Point1][2] + g_mapZones[mapZone][Point2][2]) / 2.0) - 40.0;
  325.            
  326.             TeleportEntity(client, vCenter, Float:{0.0, 0.0, 0.0}, Float:{0.0, 0.0, 0.0});
  327.  
  328.             break;
  329.         }
  330.     }
  331. }
  332.  
  333. ConnectSQL()
  334. {
  335.     if (g_hSQL != INVALID_HANDLE)
  336.     {
  337.         CloseHandle(g_hSQL);
  338.     }
  339.  
  340.     g_hSQL = INVALID_HANDLE;
  341.  
  342.     if (SQL_CheckConfig("timer"))
  343.     {
  344.         SQL_TConnect(ConnectSQLCallback, "timer");
  345.     }
  346.     else
  347.     {
  348.         SetFailState("PLUGIN STOPPED - Reason: no config entry found for 'timer' in databases.cfg - PLUGIN STOPPED");
  349.     }
  350. }
  351.  
  352. public ConnectSQLCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
  353. {
  354.     if (g_iReconnectCounter >= 5)
  355.     {
  356.         Timer_LogError("PLUGIN STOPPED - Reason: reconnect counter reached max - PLUGIN STOPPED");
  357.         return;
  358.     }
  359.  
  360.     if (hndl == INVALID_HANDLE)
  361.     {
  362.         Timer_LogError("Connection to SQL database has failed, Reason: %s", error);
  363.        
  364.         g_iReconnectCounter++;
  365.         ConnectSQL();
  366.        
  367.         return;
  368.     }
  369.  
  370.     decl String:sDriver[16];
  371.     SQL_GetDriverIdent(owner, sDriver, sizeof(sDriver));
  372.  
  373.     g_hSQL = CloneHandle(hndl);
  374.    
  375.     if (StrEqual(sDriver, "mysql", false))
  376.     {
  377.         SQL_TQuery(g_hSQL, SetNamesCallback, "SET NAMES  'utf8'", _, DBPrio_High);
  378.         SQL_TQuery(g_hSQL, CreateSQLTableCallback, "CREATE TABLE IF NOT EXISTS `mapzone` (`id` int(11) NOT NULL AUTO_INCREMENT, `type` int(11) NOT NULL, `point1_x` float NOT NULL, `point1_y` float NOT NULL, `point1_z` float NOT NULL, `point2_x` float NOT NULL, `point2_y` float NOT NULL, `point2_z` float NOT NULL, `map` varchar(32) NOT NULL, PRIMARY KEY (`id`));");
  379.     }
  380.     else if (StrEqual(sDriver, "sqlite", false))
  381.     {
  382.         SQL_TQuery(g_hSQL, CreateSQLTableCallback, "CREATE TABLE IF NOT EXISTS `mapzone` (`id` INTEGER PRIMARY KEY, `type` INTEGER NOT NULL, `point1_x` float NOT NULL, `point1_y` float NOT NULL, `point1_z` float NOT NULL, `point2_x` float NOT NULL, `point2_y` float NOT NULL, `point2_z` float NOT NULL, `map` varchar(32) NOT NULL);");
  383.     }
  384.    
  385.     g_iReconnectCounter = 1;
  386. }
  387.  
  388. public SetNamesCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
  389. {
  390.     if (hndl == INVALID_HANDLE)
  391.     {
  392.         Timer_LogError("SQL Error on SetNames: %s", error);
  393.         return;
  394.     }
  395. }
  396.  
  397. public CreateSQLTableCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
  398. {
  399.     if (owner == INVALID_HANDLE)
  400.     {
  401.         Timer_LogError(error);
  402.  
  403.         g_iReconnectCounter++;
  404.         ConnectSQL();
  405.        
  406.         return;
  407.     }
  408.    
  409.     if (hndl == INVALID_HANDLE)
  410.     {
  411.         Timer_LogError("SQL Error on CreateSQLTable: %s", error);
  412.         return;
  413.     }
  414.    
  415.     LoadMapZones();
  416. }
  417.  
  418. public AdminMenu_CategoryHandler(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  419. {
  420.     if (action == TopMenuAction_DisplayTitle)
  421.     {
  422.         FormatEx(buffer, maxlength, "%t", "Timer Management");
  423.     }
  424.     else if (action == TopMenuAction_DisplayOption)
  425.     {
  426.         FormatEx(buffer, maxlength, "%t", "Timer Management");
  427.     }
  428. }
  429.  
  430. public AdminMenu_AddMapZone(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  431. {
  432.     if (action == TopMenuAction_DisplayOption)
  433.     {
  434.         FormatEx(buffer, maxlength, "%t", "Add Map Zone");
  435.     }
  436.     else if (action == TopMenuAction_SelectOption)
  437.     {
  438.         RestartMapZoneEditor(param);
  439.         g_mapZoneEditors[param][Step] = 1;
  440.         DisplaySelectPointMenu(param, 1);
  441.     }
  442. }
  443.  
  444. public AdminMenu_RemoveMapZone(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  445. {
  446.     if (action == TopMenuAction_DisplayOption)
  447.     {
  448.         FormatEx(buffer, maxlength, "%t", "Delete Map Zone");
  449.     }
  450.     else if (action == TopMenuAction_SelectOption)
  451.     {
  452.         DeleteMapZone(param);
  453.     }
  454. }
  455.  
  456. public AdminMenu_RemoveAllMapZones(Handle:topmenu,  TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  457. {
  458.     if (action == TopMenuAction_DisplayOption)
  459.     {
  460.         FormatEx(buffer, maxlength, "%t", "Delete All Map Zones");
  461.     }
  462.     else if (action == TopMenuAction_SelectOption)
  463.     {
  464.         DeleteAllMapZones(param);
  465.     }
  466. }
  467.  
  468. RestartMapZoneEditor(client)
  469. {
  470.     g_mapZoneEditors[client][Step] = 0;
  471.  
  472.     for (new i = 0; i < 3; i++)
  473.     {
  474.         g_mapZoneEditors[client][Point1][i] = 0.0;
  475.     }
  476.  
  477.     for (new i = 0; i < 3; i++)
  478.     {
  479.         g_mapZoneEditors[client][Point1][i] = 0.0
  480.     }
  481. }
  482.  
  483. DeleteMapZone(client)
  484. {
  485.     new Float:vOrigin[3];
  486.     GetClientAbsOrigin(client, vOrigin);
  487.    
  488.     for (new zone = 0; zone < g_mapZonesCount; zone++)
  489.     {
  490.         if (IsInsideBox(vOrigin, g_mapZones[zone][Point1][0], g_mapZones[zone][Point1][1], g_mapZones[zone][Point1][2], g_mapZones[zone][Point2][0], g_mapZones[zone][Point2][1], g_mapZones[zone][Point2][2]))
  491.         {
  492.             decl String:sQuery[64];
  493.             FormatEx(sQuery, sizeof(sQuery), "DELETE FROM mapzone WHERE id = %d", g_mapZones[zone][Id]);
  494.  
  495.             SQL_TQuery(g_hSQL, DeleteMapZoneCallback, sQuery, client, DBPrio_High);
  496.             break;
  497.         }
  498.     }
  499. }
  500.  
  501. DeleteAllMapZones(client)
  502. {
  503.     decl String:sQuery[96];
  504.     FormatEx(sQuery, sizeof(sQuery), "DELETE FROM mapzone WHERE map = '%s'", g_sCurrentMap);
  505.  
  506.     SQL_TQuery(g_hSQL, DeleteMapZoneCallback, sQuery, client, DBPrio_High);
  507. }
  508.  
  509. public DeleteMapZoneCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
  510. {
  511.     if (hndl == INVALID_HANDLE)
  512.     {
  513.         Timer_LogError("SQL Error on DeleteMapZone: %s", error);
  514.         return;
  515.     }
  516.  
  517.     LoadMapZones();
  518.    
  519.     if (IsClientInGame(data))
  520.     {
  521.         PrintToChat(data, PLUGIN_PREFIX, "Map Zone Delete");
  522.     }
  523. }
  524.  
  525. DisplaySelectPointMenu(client, n)
  526. {
  527.     new Handle:panel = CreatePanel();
  528.  
  529.     decl String:sMessage[255];
  530.     decl String:sFirst[32], String:sSecond[32];
  531.     FormatEx(sFirst, sizeof(sFirst), "%t", "FIRST");
  532.     FormatEx(sSecond, sizeof(sSecond), "%t", "SECOND");
  533.    
  534.     FormatEx(sMessage, sizeof(sMessage), "%t", "Point Select Panel", (n == 1) ? sFirst : sSecond);
  535.  
  536.     DrawPanelItem(panel, sMessage, ITEMDRAW_RAWLINE);
  537.  
  538.     FormatEx(sMessage, sizeof(sMessage), "%t", "Cancel");
  539.     DrawPanelItem(panel, sMessage);
  540.  
  541.     SendPanelToClient(panel, client, PointSelect, 540);
  542.     CloseHandle(panel);
  543. }
  544.  
  545. DisplayPleaseWaitMenu(client)
  546. {
  547.     new Handle:panel = CreatePanel();
  548.    
  549.     decl String:sWait[64];
  550.     FormatEx(sWait, sizeof(sWait), "%t", "Please wait");
  551.     DrawPanelItem(panel, sWait, ITEMDRAW_RAWLINE);
  552.  
  553.     SendPanelToClient(panel, client, PointSelect, 540);
  554.     CloseHandle(panel);
  555. }
  556.  
  557. public PointSelect(Handle:menu, MenuAction:action, param1, param2)
  558. {
  559.     if (action == MenuAction_End)
  560.     {
  561.         CloseHandle(menu);
  562.     }
  563.     else if (action == MenuAction_Select)
  564.     {
  565.         if (param2 == MenuCancel_Exit && hTopMenu != INVALID_HANDLE)
  566.         {
  567.             DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
  568.         }
  569.  
  570.         RestartMapZoneEditor(param1);
  571.     }
  572. }
  573.  
  574. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
  575. {
  576.     if (buttons & IN_ATTACK2)
  577.     {
  578.         if (g_mapZoneEditors[client][Step] == 1)
  579.         {
  580.             new Float:vOrigin[3];          
  581.             GetClientAbsOrigin(client, vOrigin);
  582.             g_mapZoneEditors[client][Point1] = vOrigin;
  583.  
  584.             DisplayPleaseWaitMenu(client);
  585.  
  586.             CreateTimer(1.0, ChangeStep, GetClientSerial(client));
  587.             return Plugin_Handled;
  588.         }
  589.         else if (g_mapZoneEditors[client][Step] == 2)
  590.         {
  591.             new Float:vOrigin[3];
  592.             GetClientAbsOrigin(client, vOrigin);
  593.             g_mapZoneEditors[client][Point2] = vOrigin;
  594.  
  595.             g_mapZoneEditors[client][Step] = 3;
  596.  
  597.             DisplaySelectZoneTypeMenu(client);
  598.  
  599.             return Plugin_Handled;
  600.         }      
  601.     }
  602.  
  603.     return Plugin_Continue;
  604. }
  605.  
  606. public Action:ChangeStep(Handle:timer, any:serial)
  607. {
  608.     new client = GetClientFromSerial(serial);
  609.    
  610.     g_mapZoneEditors[client][Step] = 2;
  611.     CreateTimer(0.1, DrawAdminBox, GetClientSerial(client), TIMER_REPEAT);
  612.  
  613.     DisplaySelectPointMenu(client, 2);
  614. }
  615.  
  616. DisplaySelectZoneTypeMenu(client)
  617. {
  618.     new Handle:menu = CreateMenu(ZoneTypeSelect);
  619.     SetMenuTitle(menu, "%T", "Select zone type", client);
  620.    
  621.     decl String:sText[256];
  622.    
  623.     FormatEx(sText, sizeof(sText), "%T", "Start", client);
  624.     AddMenuItem(menu, "0", sText);
  625.  
  626.     FormatEx(sText, sizeof(sText), "%T", "End", client);
  627.     AddMenuItem(menu, "1", sText);
  628.    
  629.     FormatEx(sText, sizeof(sText), "%T", "Glitch1", client);
  630.     AddMenuItem(menu, "2", sText);
  631.    
  632.     FormatEx(sText, sizeof(sText), "%T", "Glitch2", client);
  633.     AddMenuItem(menu, "3", sText);
  634.    
  635.     FormatEx(sText, sizeof(sText), "%T", "Glitch3", client);
  636.     AddMenuItem(menu, "4", sText);
  637.    
  638.     SetMenuExitButton(menu, true);
  639.     DisplayMenu(menu, client, 360);
  640. }
  641.  
  642. public ZoneTypeSelect(Handle:menu, MenuAction:action, param1, param2)
  643. {
  644.     if (action == MenuAction_End)
  645.     {
  646.         CloseHandle(menu);
  647.         RestartMapZoneEditor(param1);
  648.     }
  649.     else if (action == MenuAction_Cancel)
  650.     {
  651.         if (param2 == MenuCancel_Exit && hTopMenu != INVALID_HANDLE)
  652.         {
  653.             DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
  654.             RestartMapZoneEditor(param1);
  655.         }
  656.     }
  657.     else if (action == MenuAction_Select)
  658.     {
  659.         new Float:point1[3];
  660.         Array_Copy(g_mapZoneEditors[param1][Point1], point1, 3);
  661.  
  662.         new Float:point2[3];
  663.         Array_Copy(g_mapZoneEditors[param1][Point2], point2, 3);
  664.  
  665.         point1[2] -= 2;
  666.         point2[2] += 100;
  667.  
  668.         AddMapZone(g_sCurrentMap, MapZoneType:param2, point1, point2);
  669.         RestartMapZoneEditor(param1);
  670.         LoadMapZones();
  671.     }
  672. }
  673.  
  674. public Action:DrawAdminBox(Handle:timer, any:serial)
  675. {
  676.     new client = GetClientFromSerial(serial);
  677.    
  678.     if (g_mapZoneEditors[client][Step] == 0)
  679.     {
  680.         return Plugin_Stop;
  681.     }
  682.    
  683.     new Float:a[3], Float:b[3];
  684.  
  685.     Array_Copy(g_mapZoneEditors[client][Point1], b, 3);
  686.  
  687.     if (g_mapZoneEditors[client][Step] == 3)
  688.     {
  689.         Array_Copy(g_mapZoneEditors[client][Point2], a, 3);
  690.     }
  691.     else
  692.     {
  693.         GetClientAbsOrigin(client, a);
  694.     }
  695.  
  696.     // Effect_DrawBeamBoxToClient(client, a, b, g_precacheLaser, 0, 0, 30, 0.1, 3.0, 3.0);
  697.     new color[4] = {255, 255, 255, 255};
  698.  
  699.     DrawBox(a, b, 0.1, color, false);
  700.     return Plugin_Continue;
  701. }
  702.  
  703. public Action:DrawZones(Handle:timer)
  704. {
  705.     if (!g_bDrawMapZones)
  706.     {
  707.         return Plugin_Stop;
  708.     }
  709.    
  710.     for (new zone = 0; zone < g_mapZonesCount; zone++)
  711.     {
  712.         if (g_mapZones[zone][Type] == Start || g_mapZones[zone][Type] == End)
  713.         {
  714.             new Float:point1[3];
  715.             Array_Copy(g_mapZones[zone][Point1], point1, 3);
  716.  
  717.             new Float:point2[3];
  718.             Array_Copy(g_mapZones[zone][Point2], point2, 3);
  719.            
  720.             if (point1[2] < point2[2])
  721.             {
  722.                 point2[2] = point1[2];
  723.             }
  724.             else
  725.             {
  726.                 point1[2] = point2[2];
  727.             }
  728.  
  729.             if (g_mapZones[zone][Type] == Start)
  730.             {
  731.                 DrawBox(point1, point2, 2.0, g_startColor, true);
  732.             }
  733.             else if (g_mapZones[zone][Type] == End)
  734.             {
  735.                 DrawBox(point1, point2, 2.0, g_endColor, true);
  736.             }
  737.         }
  738.     }
  739.  
  740.     return Plugin_Continue;
  741. }
  742.  
  743. public Action:PlayerTracker(Handle:timer)
  744. {
  745.     for (new client = 1; client <= MaxClients; client++)
  746.     {
  747.         if (IsClientInGame(client) && IsPlayerAlive(client) && !IsClientObserver(client))
  748.         {
  749.             new Float:vOrigin[3];
  750.             GetClientAbsOrigin(client, vOrigin);
  751.            
  752.             for (new zone = 0; zone < g_mapZonesCount; zone++)
  753.             {
  754.                 if (IsInsideBox(vOrigin, g_mapZones[zone][Point1][0], g_mapZones[zone][Point1][1], g_mapZones[zone][Point1][2], g_mapZones[zone][Point2][0], g_mapZones[zone][Point2][1], g_mapZones[zone][Point2][2]))
  755.                 {
  756.                     if (g_mapZones[zone][Type] == Start)
  757.                     {
  758.                         Timer_Stop(client, false);
  759.                         Timer_Start(client);
  760.                        
  761.                         if (g_bStopPrespeed)
  762.                         {
  763.                             StopPrespeed(client);
  764.                         }
  765.                     }
  766.                     else if (g_mapZones[zone][Type] == End)
  767.                     {
  768.                         if (Timer_Stop(client, false))
  769.                         {
  770.                             new bool:enabled = false;
  771.                             new jumps, fpsmax, flashbangs;
  772.                             new Float:time;
  773.  
  774.                             if (Timer_GetClientTimer(client, enabled, time, jumps, fpsmax, flashbangs))
  775.                             {
  776.                                 new difficulty = 0;
  777.                                 if (g_bTimerPhysics)
  778.                                 {
  779.                                     difficulty = Timer_GetClientDifficulty(client);
  780.                                 }
  781.  
  782.                                 Timer_FinishRound(client, g_sCurrentMap, time, jumps, flashbangs, difficulty, fpsmax);
  783.                                
  784.                                 if (g_bTimerWorldRecord)
  785.                                 {
  786.                                     Timer_ForceReloadWorldRecordCache();
  787.                                 }
  788.                             }
  789.                         }
  790.                     }
  791.                     else if (g_mapZones[zone][Type] == Glitch1)
  792.                     {
  793.                         Timer_Stop(client);
  794.                     }
  795.                     else if (g_mapZones[zone][Type] == Glitch2)
  796.                     {
  797.                         Timer_Restart(client);
  798.                     }
  799.                     else if (g_mapZones[zone][Type] == Glitch3)
  800.                     {
  801.                         CS_RespawnPlayer(client);
  802.                     }
  803.  
  804.                     break;
  805.                 }  
  806.             }
  807.         }      
  808.     }
  809.  
  810.     return Plugin_Continue;
  811. }
  812.  
  813. IsInsideBox(Float:fPCords[3], Float:fbsx, Float:fbsy, Float:fbsz, Float:fbex, Float:fbey, Float:fbez)
  814. {
  815.     new Float:fpx = fPCords[0];
  816.     new Float:fpy = fPCords[1];
  817.     new Float:fpz = fPCords[2];
  818.    
  819.     new bool:bX = false;
  820.     new bool:bY = false;
  821.     new bool:bZ = false;
  822.  
  823.     if (fbsx > fbex && fpx <= fbsx && fpx >= fbex)
  824.     {
  825.         bX = true;
  826.     }
  827.     else if (fbsx < fbex && fpx >= fbsx && fpx <= fbex)
  828.     {
  829.         bX = true;
  830.     }
  831.    
  832.     if (fbsy > fbey && fpy <= fbsy && fpy >= fbey)
  833.     {
  834.         bY = true;
  835.     }
  836.     else if (fbsy < fbey && fpy >= fbsy && fpy <= fbey)
  837.     {
  838.         bY = true;
  839.     }
  840.    
  841.     if (fbsz > fbez && fpz <= fbsz && fpz >= fbez)
  842.     {
  843.         bZ = true;
  844.     }
  845.     else if (fbsz < fbez && fpz >= fbsz && fpz <= fbez)
  846.     {
  847.         bZ = true;
  848.     }
  849.    
  850.     if (bX && bY && bZ)
  851.     {
  852.         return true;
  853.     }
  854.    
  855.     return false;
  856. }
  857.  
  858. public Native_AddMapZone(Handle:plugin, numParams)
  859. {
  860.     decl String:map[32];
  861.     GetNativeString(1, map, sizeof(map));
  862.    
  863.     new MapZoneType:type = GetNativeCell(2);   
  864.    
  865.     new Float:point1[3];
  866.     GetNativeArray(3, point1, sizeof(point1));
  867.    
  868.     new Float:point2[3];
  869.     GetNativeArray(3, point2, sizeof(point2))
  870.    
  871.     AddMapZone(map, type, point1, point2);
  872. }
  873.  
  874. DrawBox(Float:fFrom[3], Float:fTo[3], Float:fLife, color[4], bool:flat)
  875. {
  876.     //initialize tempoary variables bottom front
  877.     decl Float:fLeftBottomFront[3];
  878.     fLeftBottomFront[0] = fFrom[0];
  879.     fLeftBottomFront[1] = fFrom[1];
  880.     if(flat)
  881.     {
  882.         fLeftBottomFront[2] = fTo[2]-2;
  883.     }
  884.     else
  885.     {
  886.         fLeftBottomFront[2] = fTo[2];
  887.     }
  888.    
  889.     decl Float:fRightBottomFront[3];
  890.     fRightBottomFront[0] = fTo[0];
  891.     fRightBottomFront[1] = fFrom[1];
  892.     if(flat)
  893.     {
  894.         fRightBottomFront[2] = fTo[2]-2;
  895.     }
  896.     else
  897.     {
  898.         fRightBottomFront[2] = fTo[2];
  899.     }
  900.    
  901.     //initialize tempoary variables bottom back
  902.     decl Float:fLeftBottomBack[3];
  903.     fLeftBottomBack[0] = fFrom[0];
  904.     fLeftBottomBack[1] = fTo[1];
  905.     if(flat)
  906.     {
  907.         fLeftBottomBack[2] = fTo[2]-2;
  908.     }
  909.     else
  910.     {
  911.         fLeftBottomBack[2] = fTo[2];
  912.     }
  913.    
  914.     decl Float:fRightBottomBack[3];
  915.     fRightBottomBack[0] = fTo[0];
  916.     fRightBottomBack[1] = fTo[1];
  917.     if(flat)
  918.     {
  919.         fRightBottomBack[2] = fTo[2]-2;
  920.     }
  921.     else
  922.     {
  923.         fRightBottomBack[2] = fTo[2];
  924.     }
  925.    
  926.     //initialize tempoary variables top front
  927.     decl Float:lefttopfront[3];
  928.     lefttopfront[0] = fFrom[0];
  929.     lefttopfront[1] = fFrom[1];
  930.     if(flat)
  931.     {
  932.         lefttopfront[2] = fFrom[2]+2;
  933.     }
  934.     else
  935.     {
  936.         lefttopfront[2] = fFrom[2]+100;
  937.     }
  938.    
  939.     decl Float:righttopfront[3];
  940.     righttopfront[0] = fTo[0];
  941.     righttopfront[1] = fFrom[1];
  942.     if(flat)
  943.     {
  944.         righttopfront[2] = fFrom[2]+2;
  945.     }
  946.     else
  947.     {
  948.         righttopfront[2] = fFrom[2]+100;
  949.     }
  950.    
  951.     //initialize tempoary variables top back
  952.     decl Float:fLeftTopBack[3];
  953.     fLeftTopBack[0] = fFrom[0];
  954.     fLeftTopBack[1] = fTo[1];
  955.     if(flat)
  956.     {
  957.         fLeftTopBack[2] = fFrom[2]+2;
  958.     }
  959.     else
  960.     {
  961.         fLeftTopBack[2] = fFrom[2]+100;
  962.     }
  963.    
  964.     decl Float:fRightTopBack[3];
  965.     fRightTopBack[0] = fTo[0];
  966.     fRightTopBack[1] = fTo[1];
  967.     if(flat)
  968.     {
  969.         fRightTopBack[2] = fFrom[2]+2;
  970.     }
  971.     else
  972.     {
  973.         fRightTopBack[2] = fFrom[2]+100;
  974.     }
  975.    
  976.     //create the box
  977.     TE_SetupBeamPoints(lefttopfront,righttopfront,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  978.     TE_SetupBeamPoints(lefttopfront,fLeftTopBack,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  979.     TE_SetupBeamPoints(fRightTopBack,fLeftTopBack,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  980.     TE_SetupBeamPoints(fRightTopBack,righttopfront,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  981.  
  982.     if(!flat)
  983.     {
  984.         TE_SetupBeamPoints(fLeftBottomFront,fRightBottomFront,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  985.         TE_SetupBeamPoints(fLeftBottomFront,fLeftBottomBack,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  986.         TE_SetupBeamPoints(fLeftBottomFront,lefttopfront,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  987.  
  988.        
  989.         TE_SetupBeamPoints(fRightBottomBack,fLeftBottomBack,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  990.         TE_SetupBeamPoints(fRightBottomBack,fRightBottomFront,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  991.         TE_SetupBeamPoints(fRightBottomBack,fRightTopBack,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  992.        
  993.         TE_SetupBeamPoints(fRightBottomFront,righttopfront,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  994.         TE_SetupBeamPoints(fLeftBottomBack,fLeftTopBack,g_precacheLaser,0,0,0,fLife,3.0,3.0,10,0.0,color,0);TE_SendToAll(0.0);//TE_SendToClient(client, 0.0);
  995.     }
  996. }
  997.  
  998. ParseColor(const String:color[], result[])
  999. {
  1000.     decl String:buffers[4][4];
  1001.     ExplodeString(color, " ", buffers, sizeof(buffers), sizeof(buffers[]));
  1002.    
  1003.     for (new i = 0; i < sizeof(buffers); i++)
  1004.     {
  1005.         result[i] = StringToInt(buffers[i]);
  1006.     }
  1007. }
  1008.  
  1009. StopPrespeed(client)
  1010. {
  1011.     new Float:vVelocity[3];
  1012.     GetEntPropVector(client, Prop_Data, "m_vecVelocity", vVelocity);
  1013.    
  1014.     if (SquareRoot(Pow(vVelocity[0], 2.0) + Pow(vVelocity[1], 2.0)) > (GetEntPropFloat(client, Prop_Data, "m_flMaxspeed") * 1.115 + 0.5))
  1015.     {
  1016.         TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Float:{0.0, 0.0, 0.0});
  1017.     }  
  1018. }
  1019.  
  1020. public Setting(Handle:convar, const String:oldValue[], const String:newValue[])
  1021. {
  1022.     if (convar == sm_maxsave)
  1023.     {
  1024.         maxsave = GetConVarInt(sm_maxsave);
  1025.     }
  1026.     else if (convar == sm_maxtele)
  1027.     {
  1028.         maxtele = GetConVarInt(sm_maxtele);
  1029.     }
  1030. }
  1031.  
  1032. public OnClientAuthorized(client)
  1033. {
  1034.     Keys_create(client);
  1035. }
  1036.  
  1037. Keys_create(client)
  1038. {
  1039.     save[client] = 0;
  1040.     checkpoint[client][0] = 0.0;
  1041.     checkpoint[client][1] = 0.0;
  1042.     checkpoint[client][2] = 0.0;
  1043. }
  1044.  
  1045. public OnPlayer_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
  1046. {
  1047.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  1048.     save[client] = 0;
  1049.     tele[client] = 0;
  1050.     checkpoint[client][0] = 0.0;
  1051.     checkpoint[client][1] = 0.0;
  1052.     checkpoint[client][2] = 0.0;
  1053.     PrintToChat(client, "\x03Checkpoints are reset\x01");
  1054. }
  1055.  
  1056.  
  1057. public Action:cmd_save(client, args)
  1058. {
  1059.     if(save[client] < maxsave)
  1060.     {
  1061.         if (IsPlayerAlive(client))
  1062.         {
  1063.             GetEntPropVector(client, Prop_Send, "m_vecOrigin", checkpoint[client]);
  1064.             PrintToChat(client, "\x03[\x04Checkpoint saved\x03]");
  1065.             save[client]++;
  1066.         }
  1067.         else
  1068.         {
  1069.             PrintToChat(client, "\x03You must be alive\x01");
  1070.         }
  1071.     }
  1072.     else
  1073.     {
  1074.         PrintToChat(client, "\x03Checkpoint saved\x01");
  1075.     }
  1076.     return Plugin_Handled;
  1077. }
  1078.  
  1079. public Action:cmd_tele(client, args)
  1080. {
  1081.     if(tele[client] <  maxtele)
  1082.     {
  1083.         if (IsPlayerAlive(client))
  1084.         {
  1085.             if (tele[client] < maxtele)
  1086.                 if(save[client] > 0)
  1087.             {
  1088.                 {
  1089.                     TeleportEntity(client, checkpoint[client], NULL_VECTOR, NULL_VECTOR);
  1090.                     PrintToChat(client, "\x03Teleported\x01");
  1091.                     tele[client]++;  
  1092.                     Timer_Stop(client, false);
  1093.                 }
  1094.             }
  1095.                 else
  1096.             {
  1097.                 PrintToChat(client, "\x03First, save the position command: !save\x01");
  1098.             }
  1099.         }
  1100.         else
  1101.         {
  1102.             PrintToChat(client, "\x03You must be alive\x01");
  1103.         }
  1104.     }
  1105.     return Plugin_Handled;
  1106. }
  1107. public Action:cmd_clean(client, args)
  1108. {
  1109.     save[client] = 0;
  1110.     tele[client] = 0;
  1111.     checkpoint[client][0] = 0.0;
  1112.     checkpoint[client][1] = 0.0;
  1113.     checkpoint[client][2] = 0.0;
  1114.     PrintToChat(client, "\x03Checkpoints are reset\x01");
  1115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement