Advertisement
Rei_Ayanami

ColorMatch

Apr 27th, 2024
1,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <izcmd>
  4.  
  5. #define     CM_EVENT_TIME       (120)   // event time, in seconds (default: 120)
  6. #define     CM_MIN_PLAYERS      (2)     // players required to start the event (default: 2)
  7. #define     CM_MAX_PLAYERS      (16)    // max players allowed to join (default: 16)
  8. #define     CM_SETUP_TIME       (15)    // setup time where players can join, in seconds (default: 15)
  9. #define     CM_REWARD           (5000)  // how much money the winner will get (default: 5000)
  10. #define     CM_SEPERATE                 // prevents player following by moving every player to a different virtual world, comment or remove this line if you don't want it
  11. #define     CM_USEFENCES                // creates fences around the arena, comment or remove this line if you don't want it
  12.  
  13. enum    _:E_OBJECTID
  14. {
  15.     OBJ_ORANGE,
  16.     OBJ_RED,
  17.     OBJ_GREEN,
  18.     OBJ_YELLOW,
  19.     OBJ_PURPLE,
  20.     OBJ_PINK,
  21.     OBJ_MAROON,
  22.     OBJ_BLUE,
  23.     OBJ_WHITE
  24. }
  25.  
  26. enum    _:E_GAMESTAGE
  27. {
  28.     STAGE_NONE,
  29.     STAGE_SETUP,
  30.     STAGE_PLAYING
  31. }
  32.  
  33. new
  34.     ColorMatchObjects[9] = {INVALID_OBJECT_ID, ...},
  35.     ColorMatchNames[9][7] = {"Orange", "Red", "Green", "Yellow", "Purple", "Pink", "Maroon", "Blue", "White"},
  36.     ColorMatchColors[9] = {0xFF7F00FF, 0xEE0000FF, 0x00EE00FF, 0xFFFF00FF, 0x9B30FFFF, 0xFF1493FF, 0x8B1A1AFF, 0x1E90FFFF, 0xFFFFFFFF};
  37.    
  38. #if defined CM_USEFENCES
  39. new
  40.     ColorMatchFences[8] = {INVALID_OBJECT_ID, ...};
  41. #endif
  42.  
  43. new
  44.     ColorMatchCurrent = -1,
  45.     ColorMatchPlayers,
  46.     ColorMatchTimer = -1,
  47.     ColorMatchFallTimer = -1,
  48.     ColorMatchEventTimer = -1,
  49.     ColorMatchStage = STAGE_NONE,
  50.     Text: ColorMatchTD;
  51.    
  52. new
  53.     bool: InCMEvent[MAX_PLAYERS],
  54.     PlayerText: ColorText[MAX_PLAYERS] = {PlayerText: INVALID_TEXT_DRAW, ...};
  55.  
  56. // http://forum.sa-mp.com/showpost.php?p=3117531&postcount=5
  57. RGBAToARGB(rgba)
  58.     return rgba >>> 8 | rgba << 24;
  59.  
  60. // http://forum.sa-mp.com/showpost.php?p=1120652&postcount=3
  61. Float: frandom(Float:max, Float:min = 0.0, dp = 4)
  62. {
  63.     new
  64.         Float:mul = floatpower(10.0, dp),
  65.         imin = floatround(min * mul),
  66.         imax = floatround(max * mul);
  67.     return float(random(imax - imin) + imin) / mul;
  68. }
  69.  
  70. // http://forum.sa-mp.com/showpost.php?p=3223897&postcount=11
  71. ConvertToMinutes(time)
  72. {
  73.     new string[15];//-2000000000:00 could happen, so make the string 15 chars to avoid any errors
  74.     format(string, sizeof(string), "%02d:%02d", time / 60, time % 60);
  75.     return string;
  76. }
  77.  
  78. ColorMatch_Arena()
  79. {
  80.     for(new i; i < sizeof(ColorMatchObjects); i++) DestroyObject(ColorMatchObjects[i]);
  81.    
  82.     ColorMatchObjects[OBJ_ORANGE] = CreateObject(19353, 2005.390, 3866.277, 101.323, 0.000, 90.000, 90.000); //  orange
  83.     SetObjectMaterial(ColorMatchObjects[OBJ_ORANGE], 0, 18996, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_ORANGE]));
  84.  
  85.     ColorMatchObjects[OBJ_RED] = CreateObject(19353, 2008.590, 3866.277, 101.323, 0.000, 90.000, 90.000); // red
  86.     SetObjectMaterial(ColorMatchObjects[OBJ_RED], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_RED]));
  87.  
  88.     ColorMatchObjects[OBJ_GREEN] = CreateObject(19353, 2002.190, 3866.277, 101.323, 0.000, 90.000, 90.000); // green
  89.     SetObjectMaterial(ColorMatchObjects[OBJ_GREEN], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_GREEN]));
  90.  
  91.     ColorMatchObjects[OBJ_YELLOW] = CreateObject(19353, 2008.590, 3862.777, 101.323, 0.000, 90.000, 90.000); // yellow
  92.     SetObjectMaterial(ColorMatchObjects[OBJ_YELLOW], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_YELLOW]));
  93.  
  94.     ColorMatchObjects[OBJ_PURPLE] = CreateObject(19353, 2008.590, 3869.777, 101.323, 0.000, 90.000, 90.000); // purple
  95.     SetObjectMaterial(ColorMatchObjects[OBJ_PURPLE], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_PURPLE]));
  96.  
  97.     ColorMatchObjects[OBJ_PINK] = CreateObject(19353, 2005.390, 3862.777, 101.323, 0.000, 90.000, 90.000); // pink
  98.     SetObjectMaterial(ColorMatchObjects[OBJ_PINK], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_PINK]));
  99.  
  100.     ColorMatchObjects[OBJ_MAROON] = CreateObject(19353, 2005.390, 3869.777, 101.323, 0.000, 90.000, 90.000); // maroon
  101.     SetObjectMaterial(ColorMatchObjects[OBJ_MAROON], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_MAROON]));
  102.  
  103.     ColorMatchObjects[OBJ_BLUE] = CreateObject(19353, 2002.190, 3869.777, 101.323, 0.000, 90.000, 90.000); // blue
  104.     SetObjectMaterial(ColorMatchObjects[OBJ_BLUE], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_BLUE]));
  105.  
  106.     ColorMatchObjects[OBJ_WHITE] = CreateObject(19353, 2002.190, 3862.777, 101.323, 0.000, 90.000, 90.000); // white
  107.     SetObjectMaterial(ColorMatchObjects[OBJ_WHITE], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_WHITE]));
  108.    
  109.     #if defined CM_USEFENCES
  110.     for(new i; i < sizeof(ColorMatchFences); i++) DestroyObject(ColorMatchFences[i]);
  111.    
  112.     ColorMatchFences[0] = CreateObject(8674, 2005.395, 3871.529, 102.859, 0.000, 0.000, 0.000);
  113.     ColorMatchFences[1] = CreateObject(8674, 2000.584, 3866.285, 102.859, 0.000, 0.000, 90.000);
  114.     ColorMatchFences[2] = CreateObject(8674, 2010.208, 3866.285, 102.859, 0.000, 0.000, 90.000);
  115.     ColorMatchFences[3] = CreateObject(8674, 2005.395, 3861.021, 102.859, 0.000, 0.000, 0.000);
  116.    
  117.     ColorMatchFences[4] = CreateObject(8674, 2005.395, 3871.529, 105.809, 0.000, 0.000, 0.000);
  118.     ColorMatchFences[5] = CreateObject(8674, 2000.584, 3866.285, 105.809, 0.000, 0.000, 90.000);
  119.     ColorMatchFences[6] = CreateObject(8674, 2010.208, 3866.285, 105.809, 0.000, 0.000, 90.000);
  120.     ColorMatchFences[7] = CreateObject(8674, 2005.395, 3861.021, 105.809, 0.000, 0.000, 0.000);
  121.     #endif
  122.     return 1;
  123. }
  124.  
  125. ColorMatch_CleanUp(players = 0)
  126. {
  127.     KillTimer(ColorMatchTimer);
  128.     KillTimer(ColorMatchFallTimer);
  129.     KillTimer(ColorMatchEventTimer);
  130.     ColorMatchStage = STAGE_NONE;
  131.     ColorMatchPlayers = 0;
  132.     ColorMatchTimer = -1;
  133.     ColorMatchFallTimer = -1;
  134.     ColorMatchEventTimer = -1;
  135.    
  136.     if(players)
  137.     {
  138.         for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  139.         {
  140.             if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  141.             InCMEvent[i] = false;
  142.             PlayerTextDrawHide(i, ColorText[i]);
  143.             TextDrawHideForPlayer(i, ColorMatchTD);
  144.             SetPlayerVirtualWorld(i, 0);
  145.             SpawnPlayer(i);
  146.         }
  147.     }
  148.  
  149.     return 1;
  150. }
  151.  
  152. ColorMatch_InitPlayer(playerid)
  153. {
  154.     InCMEvent[playerid] = false;
  155.  
  156.     ColorText[playerid] = CreatePlayerTextDraw(playerid,317.000000, 150.000000, "_");
  157.     PlayerTextDrawAlignment(playerid,ColorText[playerid], 2);
  158.     PlayerTextDrawBackgroundColor(playerid,ColorText[playerid], 255);
  159.     PlayerTextDrawFont(playerid,ColorText[playerid], 2);
  160.     PlayerTextDrawLetterSize(playerid,ColorText[playerid], 0.700000, 3.000000);
  161.     PlayerTextDrawColor(playerid,ColorText[playerid], -1);
  162.     PlayerTextDrawSetOutline(playerid,ColorText[playerid], 1);
  163.     PlayerTextDrawSetProportional(playerid,ColorText[playerid], 1);
  164.     PlayerTextDrawSetSelectable(playerid,ColorText[playerid], 0);
  165.     return 1;
  166. }
  167.  
  168. ColorMatch_Eliminate(playerid)
  169. {
  170.     if(!InCMEvent[playerid]) return 1;
  171.     TextDrawHideForPlayer(playerid, ColorMatchTD);
  172.     PlayerTextDrawHide(playerid, ColorText[playerid]);
  173.     SetPlayerVirtualWorld(playerid, 0);
  174.     SpawnPlayer(playerid);
  175.     ColorMatchPlayers--;
  176.    
  177.     new string[144], name[MAX_PLAYER_NAME];
  178.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  179.     format(string, sizeof(string), "[COLORMATCH] {FFFFFF}%s(%d) got eliminated. Players Left: {F1C40F}%d", name, playerid, ColorMatchPlayers);
  180.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  181.     {
  182.         if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  183.         SendClientMessage(i, 0x3498DBFF, string);
  184.     }
  185.    
  186.     InCMEvent[playerid] = false;
  187.    
  188.     if(ColorMatchStage == STAGE_PLAYING)
  189.     {
  190.         if(ColorMatchPlayers < 2)
  191.         {
  192.             new winner = INVALID_PLAYER_ID;
  193.             for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  194.             {
  195.                 if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  196.                 winner = i;
  197.                 break;
  198.             }
  199.            
  200.             if(IsPlayerConnected(winner))
  201.             {
  202.                 GetPlayerName(winner, name, MAX_PLAYER_NAME);
  203.                 format(string, sizeof(string), "[COLORMATCH] {FFFFFF}%s(%d) has won the event!", name, winner);
  204.                 SendClientMessageToAll(0x3498DBFF, string);
  205.                 GivePlayerMoney(winner, CM_REWARD);
  206.             }
  207.            
  208.             SendClientMessageToAll(0x3498DBFF, "[COLORMATCH] {FFFFFF}Event ended.");
  209.             ColorMatch_CleanUp(1);
  210.         }
  211.     }
  212.    
  213.     return 1;
  214. }
  215.  
  216. public OnFilterScriptInit()
  217. {
  218.     ColorMatchObjects[OBJ_ORANGE] = CreateObject(19353, 2005.390, 3866.277, 101.323, 0.000, 90.000, 90.000); //  orange
  219.     SetObjectMaterial(ColorMatchObjects[OBJ_ORANGE], 0, 18996, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_ORANGE]));
  220.    
  221.     ColorMatchObjects[OBJ_RED] = CreateObject(19353, 2008.590, 3866.277, 101.323, 0.000, 90.000, 90.000); // red
  222.     SetObjectMaterial(ColorMatchObjects[OBJ_RED], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_RED]));
  223.    
  224.     ColorMatchObjects[OBJ_GREEN] = CreateObject(19353, 2002.190, 3866.277, 101.323, 0.000, 90.000, 90.000); // green
  225.     SetObjectMaterial(ColorMatchObjects[OBJ_GREEN], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_GREEN]));
  226.    
  227.     ColorMatchObjects[OBJ_YELLOW] = CreateObject(19353, 2008.590, 3862.777, 101.323, 0.000, 90.000, 90.000); // yellow
  228.     SetObjectMaterial(ColorMatchObjects[OBJ_YELLOW], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_YELLOW]));
  229.    
  230.     ColorMatchObjects[OBJ_PURPLE] = CreateObject(19353, 2008.590, 3869.777, 101.323, 0.000, 90.000, 90.000); // purple
  231.     SetObjectMaterial(ColorMatchObjects[OBJ_PURPLE], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_PURPLE]));
  232.  
  233.     ColorMatchObjects[OBJ_PINK] = CreateObject(19353, 2005.390, 3862.777, 101.323, 0.000, 90.000, 90.000); // pink
  234.     SetObjectMaterial(ColorMatchObjects[OBJ_PINK], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_PINK]));
  235.    
  236.     ColorMatchObjects[OBJ_MAROON] = CreateObject(19353, 2005.390, 3869.777, 101.323, 0.000, 90.000, 90.000); // maroon
  237.     SetObjectMaterial(ColorMatchObjects[OBJ_MAROON], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_MAROON]));
  238.    
  239.     ColorMatchObjects[OBJ_BLUE] = CreateObject(19353, 2002.190, 3869.777, 101.323, 0.000, 90.000, 90.000); // blue
  240.     SetObjectMaterial(ColorMatchObjects[OBJ_BLUE], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_BLUE]));
  241.  
  242.     ColorMatchObjects[OBJ_WHITE] = CreateObject(19353, 2002.190, 3862.777, 101.323, 0.000, 90.000, 90.000); // white
  243.     SetObjectMaterial(ColorMatchObjects[OBJ_WHITE], 0, 18646, "matcolours", "white", RGBAToARGB(ColorMatchColors[OBJ_WHITE]));
  244.    
  245.     #if defined CM_USEFENCES
  246.     ColorMatchFences[0] = CreateObject(8674, 2005.395, 3871.529,102.859, 0.000, 0.000, 0.000);
  247.     ColorMatchFences[1] = CreateObject(8674, 2000.584, 3866.285,102.859, 0.000, 0.000, 90.000);
  248.     ColorMatchFences[2] = CreateObject(8674, 2010.208, 3866.285,102.859, 0.000, 0.000, 90.000);
  249.     ColorMatchFences[3] = CreateObject(8674, 2005.395, 3861.021,102.859, 0.000, 0.000, 0.000);
  250.    
  251.     ColorMatchFences[4] = CreateObject(8674, 2005.395, 3871.529, 105.809, 0.000, 0.000, 0.000);
  252.     ColorMatchFences[5] = CreateObject(8674, 2000.584, 3866.285, 105.809, 0.000, 0.000, 90.000);
  253.     ColorMatchFences[6] = CreateObject(8674, 2010.208, 3866.285, 105.809, 0.000, 0.000, 90.000);
  254.     ColorMatchFences[7] = CreateObject(8674, 2005.395, 3861.021, 105.809, 0.000, 0.000, 0.000);
  255.     #endif
  256.    
  257.     ColorMatchTD = TextDrawCreate(39.000000, 300.000000, "_");
  258.     TextDrawBackgroundColor(ColorMatchTD, 255);
  259.     TextDrawFont(ColorMatchTD, 2);
  260.     TextDrawLetterSize(ColorMatchTD, 0.260000, 1.400000);
  261.     TextDrawColor(ColorMatchTD, -1);
  262.     TextDrawSetOutline(ColorMatchTD, 1);
  263.     TextDrawSetProportional(ColorMatchTD, 1);
  264.     TextDrawSetSelectable(ColorMatchTD, 0);
  265.    
  266.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++) if(IsPlayerConnected(i)) ColorMatch_InitPlayer(i);
  267.     return 1;
  268. }
  269.  
  270. public OnFilterScriptExit()
  271. {
  272.     for(new i; i < sizeof(ColorMatchObjects); i++) DestroyObject(ColorMatchObjects[i]);
  273.    
  274.     #if defined CM_USEFENCES
  275.     for(new i; i < sizeof(ColorMatchFences); i++) DestroyObject(ColorMatchFences[i]);
  276.     #endif
  277.    
  278.     TextDrawDestroy(ColorMatchTD);
  279.    
  280.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  281.     {
  282.         if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  283.         PlayerTextDrawDestroy(i, ColorText[i]);
  284.         SetPlayerVirtualWorld(i, 0);
  285.         SpawnPlayer(i);
  286.     }
  287.    
  288.     return 1;
  289. }
  290.  
  291. public OnPlayerConnect(playerid)
  292. {
  293.     ColorMatch_InitPlayer(playerid);
  294.     return 1;
  295. }
  296.  
  297. public OnPlayerStateChange(playerid, newstate, oldstate)
  298. {
  299.     ColorMatch_Eliminate(playerid);
  300.     return 1;
  301. }
  302.  
  303. CMD:colormatch(playerid, params[])
  304. {
  305.     if(InCMEvent[playerid]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already in the ColorMatch event.");
  306.     if(ColorMatchStage == STAGE_PLAYING) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't join to the ColorMatch event because it started.");
  307.     if(ColorMatchStage == STAGE_NONE) {
  308.         // init game
  309.         ColorMatchStage = STAGE_SETUP;
  310.         ColorMatchPlayers = 1;
  311.         ColorMatchTimer = SetTimerEx("CM_SetupTimer", 1000, false, "i", CM_SETUP_TIME);
  312.         ColorMatchFallTimer = ColorMatchEventTimer = -1;
  313.         ColorMatch_Arena();
  314.        
  315.         new string[144], name[MAX_PLAYER_NAME];
  316.         GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  317.         format(string, sizeof(string), "[COLORMATCH] {FFFFFF}%s(%d) has started the event. Use {F1C40F}/colormatch {FFFFFF}to join.", name, playerid);
  318.         SendClientMessageToAll(0x3498DBFF, string);
  319.     }else{
  320.         // player join
  321.         if(ColorMatchPlayers >= CM_MAX_PLAYERS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't join to the ColorMatch event because its full.");
  322.         ColorMatchPlayers++;
  323.        
  324.         new string[144], name[MAX_PLAYER_NAME];
  325.         GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  326.         format(string, sizeof(string), "[COLORMATCH] {FFFFFF}%s(%d) has joined the event. Use {F1C40F}/colormatch {FFFFFF}to join. [%d/%d]", name, playerid, ColorMatchPlayers, CM_MAX_PLAYERS);
  327.         SendClientMessageToAll(0x3498DBFF, string);
  328.     }
  329.  
  330.     InCMEvent[playerid] = true;
  331.  
  332.     new Float: x, Float: y, Float: z;
  333.     GetObjectPos(ColorMatchObjects[ random(9) ], x, y, z);
  334.     SetPlayerPos(playerid, x + frandom(1.0, -1.0), y + frandom(1.0, -1.0), z + 1.0);
  335.     SetPlayerVirtualWorld(playerid, 1);
  336.    
  337.     SendClientMessage(playerid, 0x3498DBFF, "[COLORMATCH] {FFFFFF}If you fall off/get stuck during setup time, don't worry because you'll get teleported again once the event begins.");
  338.     return 1;
  339. }
  340.  
  341. forward CM_SetupTimer(time);
  342. public CM_SetupTimer(time)
  343. {
  344.     new string[144], soundid = 1056;
  345.     time--;
  346.    
  347.     if(time < 1) {
  348.         if(ColorMatchPlayers < CM_MIN_PLAYERS) {
  349.             SendClientMessageToAll(0x3498DBFF, "[COLORMATCH] {FFFFFF}Event didn't start because not enough players joined.");
  350.             ColorMatch_CleanUp(1);
  351.             return 1;
  352.         }else{
  353.             ColorMatchStage = STAGE_PLAYING;
  354.             ColorMatchTimer = SetTimer("CM_PickColor", 2000, false);
  355.             ColorMatchFallTimer = SetTimer("CM_FallTimer", 500, true);
  356.             ColorMatchEventTimer = SetTimerEx("CM_EndEvent", 1000, false, "i", CM_EVENT_TIME);
  357.             TextDrawSetString(ColorMatchTD, "_");
  358.            
  359.             format(string, sizeof(string), "~n~~n~~n~~b~~h~~h~Event ~g~~h~Started!");
  360.             soundid = 1057;
  361.         }
  362.     }else{
  363.         format(string, sizeof(string), "~n~~n~~n~~b~~h~~h~Event: ~g~~h~%d", time);
  364.         soundid = 1056;
  365.     }
  366.    
  367.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  368.     {
  369.         if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  370.         PlayerPlaySound(i, soundid, 0.0, 0.0, 0.0);
  371.         GameTextForPlayer(i, string, 1000, 4);
  372.        
  373.         if(time < 1)
  374.         {
  375.             TextDrawShowForPlayer(i, ColorMatchTD);
  376.  
  377.             new Float: x, Float: y, Float: z;
  378.             GetObjectPos(ColorMatchObjects[ random(9) ], x, y, z);
  379.             SetPlayerPos(i, x + frandom(1.0, -1.0), y + frandom(1.0, -1.0), z + 1.0);
  380.            
  381.             #if defined CM_SEPERATE
  382.             SetPlayerVirtualWorld(i, 100 + i);
  383.             #endif
  384.         }
  385.     }
  386.    
  387.     if(time > 0) ColorMatchTimer = SetTimerEx("CM_SetupTimer", 1000, false, "i", time);
  388.     return 1;
  389. }
  390.  
  391. forward CM_FallTimer();
  392. public CM_FallTimer()
  393. {
  394.     if(ColorMatchStage != STAGE_PLAYING) return 1;
  395.     new Float: z;
  396.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  397.     {
  398.         if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  399.         GetPlayerPos(i, z, z, z);
  400.         if(z < 95.0) ColorMatch_Eliminate(i);
  401.     }
  402.    
  403.     return 1;
  404. }
  405.  
  406. forward CM_PickColor();
  407. public CM_PickColor()
  408. {
  409.     if(ColorMatchStage != STAGE_PLAYING) return 1;
  410.     new id = random(sizeof(ColorMatchNames));
  411.     ColorMatchCurrent = id;
  412.  
  413.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  414.     {
  415.         if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  416.         PlayerTextDrawColor(i, ColorText[i], ColorMatchColors[id]);
  417.         PlayerTextDrawSetString(i, ColorText[i], ColorMatchNames[ random(sizeof(ColorMatchNames)) ]);
  418.         PlayerTextDrawShow(i, ColorText[i]);
  419.     }
  420.  
  421.     ColorMatchTimer = SetTimer("CM_MoveObjects", 3000, false);
  422.     return 1;
  423. }
  424.  
  425. forward CM_MoveObjects();
  426. public CM_MoveObjects()
  427. {
  428.     if(ColorMatchStage != STAGE_PLAYING) return 1;
  429.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  430.     {
  431.         if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  432.         PlayerTextDrawColor(i, ColorText[i], 0xFFFFFFFF);
  433.         PlayerTextDrawSetString(i, ColorText[i], "_");
  434.         PlayerTextDrawHide(i, ColorText[i]);
  435.     }
  436.    
  437.     new Float: x, Float: y, Float: z;
  438.     for(new i; i < sizeof(ColorMatchObjects); i++)
  439.     {
  440.         if(i == ColorMatchCurrent) continue;
  441.         GetObjectPos(ColorMatchObjects[i], x, y, z);
  442.         SetObjectPos(ColorMatchObjects[i], x, y, z - 1000.0);
  443.     }
  444.  
  445.     ColorMatchTimer = SetTimer("CM_FixObjects", 3000, false);
  446.     return 1;
  447. }
  448.  
  449. forward CM_FixObjects();
  450. public CM_FixObjects()
  451. {
  452.     if(ColorMatchStage != STAGE_PLAYING) return 1;
  453.     new Float: x, Float: y, Float: z;
  454.     for(new i; i < sizeof(ColorMatchObjects); i++)
  455.     {
  456.         if(i == ColorMatchCurrent) continue;
  457.         GetObjectPos(ColorMatchObjects[i], x, y, z);
  458.         SetObjectPos(ColorMatchObjects[i], x, y, z + 1000.0);
  459.     }
  460.    
  461.     ColorMatchTimer = SetTimer("CM_PickColor", 1000, false);
  462.     return 1;
  463. }
  464.  
  465. forward CM_EndEvent(time);
  466. public CM_EndEvent(time)
  467. {
  468.     if(ColorMatchStage != STAGE_PLAYING) return 1;
  469.     new string[32];
  470.    
  471.     if(time > 1) {
  472.         time--;
  473.        
  474.         format(string, sizeof(string), "Time Left: %s%s", (time > 10) ? ("~y~~h~") : ("~r~~h~"), ConvertToMinutes(time));
  475.         TextDrawSetString(ColorMatchTD, string);
  476.         ColorMatchEventTimer = SetTimerEx("CM_EndEvent", 1000, false, "i", time);
  477.     }else if(time == 1) {
  478.         for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  479.         {
  480.             if(!IsPlayerConnected(i) || !InCMEvent[i]) continue;
  481.             GivePlayerMoney(i, CM_REWARD);
  482.             SendClientMessage(i, 0x3498DBFF, "[COLORMATCH] {FFFFFF}You're all winners!");
  483.         }
  484.        
  485.         SendClientMessageToAll(0x3498DBFF, "[COLORMATCH] {FFFFFF}Event ended.");
  486.         ColorMatch_CleanUp(1);
  487.     }
  488.    
  489.     return 1;
  490. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement