Jay_

Minigame fs handler for lvp

May 23rd, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 40.38 KB | None | 0 0
  1. /**
  2.     Runaway Race! By Jay
  3.  
  4.     Coded for LVP on SA-MP 0.3z - v0.2 of the handler made compatiable with 0.3.7
  5.    
  6.     THIS USES THE GENERIC MINIGAME FS BY JAY
  7.    
  8.     Credits to LR for this map
  9. **/
  10.  
  11. #include    <a_samp>
  12. #include    <streamer>
  13.  
  14.  
  15. // MAP SETTINGS:
  16.  
  17. #define     GAME_WORLD_ID           999     // random virtual world for the game
  18. #define     COUNTDOWN_SECONDS       15      // be careful when adjusting this - should be minimum 15 seconds!
  19.  
  20. // SA-MP default checkpoints don't float - set this to 1 to use a race cp which does float.
  21. #define     USE_RACE_CHECKPOINT     1
  22. // for testing new maps
  23. #define     DEBUG_MODE           0
  24.  
  25. // comment out for no height checking
  26. // otherwise if a player goes below this height he'll go back to the start (or a safe point)
  27. #define     MINIMUM_HEIGHT          60
  28. // Safe points work with minimum height
  29. // Some maps need "safe points" so that the player will teleport back to them if they cross one -
  30. // so they dont go back to the start if they fall below the minimum height distance.
  31. #define     MAX_SAFE_POINTS     20
  32. #define     SAFEPOINT_RANGE     5
  33.  
  34. // This makes the checkpoint only show when the player is in range of it. Comment it out to always show it.
  35. #define     CHECKPOINT_RANGE_CHECK
  36.  
  37. // Makes the game work with only one player
  38. #define     SINGLE_PLAYER_MODE  1
  39.  
  40. /**
  41.     MAP AND GAME CONFIGURATION
  42. **/
  43.    
  44. // url for game music to stream
  45. static  stock   musicUrl[128] = "https://db.tt/2kTyQ9Tz";
  46. // position of end checkpoint
  47. static  stock   Float:endPos[3] = {3897.7725, 2130.9377, 92.3155};
  48. // x, y, z, ang
  49. static  stock   Float:startPos[4] = { 3894.8491,  1908.1697, 71.3759, 0.8247};
  50.  
  51. // Camera Angles when it starts
  52. static  stock   Float:interpolateCamPos[6] = {3900.459228, 1931.925170, 121.677070, 3898.445312, 2158.911376, 99.876800};
  53. static  stock   Float:interpolateCamLookAt[8] = {3894.8491,  1908.1697, 71.3759, 3894.516845, 2090.730468, 110.785514};
  54.  
  55. static  stock   cmdName[10] = "/runrace2";
  56. static  stock   top3CmdName[5] = "/rr2";
  57.  
  58. static  stock   textdrawTitle[23] = "JAYS RUNAWAY RACE ~y~2";
  59. static  stock   textdrawInstructions[74] = "Follow the mystical pathaway!~n~Be the first player to reach the end.";
  60.  
  61. static  stock   gameTitle[64] = "Runaway Race 2";
  62.  
  63. // Database used for storing best times
  64. static  stock   db_name[32] = "runrace2_times.db";
  65. static  stock   db_table[32] = "runrace2_times";
  66.  
  67. // PLEASE NOTE: To configure the map objects, see the CreateDynamicObject statements when the filterscript loads.
  68.  
  69.  
  70.  
  71. /** END OF CONFIG - DONT TOUCH UNLESS YOU KNOW WHAT YOU'RE DOING THANKS **/
  72.  
  73. /** GAME SPECIFIC GLOBAL VARIABLES AND FORWARDS - THESE WHERE DONE BY LR*/
  74. new e1;
  75. new e2;
  76. new c1;
  77. new c2;
  78. new c3;
  79.  
  80. forward e11();
  81. forward e12();
  82. forward e21();
  83. forward e22();
  84. forward c11();
  85. forward c12();
  86. forward c21();
  87. forward c22();
  88. forward c31();
  89. forward c32();
  90.  
  91. // Jay: Original code by LR but I could probably could do with improving this - it can avoid timers
  92. // and use OnObjectMoved
  93.  
  94. //==========================================================
  95. public e11()
  96. {
  97.     StopDynamicObject(e1);
  98.     MoveDynamicObject(e1,3984.434,2087.951,99.5232,2.00);
  99.     SetTimer("e12",13000,0);
  100. }
  101.  
  102. public e12()
  103. {
  104.     StopDynamicObject(e1);
  105.     MoveDynamicObject(e1,3984.434,2087.951,127.202,2.00);
  106.     SetTimer("e11",13000,0);
  107. }
  108. //==========================================================
  109.  
  110. public e21()
  111. {
  112.     StopDynamicObject(e2);
  113.     MoveDynamicObject(e2,3810.168,2084.527,103.2615,2.00);
  114.     SetTimer("e22",13000,0);
  115. }
  116.  
  117. public e22()
  118. {
  119.     StopDynamicObject(e2);
  120.     MoveDynamicObject(e2,3810.168,2084.527,124.408,2.00);
  121.     SetTimer("e21",13000,0);
  122. }
  123. //==========================================================
  124. public c11()
  125. {
  126.     StopDynamicObject(c1);
  127.     MoveDynamicObject(c1,3897.563,2101.253,71.4238,2.00);
  128.     SetTimer("c12",5000,0);
  129. }
  130.  
  131. public c12()
  132. {
  133.     StopDynamicObject(c1);
  134.     MoveDynamicObject(c1,3897.563,2101.253,80.464,2.00);
  135.     SetTimer("c11",5000,0);
  136. }
  137. //==========================================================
  138. public c21()
  139. {
  140.     StopDynamicObject(c2);
  141.     MoveDynamicObject(c2,3897.670,2106.577,71.0000,2.00);
  142.     SetTimer("c22",5000,0);
  143. }
  144.  
  145. public c22()
  146. {
  147.     StopDynamicObject(c2);
  148.     MoveDynamicObject(c2,3897.670,2106.577,80.486,2.00);
  149.     SetTimer("c21",5000,0);
  150. }
  151. //==========================================================
  152. public c31()
  153. {
  154.     StopDynamicObject(c3);
  155.     MoveDynamicObject(c3,3897.675,2112.000,70.6000,2.00);
  156.     SetTimer("c32",5000,0);
  157. }
  158.  
  159. public c32()
  160. {
  161.     StopDynamicObject(c3);
  162.     MoveDynamicObject(c3,3897.675,2112.000,80.583,2.00);
  163.     SetTimer("c31",5000,0);
  164. }
  165.  
  166. // IMPORTANT DEFINES
  167.  
  168. #define     SLOTS                   250     // AKA max_players w/e
  169.  
  170. #define     GAME_STATE_IDLE         0
  171. #define     GAME_STATE_SIGNUP       1
  172. #define     GAME_STATE_RUNNING      2
  173.  
  174. /** HANDLER VARIABLES */
  175.  
  176.  
  177. static  stock   bool:HasPlayerSignedUp[SLOTS];
  178. static  stock   CurrentGameState                        = GAME_STATE_IDLE;
  179. static  stock   bool:HasAnyoneWon                       = false;
  180. static  stock   numberOfPeopleFinished                  = 0;
  181. static  stock   playerStartTimeTicks[SLOTS];
  182.  
  183. static  stock   playerCountdownSeconds[SLOTS]           = COUNTDOWN_SECONDS;
  184. static  stock   playerCountdownTimer[SLOTS]             = {-1, ...};
  185. static  stock   playerCheckpointRangeTimer[SLOTS]       = {-1, ...};
  186. static  stock   playerTimeUpdateTimer[SLOTS]            = {-1, ...};
  187. static  stock   playerHeightCheckTimer[SLOTS]           = {-1, ...};
  188. static  stock   playerSafePointTimer[SLOTS]             = {-1, ...};
  189.  
  190. static  stock   safePoints[MAX_SAFE_POINTS][3];
  191. static  stock   Text3D:safePointText[MAX_SAFE_POINTS]   = {Text3D:-1, ...};
  192. static  stock   playerLastSafePoint[SLOTS]              = {-1, ...};
  193. static  stock   safePointCount                          = 0;
  194.  
  195. // for the cmd to show the top 3
  196. static  stock   bool:isTop3Showing[SLOTS];
  197.  
  198. // track objects to delete them when the FS is unloaded
  199. static  stock   mapObjects[2];
  200. static  stock   gateObject = INVALID_OBJECT_ID;
  201.  
  202. // Note: THIS IS NOT a config option - dont amend it please.
  203. static  stock   bool:UseDatabase = true;
  204.  
  205. // textdraws
  206. new Text:title;
  207. new Text:instructions;
  208. new Text:signup;
  209. new Text:getReady;
  210. new Text:countdown;
  211. new Text:endTitle;
  212. new Text:top3Times;
  213. new Text:top3timesTitle;
  214. new PlayerText:endInfo[SLOTS] = {PlayerText:INVALID_TEXT_DRAW, ...};
  215. new PlayerText:yourTime[SLOTS] = {PlayerText:INVALID_TEXT_DRAW, ...};
  216.  
  217.  
  218. // Keep track of the top 3 entries
  219. new     Top3Times[3];   // UNIX MS
  220. new     Top3Names[3][MAX_PLAYER_NAME];
  221.  
  222.  
  223. /*// LVP uses an outdated streamer - need this hack in for an extra param
  224. #if DEBUG_MODE == 1
  225.     native CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 1200.0, Float:bla=2000.0);
  226. #else
  227.     native CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 1200.0);
  228. #endif
  229. */
  230. public OnFilterScriptInit()
  231. {
  232.  
  233.     #if DEBUG_MODE == 0
  234.         SetTimer("promo", 12*1000*60, 1);
  235.         new str[128];
  236.         SendClientMessageToAll(-1, "-----------");
  237.         format(str, 128, "%s by Jay has been loaded on the server!", gameTitle);
  238.         SendClientMessageToAll(-1, str);
  239.         SendClientMessageToAll(-1, cmdName);
  240.         SendClientMessageToAll(-1, "----------");
  241.     #else
  242.         printf("----------------------------");
  243.         printf("Jay's Minigame Filterscript DEBUG BUILD loaded");
  244.         printf("----------------------------");
  245.     #endif
  246.  
  247.    
  248.     if(!fexist(db_name))
  249.     {
  250.         initDb();
  251.     }
  252.    
  253.     updateBestPlayersAndTimes();
  254.     SetTimer("CheckGameEnd", 2000, 1);
  255.    
  256.     title = TextDrawCreate(187.000000, 162.000000, textdrawTitle);
  257.     TextDrawBackgroundColor(title, 255);
  258.     TextDrawFont(title, 2);
  259.     TextDrawLetterSize(title, 0.700000, 3.199999);
  260.     TextDrawColor(title, -1);
  261.     TextDrawSetOutline(title, 0);
  262.     TextDrawSetProportional(title, 1);
  263.     TextDrawSetShadow(title, 1);
  264.  
  265.     instructions = TextDrawCreate(166.000000, 195.000000, textdrawInstructions);
  266.     TextDrawBackgroundColor(instructions, 255);
  267.     TextDrawFont(instructions, 1);
  268.     TextDrawLetterSize(instructions, 0.580000, 2.300000);
  269.     TextDrawColor(instructions, -1);
  270.     TextDrawSetOutline(instructions, 0);
  271.     TextDrawSetProportional(instructions, 1);
  272.     TextDrawSetShadow(instructions, 1);
  273.  
  274.     getReady = TextDrawCreate(247.000000, 247.000000, "GET READY!");
  275.     TextDrawBackgroundColor(getReady, 255);
  276.     TextDrawFont(getReady, 3);
  277.     TextDrawLetterSize(getReady, 0.839999, 3.000000);
  278.     TextDrawColor(getReady, -1);
  279.     TextDrawSetOutline(getReady, 0);
  280.     TextDrawSetProportional(getReady, 1);
  281.     TextDrawSetShadow(getReady, 1);
  282.  
  283.     countdown = TextDrawCreate(297.000000, 279.000000, "_");
  284.     TextDrawBackgroundColor(countdown, 255);
  285.     TextDrawFont(countdown, 3);
  286.     TextDrawLetterSize(countdown, 1.000000, 4.199999);
  287.     TextDrawColor(countdown, -1);
  288.     TextDrawSetOutline(countdown, 0);
  289.     TextDrawSetProportional(countdown, 1);
  290.     TextDrawSetShadow(countdown, 1);
  291.    
  292.     format(str, 128, "MINIGAME: JAY'S %s~n~Use ~y~%s~w~ to signup now! ~n~See if you can make the ~r~%s~w~!", gameTitle, cmdName, top3CmdName);
  293.     signup = TextDrawCreate(19.000000, 258.000000, str);
  294.     TextDrawBackgroundColor(signup, 255);
  295.     TextDrawFont(signup, 1);
  296.     TextDrawLetterSize(signup, 0.490000, 2.000000);
  297.     TextDrawColor(signup, -1);
  298.     TextDrawSetOutline(signup, 0);
  299.     TextDrawSetProportional(signup, 1);
  300.     TextDrawSetShadow(signup, 1);
  301.    
  302.     format(str, 128, "Jay's %s", gameTitle);
  303.     endTitle = TextDrawCreate(224.000000, 155.000000, str);
  304.     TextDrawBackgroundColor(endTitle, 255);
  305.     TextDrawFont(endTitle, 1);
  306.     TextDrawLetterSize(endTitle, 0.750000, 3.099999);
  307.     TextDrawColor(endTitle, -1);
  308.     TextDrawSetOutline(endTitle, 0);
  309.     TextDrawSetProportional(endTitle, 1);
  310.     TextDrawSetShadow(endTitle, 1);
  311.  
  312.     top3Times = TextDrawCreate(35.000000, 274.000000, "~y~TOP 3 TIMES:~n~~w~~r~#1~w~ Jay: 1:23~n~~r~#2~w~ Chris: 2:32~n~~r~#3~w~ Tom: 3:11");
  313.     TextDrawBackgroundColor(top3Times, 255);
  314.     TextDrawFont(top3Times, 1);
  315.     TextDrawLetterSize(top3Times, 0.370000, 1.400000);
  316.     TextDrawColor(top3Times, -1);
  317.     TextDrawSetOutline(top3Times, 0);
  318.     TextDrawSetProportional(top3Times, 1);
  319.     TextDrawSetShadow(top3Times, 1);
  320.    
  321.     format(str, 128, "Jay's %s", gameTitle);
  322.     top3timesTitle = TextDrawCreate(34.000000, 234.000000, str);
  323.     TextDrawBackgroundColor(top3timesTitle, 255);
  324.     TextDrawFont(top3timesTitle, 2);
  325.     TextDrawLetterSize(top3timesTitle, 0.340000, 1.600000);
  326.     TextDrawColor(top3timesTitle, -1);
  327.     TextDrawSetOutline(top3timesTitle, 0);
  328.     TextDrawSetProportional(top3timesTitle, 1);
  329.     TextDrawSetShadow(top3timesTitle, 1);
  330.    
  331.     // Load the object map and any specific timers etc for it
  332.     // credits to lr for these:
  333.  
  334.     SetTimer("e11",1000,0);
  335.     SetTimer("e21",1000,0);
  336.     SetTimer("c11",1000,0);
  337.     SetTimer("c21",5000,0);
  338.     SetTimer("c31",3000,0);
  339.  
  340.     mapObjects[0] = CreateDynamicObject(4002,3891.865,2013.299,20.300,0.0,0.0,0.0);
  341.     e1=CreateDynamicObject(2669,3984.434,2087.951,127.202,0.0,0.0,88.522);
  342.     e2=CreateDynamicObject(2669,3810.168,2084.527,124.408,0.0,0.0,270.000);
  343.     c1=CreateDynamicObject(3565,3897.563,2101.253,80.464,0.0,0.0,0.0);
  344.     c2=CreateDynamicObject(3565,3897.670,2106.577,80.486,0.0,0.0,0.0);
  345.     c3=CreateDynamicObject(3565,3897.675,2112.000,80.583,0.0,0.0,0.0);
  346.     CreateDynamicObject(18367,3893.207,2046.068,116.156,0.0,0.0,0.0);
  347.     CreateDynamicObject(1428,3893.113,2045.830,117.637,-36.096,0.0,0.0);
  348.     CreateDynamicObject(18367,3893.131,2049.135,119.926,0.0,0.0,180.000);
  349.     CreateDynamicObject(1428,3893.117,2047.865,119.294,-33.518,0.0,0.0);
  350.     CreateDynamicObject(17068,3893.217,2090.855,123.578,0.0,0.0,0.0);
  351.     CreateDynamicObject(17068,3893.224,2112.767,123.572,0.0,0.0,0.0);
  352.     CreateDynamicObject(3632,3891.938,2078.897,124.146,0.0,0.0,0.0);
  353.     CreateDynamicObject(3632,3893.231,2078.904,124.147,0.0,0.0,0.0);
  354.     CreateDynamicObject(3632,3893.845,2078.882,124.144,0.0,0.0,0.0);
  355.     CreateDynamicObject(3632,3892.573,2078.919,124.149,0.0,0.0,0.0);
  356.     CreateDynamicObject(3632,3894.433,2078.876,124.144,0.0,0.0,0.0);
  357.     CreateDynamicObject(980,3892.971,2080.429,126.296,-0.859,-89.381,0.0);
  358.     CreateDynamicObject(3800,3892.858,2079.867,124.533,0.0,0.0,0.0);
  359.     CreateDynamicObject(3800,3895.200,2079.901,127.014,0.0,0.0,0.0);
  360.     CreateDynamicObject(3800,3890.754,2079.876,127.042,0.0,0.0,0.0);
  361.     CreateDynamicObject(3800,3892.990,2079.895,129.952,0.0,0.0,0.0);
  362.     CreateDynamicObject(3800,3892.957,2081.054,130.982,0.0,0.0,0.0);
  363.     CreateDynamicObject(3800,3891.240,2081.093,131.004,0.0,0.0,0.0);
  364.     CreateDynamicObject(3800,3895.010,2081.094,130.936,0.0,0.0,0.0);
  365.     CreateDynamicObject(3502,3893.225,2089.230,132.547,-24.064,1.719,-0.232);
  366.     CreateDynamicObject(9919,3893.687,1916.474,6.990,0.0,0.0,90.000);
  367.     CreateDynamicObject(9766,3894.403,1972.374,89.026,27.502,0.0,0.0);
  368.     CreateDynamicObject(1653,3907.479,2133.804,124.581,-89.381,0.0,0.0);
  369.     CreateDynamicObject(1653,3876.365,2132.839,124.302,-90.241,0.0,0.859);
  370.     CreateDynamicObject(1653,3919.172,2130.843,124.578,-90.241,-10.313,-37.970);
  371.     CreateDynamicObject(1653,3865.161,2136.240,124.328,-90.241,0.0,144.531);
  372.     CreateDynamicObject(13604,3893.671,2126.914,125.425,0.0,0.0,0.0);
  373.     CreateDynamicObject(1653,3859.520,2134.055,124.326,-90.241,-11.173,-109.690);
  374.     CreateDynamicObject(1653,3923.910,2133.732,124.557,-90.241,-17.189,74.453);
  375.     CreateDynamicObject(1653,3919.117,2136.832,124.578,-90.241,-8.594,20.626);
  376.     CreateDynamicObject(1653,3864.315,2130.270,124.325,-89.381,0.0,22.500);
  377.     CreateDynamicObject(16481,3837.345,2133.266,126.392,0.859,7.735,180.000);
  378.     CreateDynamicObject(16481,3798.851,2133.272,134.517,0.0,0.0,180.000);
  379.     CreateDynamicObject(16481,3945.796,2133.991,127.178,0.0,6.016,0.0);
  380.     CreateDynamicObject(16481,3984.141,2134.092,135.767,0.0,0.0,0.0);
  381.     CreateDynamicObject(4106,4003.259,2125.426,151.362,0.859,0.0,-176.108);
  382.     CreateDynamicObject(18553,4001.386,2141.232,144.605,0.0,0.0,2.578);
  383.     CreateDynamicObject(18553,4001.306,2142.823,146.283,0.0,0.0,2.578);
  384.     CreateDynamicObject(4106,3782.671,2123.675,148.765,0.0,0.0,180.000);
  385.     CreateDynamicObject(18553,3781.459,2140.064,142.700,0.0,0.0,0.0);
  386.     CreateDynamicObject(18553,3781.420,2141.282,144.249,2.578,0.0,0.077);
  387.     CreateDynamicObject(3798,3783.680,2092.647,148.250,0.0,0.0,0.0);
  388.     CreateDynamicObject(3798,3783.684,2090.731,146.326,0.0,0.0,0.0);
  389.     CreateDynamicObject(3798,4006.381,2094.526,151.305,0.0,0.0,4.297);
  390.     CreateDynamicObject(3798,4006.576,2092.531,149.356,0.0,0.0,3.438);
  391.     CreateDynamicObject(10009,4007.498,2082.917,139.977,0.0,0.0,92.742);
  392.     CreateDynamicObject(10009,4011.104,2083.542,131.184,0.0,0.0,133.445);
  393.     CreateDynamicObject(1383,3984.386,2089.960,105.082,0.0,0.0,0.0);
  394.     CreateDynamicObject(16318,3966.972,2088.953,90.881,0.0,0.0,2.578);
  395.     CreateDynamicObject(10009,3784.280,2082.033,137.743,0.0,0.0,-270.723);
  396.     CreateDynamicObject(10009,3783.339,2088.013,128.315,0.0,0.0,-45.000);
  397.     CreateDynamicObject(1383,3810.052,2082.515,104.275,0.0,0.0,0.0);
  398.     CreateDynamicObject(16318,3828.514,2083.117,90.994,0.0,0.0,-178.281);
  399.     CreateDynamicObject(16501,3852.474,2083.917,86.037,0.0,0.0,91.719);
  400.     CreateDynamicObject(16501,3859.496,2084.146,86.025,0.0,0.0,91.719);
  401.     CreateDynamicObject(16501,3866.377,2084.353,86.009,0.0,0.0,91.719);
  402.     CreateDynamicObject(16501,3872.436,2084.550,86.866,0.0,-89.381,90.859);
  403.     CreateDynamicObject(16501,3943.018,2087.978,85.943,0.0,0.0,92.578);
  404.     CreateDynamicObject(16501,3935.968,2087.667,85.948,0.0,0.0,92.578);
  405.     CreateDynamicObject(16501,3928.946,2087.345,85.931,0.0,0.0,92.578);
  406.     CreateDynamicObject(16501,3922.959,2087.137,86.811,0.0,-90.241,91.246);
  407.     CreateDynamicObject(1214,4008.041,2086.609,128.564,0.0,0.0,0.0);
  408.     CreateDynamicObject(1214,4003.939,2086.606,129.082,0.0,0.0,0.0);
  409.     CreateDynamicObject(1214,3999.752,2086.605,129.670,0.0,0.0,0.0);
  410.     CreateDynamicObject(1214,3995.376,2086.620,130.151,0.0,0.0,0.0);
  411.     CreateDynamicObject(1214,3991.424,2086.608,130.786,0.0,0.0,0.0);
  412.     CreateDynamicObject(1214,3786.153,2084.786,125.654,0.0,0.0,0.0);
  413.     CreateDynamicObject(1214,3790.359,2084.810,126.335,0.0,0.0,0.0);
  414.     CreateDynamicObject(1214,3794.634,2084.797,127.000,0.0,0.0,0.0);
  415.     CreateDynamicObject(1214,3799.078,2084.784,127.613,0.0,0.0,0.0);
  416.     CreateDynamicObject(1214,3803.177,2084.778,128.192,0.0,0.0,0.0);
  417.     CreateDynamicObject(16501,3878.103,2081.006,83.841,17.189,0.0,56.250);
  418.     CreateDynamicObject(16501,3883.221,2077.602,81.934,17.189,0.0,56.173);
  419.     CreateDynamicObject(16501,3888.874,2073.831,79.845,17.189,0.0,56.250);
  420.     CreateDynamicObject(16501,3894.422,2070.117,77.738,18.048,0.0,56.250);
  421.     CreateDynamicObject(16501,3917.516,2083.142,83.738,18.048,0.0,-48.515);
  422.     CreateDynamicObject(16501,3912.615,2078.798,81.595,18.048,0.0,-48.438);
  423.     CreateDynamicObject(16501,3907.610,2074.365,79.428,18.048,0.0,-48.515);
  424.     CreateDynamicObject(16501,3902.782,2070.091,77.460,15.470,0.0,-48.515);
  425.     CreateDynamicObject(16501,3898.700,2068.369,77.900,0.0,-91.100,0.0);
  426.     CreateDynamicObject(3502,3898.668,2074.936,79.484,0.0,0.0,-180.000);
  427.     CreateDynamicObject(3502,3898.740,2083.128,79.808,-4.297,0.0,179.141);
  428.     CreateDynamicObject(3502,3898.792,2091.243,80.429,-4.297,-0.859,180.000);
  429.     CreateDynamicObject(1228,3892.465,2136.665,127.515,0.0,0.0,92.578);
  430.     CreateDynamicObject(1225,3894.154,2136.677,127.550,0.0,0.0,11.250);
  431.     CreateDynamicObject(1225,3890.719,2136.545,127.550,0.0,0.0,0.0);
  432.     CreateDynamicObject(1318,3890.762,2135.976,127.643,-91.100,0.0,-68.359);
  433.     CreateDynamicObject(1318,3894.251,2136.068,127.643,-90.241,0.0,67.500);
  434.     CreateDynamicObject(1323,3892.439,2136.792,128.204,0.0,0.0,-90.000);
  435.     CreateDynamicObject(18553,3781.546,2137.573,142.755,0.0,-88.522,-0.859);
  436.     CreateDynamicObject(18553,3781.584,2136.337,141.564,0.859,-89.381,88.281);
  437.     CreateDynamicObject(18553,4001.249,2139.573,144.655,-179.623,90.241,2.682);
  438.     CreateDynamicObject(18553,4001.174,2137.633,143.032,0.859,-91.100,273.438);
  439.     CreateDynamicObject(13644,3892.755,2119.930,85.033,0.0,0.0,179.691);
  440.     CreateDynamicObject(13644,3903.010,2119.968,85.020,0.0,0.0,0.0);
  441.     CreateDynamicObject(1660,3901.557,2131.104,88.512,0.0,0.0,90.000);
  442.     CreateDynamicObject(1660,3893.857,2130.736,88.550,-1.719,0.0,-90.000);
  443.     CreateDynamicObject(1271,3898.568,2096.698,80.144,0.0,0.0,0.0);
  444.     CreateDynamicObject(1271,3898.568,2095.987,79.482,0.0,0.0,0.0);
  445.     CreateDynamicObject(944,3898.608,2098.486,81.325,0.0,0.0,90.000);
  446.     CreateDynamicObject(16782,3898.591,2070.301,82.203,0.0,0.0,-90.000);
  447.     CreateDynamicObject(11544,3892.837,2129.849,92.317,17.189,0.0,0.0);
  448.     mapObjects[1] =     CreateDynamicObject(11544,3902.764,2129.844,92.122,16.329,0.0,0.0);
  449.    
  450.     // add safe points
  451.     addSafePoint(3893.449951, 2013.427612, 121.029891);
  452.     addSafePoint(3892.882812, 2133.415771, 128.151565);
  453.     addSafePoint(3781.525390, 2133.100830, 140.722702);
  454.     addSafePoint(4001.285888, 2133.947265, 142.207702);
  455.     addSafePoint(4006.360107, 2095.140625, 154.308441);
  456.     addSafePoint(3783.977294, 2093.059326, 151.900924);
  457.     addSafePoint(3821.826416, 2082.979980, 95.346641);
  458.     addSafePoint(3973.439453, 2089.391601, 94.753097);
  459.    
  460.     // put all the objects in the correct world.
  461.     for(new i = mapObjects[0]; i < mapObjects[1]+1; i++)
  462.     {
  463.         Streamer_SetIntData(STREAMER_TYPE_OBJECT, i, E_STREAMER_WORLD_ID, GAME_WORLD_ID);
  464.     }
  465.     return 1;
  466. }
  467.  
  468. public OnGameModeInit() {
  469.     // re-initialise this when the gamemode restarts
  470.     // todo: remove hardcoded name
  471.     SendRconCommand("reloadfs jay_runaway2");
  472. }
  473.  
  474. forward promo();
  475. public promo()
  476. {
  477.     SendClientMessageToAll(-1, "---------------------------------");
  478.     new str[128];
  479.     format(str, 128, "Jay's %s - See if you can make the {00FF00}%s!!", gameTitle, top3CmdName);
  480.     SendClientMessageToAll(-1, str);
  481.     format(str, 128, "Use %s to start the game.", cmdName);
  482.     SendClientMessageToAll(-1, str);
  483.     SendClientMessageToAll(-1, "---------------------------------");
  484.  
  485. }
  486.  
  487. stock initDb()
  488. {
  489.     // create the file first
  490.     new File:create = fopen(db_name);
  491.     fclose(create);
  492.    
  493.     // Ok now init the database
  494.     new DB:db_best_times = db_open(db_name);
  495.     new DBResult:result;
  496.    
  497.     // TODO: Sort hardcoded runrace_times here!!!
  498.    
  499.     result = db_query(db_best_times, "CREATE TABLE `runrace_times` (\
  500.     `Id`    INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\
  501.     `PlayerName`    TEXT NOT NULL,\
  502.     `Time`  INTEGER NOT NULL,\
  503.    `Timestamp` DATETIME DEFAULT CURRENT_TIMESTAMP);");
  504.  
  505.     if(result != DBResult:0)
  506.     {
  507.         printf("Initialised Database Successfully for Jay's %s", gameTitle);
  508.     }
  509.     else
  510.     {
  511.         UseDatabase = false;
  512.         printf("WARNING: Failed to initialise database for Jay's %s", gameTitle);
  513.     }
  514.    
  515.     db_close(db_best_times);
  516. }
  517.  
  518. stock insertDbRecord(PlayerName[], playerTime)
  519. {
  520.     if(!fexist(db_name))
  521.         initDb();
  522.  
  523.     if(UseDatabase == false)
  524.     {
  525.         printf("Unable to save game data for Jay's %s for player: %s with time: %d as the database has an error.", gameTitle, PlayerName, playerTime);
  526.         return;
  527.     }
  528.  
  529.     new DB:db_best_times = db_open(db_name);
  530.     new DBResult:result;
  531.    
  532.     new str[128];
  533.     format(str, 128, "INSERT INTO %s (PlayerName, Time) VALUES('%s', %d);", db_table, PlayerName, playerTime);
  534.     result = db_query(db_best_times, str);
  535.    
  536.     if(result != DBResult:0)
  537.     {
  538.         printf("Successfully added data for player %s to database for Jay's %s", PlayerName, gameTitle);
  539.     }
  540.     else
  541.     {
  542.         UseDatabase = false;
  543.         printf("WARNING: Error occured when attempting to add data for player %s playing Jay's %s", PlayerName, gameTitle);
  544.     }
  545.     db_close(db_best_times);
  546. }
  547.  
  548. stock updateBestPlayersAndTimes()
  549. {
  550.     // Database doesn't exist - initialise it and stop here
  551.     // since there can't possibly be any data to retrieve at this point
  552.     if(!fexist(db_name)) {
  553.         initDb();
  554.         return;
  555.     }
  556.  
  557.     if(UseDatabase == false)
  558.         return;
  559.    
  560.     new DB:db_best_times = db_open(db_name);
  561.     new DBResult:result;
  562.  
  563.     new str[128];
  564.     format(str, 128, "SELECT * FROM %s ORDER BY Time LIMIT 3;", db_table);
  565.     result = db_query(db_best_times, str);
  566.     if(db_num_rows(result) == 3)
  567.     {
  568.         new timeStr[128];
  569.         new i = 0;
  570.         do
  571.         {
  572.             db_get_field_assoc(result, "PlayerName", Top3Names[i], MAX_PLAYER_NAME);
  573.             db_get_field_assoc(result, "Time", timeStr, 128);
  574.             Top3Times[i] = strval(timeStr);
  575.             i++;
  576.         }
  577.         while(db_next_row(result));
  578.  
  579.         format(str, 128, "~y~TOP 3 TIMES:~n~~w~~r~#1~w~ %s: %s~n~~r~#2~w~ %s: %s~n~~r~#3~w~ %s: %s",
  580.             Top3Names[0], FormatTime(Top3Times[0]),
  581.             Top3Names[1], FormatTime(Top3Times[1]),
  582.             Top3Names[2], FormatTime(Top3Times[2]));
  583.            
  584.         TextDrawSetString(top3Times, str);
  585.     }
  586.     else
  587.     {
  588.         printf("Only found %d entries in database. Needs to be at least 3.", db_num_rows(result));
  589.     }
  590.     db_close(db_best_times);
  591.    
  592.    
  593.    
  594. }
  595.  
  596. // debug
  597. stock DisplayTop3()
  598. {
  599.     printf("TOP 3 STORED RESULTS:");
  600.     for(new i =0 ; i < 3; i++)
  601.     {
  602.         printf("Name: %s Time: %d", Top3Names[i], Top3Times[i]);
  603.     }
  604. }
  605.  
  606. public OnFilterScriptExit()
  607. {
  608.     #if DEBUG_MODE == 0
  609.         new str[128];
  610.         format(str, 128, "Jay's %s has been unloaded from the server.", gameTitle);
  611.         SendClientMessageToAll(-1, str);
  612.         SendClientMessageToAll(-1, "SEE YOU NEXT TIME!");
  613.     #endif
  614.  
  615.     EndGame();
  616.  
  617.     for(new i = mapObjects[0]; i < mapObjects[1]; i++)
  618.     {
  619.         DestroyDynamicObject(i);
  620.         DestroyDynamicObject(gateObject);
  621.     }
  622.     RemoveSafePointTexts();
  623. }
  624.  
  625. // Reset some data when the player leaves
  626. public OnPlayerDisconnect(playerid, reason)
  627. {
  628.     if(playerid >= SLOTS) {
  629.         new str[128];
  630.         format(str, 128, "Unloading Jay's Runaway race because the maximum number of slots (%d) have been exceeded.", SLOTS);
  631.         print(str);
  632.         SendClientMessageToAll(-1, str);
  633.         SendRconCommand("unloadfs jay_runaway");
  634.         return 1;
  635.     }
  636.  
  637.     #pragma unused reason
  638.     RemovePlayerFromGame(playerid);
  639.     return 1;
  640. }
  641.  
  642.  
  643. stock bool:IsPlayerSignedUp(playerid)
  644. {
  645.     if(IsPlayerConnected(playerid)) {
  646.         if(HasPlayerSignedUp[playerid] == true) {
  647.             return true;
  648.         }
  649.     }
  650.     return false;
  651. }
  652.  
  653.  
  654.  
  655. public OnPlayerCommandText(playerid, cmdtext[])
  656. {
  657.     #if DEBUG_MODE == 1
  658.         if(strcmp(cmdtext,"/savepos",true)==0)
  659.         {
  660.             new string[128], string2[64], Float:X, Float:Z, Float:Y, Float:ang;
  661.             GetPlayerPos(playerid, X, Y, Z);
  662.             GetPlayerFacingAngle(playerid, ang);
  663.             format(string, sizeof(string), "%f, %f, %f, %f //%s \r\n", X, Y, Z, ang, cmdtext[9]);
  664.             new entry[256];
  665.             format(entry, sizeof(entry), "%s\r\n",string);
  666.             new File:hFile;
  667.             hFile = fopen("SavedPos2.txt", io_append);
  668.             if (hFile)
  669.             {
  670.                 fwrite(hFile, entry);
  671.                 fclose(hFile);
  672.                 format(string2, sizeof(string2),"Player Pos Should Be Saved. With comment: %s", cmdtext[9]);
  673.                 SendClientMessage(playerid, -1,string2);
  674.             }
  675.             return 1;
  676.         }
  677.         else if(!strcmp(cmdtext, "/runfinish", true) && IsPlayerAdmin(playerid))
  678.         {
  679.             SendClientMessage(playerid, -1, "Teleported you to the end pos.");
  680.             SetPlayerPos(playerid, endPos[0], endPos[1], endPos[2]);
  681.             return 1;
  682.         }
  683.  
  684.  
  685.         else if(!strcmp(cmdtext, "/show3", true) && IsPlayerAdmin(playerid))
  686.         {
  687.             updateBestPlayersAndTimes();
  688.             DisplayTop3();
  689.             return 1;
  690.         }
  691.         else if(!strcmp(cmdtext, "/gotogame", true) && IsPlayerAdmin(playerid))
  692.         {
  693.             TeleportPlayerToGame(playerid);
  694.             return 1;
  695.         }
  696.     #endif
  697.  
  698.     if(!strcmp(cmdtext, cmdName, true))
  699.     {
  700.         if(CurrentGameState == GAME_STATE_RUNNING)
  701.         {
  702.             SendClientMessage(playerid, -1, "{FF0000}The game is already running try later.");
  703.             return 1;
  704.         }
  705.  
  706.         HasPlayerSignedUp[playerid] = true;
  707.  
  708.         if(CurrentGameState == GAME_STATE_IDLE)
  709.         {
  710.             StartGame();
  711.         }
  712.         new str[128];
  713.         format(str, 128, "{00FF00}You have signed up for Jay's %s. It's starting soon. Use /leave to leave", gameTitle);
  714.         SendClientMessage(playerid, -1, str);
  715.         return 1;
  716.     }
  717.    
  718.     else if(!strcmp(cmdtext, top3CmdName, true))
  719.     {
  720.         if(isTop3Showing[playerid] == true)
  721.         {
  722.             TextDrawHideForPlayer(playerid, top3Times);
  723.             isTop3Showing[playerid] = false;
  724.         }
  725.         else
  726.         {
  727.             TextDrawShowForPlayer(playerid, top3Times);
  728.             isTop3Showing[playerid] = true;
  729.         }
  730.         return 1;
  731.     }
  732.     else if(!strcmp(cmdtext, "/leave", true))
  733.     {
  734.         if(IsPlayerSignedUp(playerid) == true)
  735.         {
  736.             RemovePlayerFromGame(playerid);
  737.            
  738.             new str[128];
  739.             format(str, 128, "You have left Jay's %s", gameTitle);
  740.             SendClientMessage(playerid, -1, str);
  741.             return 1;
  742.         }
  743.         return 0;
  744.     }
  745.  
  746.     else if(IsPlayerSignedUp(playerid) && CurrentGameState == GAME_STATE_IDLE)
  747.     {
  748.         new str[128];
  749.         format(str, 128, "You can't use commands whilst taking part in Jay's %s", gameTitle);
  750.         SendClientMessage(playerid, -1, str);
  751.         return 1;
  752.     }
  753.    
  754.     return 0;
  755. }
  756.  
  757. /**
  758. * Check every two seconds if the game is running
  759. * check to end it in case no players are left
  760. **/
  761. forward CheckGameEnd();
  762. public CheckGameEnd()
  763. {
  764.     if(CurrentGameState == GAME_STATE_RUNNING)
  765.     {
  766.         new numberOfSignups = 0;
  767.    
  768.         for(new i = 0; i < SLOTS; i++)
  769.         {
  770.             if(!IsPlayerConnected(i) || IsPlayerNPC(i))
  771.                 continue;
  772.  
  773.             if(IsPlayerSignedUp(i) == false)
  774.                 continue;
  775.  
  776.             numberOfSignups++;
  777.         }
  778.        
  779.         if(numberOfSignups == 0)
  780.         {
  781.             new str[128];
  782.             format(str, 128, "Jay's %s has ended: there is nobody left!", gameTitle);
  783.             SendClientMessageToAll(-1, str);
  784.             EndGame();
  785.         }
  786.     }
  787. }
  788.  
  789.  
  790. forward StartGame();
  791. public StartGame()
  792. {
  793.     // Game is idle - enter signup phase
  794.     if(CurrentGameState == GAME_STATE_IDLE)
  795.     {
  796.         TextDrawShowForAll(signup);
  797.         CurrentGameState = GAME_STATE_SIGNUP;
  798.        
  799.         #if DEBUG_MODE == 0
  800.             new str[128];
  801.             SendClientMessageToAll(-1, "-------------");
  802.  
  803.             format(str, 128, "Jay's %s is now signing up.", gameTitle);
  804.             SendClientMessageToAll(-1, str);
  805.             format(str, 128, "Use %s to join the game. Starting in 20 seconds.", cmdName);
  806.             SendClientMessageToAll(-1, str);
  807.             SendClientMessageToAll(-1, "------------");
  808.  
  809.             format(str, 128, "~y~Jay's %s~n~~w~Use ~r~%s~w~!!",gameTitle, cmdName);
  810.             GameTextForAll(str, 5000, 5);
  811.             SetTimer("StartGame", 20*1000, 0);
  812.         #else
  813.             SetTimer("StartGame", 1000, 0);
  814.         #endif
  815.         return;
  816.     }
  817.  
  818.     // Game is not idle - start it!
  819.  
  820.     TextDrawHideForAll(signup);
  821.  
  822.     new numberOfSignups = 0;
  823.  
  824.     for(new i = 0; i < SLOTS; i++)
  825.     {
  826.         if(!IsPlayerConnected(i) || IsPlayerNPC(i))
  827.             continue;
  828.        
  829.         if(IsPlayerSignedUp(i) == false)
  830.             continue;
  831.        
  832.         numberOfSignups++;
  833.     }
  834.     #if SINGLE_PLAYER_MODE == 0
  835.         // not enough people signed up.
  836.         if(numberOfSignups < 2)
  837.         {
  838.             new str[128];
  839.             format(str, 128, "Not enough people have signed up for Jay's %s :(", gameTitle);
  840.             SendClientMessageToAll(-1, str);
  841.             EndGame();
  842.             return;
  843.         }
  844.     #endif
  845.  
  846.     // Ok now loop through the signups again and start this fucker.
  847.     for(new i = 0; i < SLOTS; i++)
  848.     {
  849.         if(!IsPlayerConnected(i) || IsPlayerNPC(i))
  850.             continue;
  851.  
  852.         if(IsPlayerSignedUp(i) == false)
  853.             continue;
  854.  
  855.         ResetPlayerWeapons(i);
  856.  
  857.         #if !defined CHECKPOINT_RANGE_CHECk
  858.             #if USE_RACE_CHECKPOINT == 1
  859.                 SetPlayerRaceCheckpoint(i, 1, endPos[0], endPos[1], endPos[2], 0, 0, 0, 5.0);
  860.             #else
  861.                 SetPlayerCheckpoint(i, endPos[0], endPos[1], endPos[2], 5.0);
  862.             #endif
  863.         #endif
  864.        
  865.         TeleportPlayerToGame(i);
  866.         InterpolateCameraPos(i, interpolateCamPos[0], interpolateCamPos[1], interpolateCamPos[2], interpolateCamPos[3], interpolateCamPos[4], interpolateCamPos[5], 5000, CAMERA_MOVE);
  867.         InterpolateCameraLookAt(i, interpolateCamLookAt[0], interpolateCamLookAt[1], interpolateCamLookAt[2], interpolateCamLookAt[3], interpolateCamLookAt[4], interpolateCamLookAt[5], 5000, CAMERA_MOVE);
  868.  
  869.  
  870.         Streamer_Update(i);
  871.        
  872.         playerCountdownSeconds[i] = COUNTDOWN_SECONDS;
  873.        
  874.         TogglePlayerControllable(i, 0);
  875.  
  876.         playerCountdownTimer[i] = SetTimerEx("processGame", 1000, 1, "d", i);
  877.     }
  878.    
  879.     updateBestPlayersAndTimes();
  880.     HasAnyoneWon = false;
  881.     CurrentGameState = GAME_STATE_RUNNING;
  882.     numberOfPeopleFinished = 0;
  883. }
  884.  
  885. forward processGame(playerid);
  886. public processGame(playerid)
  887. {
  888.     if(playerCountdownSeconds[playerid] == 0)
  889.     {
  890.         KillTimer(playerCountdownTimer[playerid]);
  891.         playerCountdownTimer[playerid] = -1;
  892.    
  893.         TogglePlayerControllable(playerid, 1);
  894.    
  895.         GameTextForPlayer(playerid, "~g~GO!!", 5000, 5);
  896.         PlayerPlaySound(playerid, 3201, 0, 0, 0);
  897.        
  898.         SetCameraBehindPlayer(playerid);
  899.         TextDrawHideForPlayer(playerid, title);
  900.         TextDrawHideForPlayer(playerid, instructions);
  901.         TextDrawHideForPlayer(playerid, getReady);
  902.         TextDrawHideForPlayer(playerid, countdown);
  903.        
  904.         TextDrawShowForPlayer(playerid, top3timesTitle);
  905.         TextDrawShowForPlayer(playerid, top3Times);
  906.        
  907.         yourTime[playerid] = CreatePlayerTextDraw(playerid,33.000000, 246.000000, "~y~YOUR TIME:~w~ --");
  908.         PlayerTextDrawBackgroundColor(playerid, yourTime[playerid], 255);
  909.         PlayerTextDrawFont(playerid, yourTime[playerid], 1);
  910.         PlayerTextDrawLetterSize(playerid, yourTime[playerid], 0.370000, 1.400000);
  911.         PlayerTextDrawColor(playerid, yourTime[playerid], -1);
  912.         PlayerTextDrawSetOutline(playerid, yourTime[playerid], 0);
  913.         PlayerTextDrawSetProportional(playerid, yourTime[playerid], 1);
  914.         PlayerTextDrawSetShadow(playerid, yourTime[playerid], 1);
  915.         PlayerTextDrawShow(playerid, yourTime[playerid]);
  916.        
  917.        
  918.         playerTimeUpdateTimer[playerid] = SetTimerEx("updatePlayerTime", 250, 1, "d", playerid);
  919.         #if defined MINIMUM_HEIGHT
  920.             playerHeightCheckTimer[playerid] = SetTimerEx("checkMinimumHeight", 1000, 1, "d", playerid);
  921.         #endif
  922.         #if defined CHECKPOINT_RANGE_CHECK
  923.             playerCheckpointRangeTimer[playerid] = SetTimerEx("checkCheckpointRange", 1000, 1, "d", playerid);
  924.         #endif
  925.        
  926.         if(safePointCount > 0){
  927.             playerSafePointTimer[playerid] = SetTimerEx("checkSafepointRange", 500, 1, "d", playerid);
  928.         }
  929.        
  930.         playerStartTimeTicks[playerid] = GetTickCount();
  931.         return;
  932.     }
  933.    
  934.     if(playerCountdownSeconds[playerid] == COUNTDOWN_SECONDS)
  935.     {
  936.         startMusic(playerid);
  937.     }
  938.    
  939.     if(playerCountdownSeconds[playerid] == 10)
  940.     {
  941.         TextDrawShowForPlayer(playerid, title);
  942.     }
  943.  
  944.     if(playerCountdownSeconds[playerid] == 9)
  945.     {
  946.         TextDrawShowForPlayer(playerid, instructions);
  947.     }
  948.  
  949.     else if(playerCountdownSeconds[playerid] == 5)
  950.     {
  951.         TextDrawShowForPlayer(playerid, getReady);
  952.     }
  953.    
  954.     else if (playerCountdownSeconds[playerid] == 3)
  955.     {
  956.         TextDrawShowForPlayer(playerid, countdown);
  957.     }
  958.    
  959.     if(playerCountdownSeconds[playerid] < 4)
  960.     {
  961.         PlayerPlaySound(playerid, 1056, 0, 0, 0);
  962.     }
  963.  
  964.     new string[24];
  965.     format(string, 24, "%d", playerCountdownSeconds[playerid]);
  966.     TextDrawSetString(countdown, string);
  967.     playerCountdownSeconds[playerid]--;
  968. }
  969.  
  970.  
  971. forward checkCheckpointRange(playerid);
  972. public checkCheckpointRange(playerid)
  973. {
  974.     if(!IsPlayerInRangeOfPoint(playerid, 15.0, endPos[0], endPos[1], endPos[2])){
  975.         #if USE_RACE_CHECKPOINT == 1
  976.             DisablePlayerRaceCheckpoint(playerid);
  977.         #else
  978.             DisablePlayerCheckpoint(playerid);
  979.         #endif
  980.     }else {
  981.         #if USE_RACE_CHECKPOINT == 1
  982.             SetPlayerRaceCheckpoint(playerid, 1, endPos[0], endPos[1], endPos[2], 0, 0, 0, 5.0);
  983.         #else
  984.             SetPlayerCheckpoint(playerid, endPos[0], endPos[1], endPos[2], 5.0);
  985.         #endif
  986.     }
  987. }
  988.  
  989. forward updatePlayerTime(playerid);
  990. public updatePlayerTime(playerid)
  991. {
  992.     new str[128];
  993.     format(str, 128, "~y~YOUR TIME:~w~ %s", FormatTime(GetTickCount() - playerStartTimeTicks[playerid]));
  994.     PlayerTextDrawSetString(playerid, yourTime[playerid], str);
  995. }
  996.  
  997.  
  998. forward checkMinimumHeight(playerid);
  999. public checkMinimumHeight(playerid) {
  1000.  
  1001.     #if defined MINIMUM_HEIGHT
  1002.         new Float:x, Float:y, Float:z;
  1003.         GetPlayerPos(playerid, x, y, z);
  1004.         if(z < MINIMUM_HEIGHT) {
  1005.             TeleportPlayerToGame(playerid);
  1006.             GameTextForPlayer(playerid, "Hint: use ~r~/leave~w~ to exit game.", 5000, 5);
  1007.         }
  1008.     #else
  1009.         #pragma unused playerid
  1010.     #endif
  1011. }
  1012.  
  1013.  
  1014. forward startMusic(playerid);
  1015. public startMusic(playerid) {
  1016.     PlayAudioStreamForPlayer(playerid, musicUrl);
  1017. }
  1018.  
  1019. forward checkSafepointRange(playerid);
  1020. public checkSafepointRange(playerid)
  1021. {
  1022.     for(new i = 0; i < safePointCount+1; i++)
  1023.     {
  1024.         if(IsPlayerInRangeOfPoint(playerid, SAFEPOINT_RANGE, safePoints[i][0], safePoints[i][1], safePoints[i][2]))
  1025.         {
  1026.             if(playerLastSafePoint[playerid] != i)
  1027.             {
  1028.                 PlayerPlaySound(playerid, 1056, 0, 0, 0);
  1029.                 playerLastSafePoint[playerid] = i;
  1030.                 GameTextForPlayer(playerid, "Safe point", 5000, 5);
  1031.             }
  1032.             return;
  1033.         }
  1034.     }
  1035. }
  1036. stock addSafePoint(Float:x, Float:y, Float:z)
  1037. {
  1038.     if(++safePointCount >= MAX_SAFE_POINTS)
  1039.         return;
  1040.  
  1041.     safePoints[safePointCount][0] = floatround(x);
  1042.     safePoints[safePointCount][1] = floatround(y);
  1043.     safePoints[safePointCount][2] = floatround(z);
  1044.    
  1045.     safePointText[safePointCount] = Create3DTextLabel("SAFE POINT", -1, x, y, z, SAFEPOINT_RANGE, GAME_WORLD_ID, 0);
  1046. }
  1047.  
  1048. stock RemoveSafePointTexts()
  1049. {
  1050.     for(new i = 0; i < safePointCount; i++)
  1051.     {
  1052.         Delete3DTextLabel(safePointText[safePointCount]);
  1053.         safePointText[safePointCount] = Text3D:-1;
  1054.     }
  1055. }
  1056.  
  1057.  
  1058. stock TeleportPlayerToGame(playerid)
  1059. {
  1060.     SetPlayerVirtualWorld(playerid, GAME_WORLD_ID);
  1061.     // player has a safe point!
  1062.     if(playerLastSafePoint[playerid] != -1) {
  1063.         SetPlayerPos(playerid, safePoints[playerLastSafePoint[playerid]][0], safePoints[playerLastSafePoint[playerid]][1], safePoints[playerLastSafePoint[playerid]][2]+2);
  1064.     }else {
  1065.         SetPlayerPos(playerid, startPos[0], startPos[1], startPos[2]);
  1066.         SetPlayerFacingAngle(playerid, startPos[3]);
  1067.     }
  1068. }
  1069.  
  1070. forward HandleCheckpointEntry(playerid);
  1071. public HandleCheckpointEntry(playerid)
  1072. {
  1073.     if(IsPlayerSignedUp(playerid) && CurrentGameState == GAME_STATE_RUNNING)
  1074.     {
  1075.         KillTimer(playerTimeUpdateTimer[playerid]);
  1076.         KillTimer(playerHeightCheckTimer[playerid]);
  1077.         KillTimer(playerCheckpointRangeTimer[playerid]);
  1078.         KillTimer(playerSafePointTimer[playerid]);
  1079.         SetTimerEx("RemovePlayerFromGame", 7000, 0, "d", playerid);
  1080.         TextDrawShowForPlayer(playerid, endTitle);
  1081.         numberOfPeopleFinished++;
  1082.  
  1083.         new name [MAX_PLAYER_NAME];
  1084.         GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  1085.  
  1086.         new finishTime = GetTickCount() - playerStartTimeTicks[playerid];
  1087.  
  1088.         // Make it fair - anything less than 30 has to be a cheat.
  1089.         if(finishTime > 30000)
  1090.             insertDbRecord(name, finishTime);
  1091.         updateBestPlayersAndTimes();
  1092.  
  1093.         new str[128];
  1094.         format(str, 128, "You finished in ~y~%s ~w~Place.~n~Your Time: ~y~%s~w~.", ordinal(numberOfPeopleFinished), FormatTime(finishTime));
  1095.  
  1096.         if(endInfo[playerid] != PlayerText:INVALID_TEXT_DRAW)
  1097.         {
  1098.             PlayerTextDrawDestroy(playerid, endInfo[playerid]);
  1099.         }
  1100.         endInfo[playerid] = CreatePlayerTextDraw(playerid, 225.000000, 185.000000, str);
  1101.         PlayerTextDrawBackgroundColor(playerid, endInfo[playerid], 255);
  1102.         PlayerTextDrawFont(playerid, endInfo[playerid], 2);
  1103.         PlayerTextDrawLetterSize(playerid, endInfo[playerid], 0.500000, 2.500000);
  1104.         PlayerTextDrawColor(playerid, endInfo[playerid], -1);
  1105.         PlayerTextDrawSetOutline(playerid, endInfo[playerid], 0);
  1106.         PlayerTextDrawSetProportional(playerid, endInfo[playerid], 1);
  1107.         PlayerTextDrawSetShadow(playerid, endInfo[playerid], 1);
  1108.         PlayerTextDrawShow(playerid, endInfo[playerid]);
  1109.  
  1110.         TogglePlayerControllable(playerid, false);
  1111.         SetCameraBehindPlayer(playerid);
  1112.         #if USE_RACE_CHECKPOINT == 0
  1113.         DisablePlayerCheckpoint(playerid);
  1114.         #else
  1115.         DisablePlayerRaceCheckpoint(playerid);
  1116.         #endif
  1117.         PlayAudioStreamForPlayer(playerid, "https://dl.dropboxusercontent.com/u/45389967/door_run/You%20Win%20%28short%29%20-%20Dr.%20Mario%2064%20Music.mp3");
  1118.  
  1119.         if(HasAnyoneWon == false)
  1120.         {
  1121.             HasAnyoneWon = true;
  1122.             SendClientMessageToAll(-1, "-------------");
  1123.             format(str, 128, "Jay's %s - WE HAVE A WINNER!", gameTitle);
  1124.             SendClientMessageToAll(-1, str);
  1125.             format(str, 128, "%s has won!!!", name);
  1126.             SendClientMessageToAll(-1, str);
  1127.             SendClientMessageToAll(-1, "-----------");
  1128.         } else {
  1129.             format(str, 128, "You have finished Jay's %s. Unfortunately, you didn't win.", gameTitle);
  1130.             SendClientMessage(playerid, -1, str);
  1131.             SendClientMessage(playerid, -1, "BETTER LUCK NEXT TIME CHUM!");
  1132.         }
  1133.     }
  1134. }
  1135.  
  1136. public OnPlayerEnterCheckpoint(playerid)
  1137. {
  1138.     #if USE_RACE_CHECKPOINT == 0
  1139.     HandleCheckpointEntry(playerid);
  1140.     #endif
  1141.     return 1;
  1142. }
  1143.  
  1144. public OnPlayerEnterRaceCheckpoint(playerid)
  1145. {
  1146.     #if USE_RACE_CHECKPOINT == 1
  1147.     HandleCheckpointEntry(playerid);
  1148.     #endif
  1149.     return 1;
  1150. }
  1151.  
  1152. public OnPlayerSpawn(playerid)
  1153. {
  1154.     if(IsPlayerSignedUp(playerid) && CurrentGameState == GAME_STATE_RUNNING)
  1155.     {
  1156.         new str[128];
  1157.         format(str, 128, "You have been removed from Jay's %s because you have respawned.", gameTitle);
  1158.         SendClientMessage(playerid, -1, str);
  1159.         RemovePlayerFromGame(playerid);
  1160.     }
  1161.     return 1;
  1162. }
  1163.  
  1164. stock EndGame()
  1165. {
  1166.     for(new i = 0; i < SLOTS; i++)
  1167.     {
  1168.         if(!IsPlayerConnected(i) || IsPlayerNPC(i))
  1169.             continue;
  1170.    
  1171.         if(IsPlayerSignedUp(i) == false)
  1172.             continue;
  1173.  
  1174.         RemovePlayerFromGame(i);
  1175.     }
  1176.     CurrentGameState = GAME_STATE_IDLE;
  1177. }
  1178.  
  1179. forward RemovePlayerFromGame(playerid);
  1180. public RemovePlayerFromGame(playerid)
  1181. {
  1182.     if(CurrentGameState == GAME_STATE_RUNNING)
  1183.     {
  1184.         SpawnPlayer(playerid);
  1185.         DisablePlayerCheckpoint(playerid);
  1186.         StopAudioStreamForPlayer(playerid);
  1187.         KillTimer(playerTimeUpdateTimer[playerid]);
  1188.         KillTimer(playerHeightCheckTimer[playerid]);
  1189.         KillTimer(playerCheckpointRangeTimer[playerid]);
  1190.         KillTimer(playerSafePointTimer[playerid]);
  1191.         playerSafePointTimer[playerid] = -1;
  1192.         playerCheckpointRangeTimer[playerid] = -1;
  1193.         playerTimeUpdateTimer[playerid] = -1;
  1194.         playerHeightCheckTimer[playerid] = -1;
  1195.     }
  1196.    
  1197.     if(playerCountdownTimer[playerid] != -1)
  1198.     {
  1199.         KillTimer(playerCountdownTimer[playerid]);
  1200.         playerCountdownTimer[playerid] = -1;
  1201.     }
  1202.  
  1203.     playerCountdownSeconds[playerid] = COUNTDOWN_SECONDS;
  1204.     HasPlayerSignedUp[playerid] = false;
  1205.     playerLastSafePoint[playerid] = -1;
  1206.    
  1207.     if(endInfo[playerid] != PlayerText:INVALID_TEXT_DRAW)
  1208.     {
  1209.         PlayerTextDrawDestroy(playerid, endInfo[playerid]);
  1210.         endInfo[playerid] = PlayerText:INVALID_TEXT_DRAW;
  1211.     }
  1212.    
  1213.     if(yourTime[playerid] != PlayerText:INVALID_TEXT_DRAW)
  1214.     {
  1215.         PlayerTextDrawDestroy(playerid, yourTime[playerid]);
  1216.         yourTime[playerid] = PlayerText:INVALID_TEXT_DRAW;
  1217.     }
  1218.     TextDrawHideForPlayer(playerid, endTitle);
  1219.     TextDrawHideForPlayer(playerid, top3timesTitle);
  1220.     TextDrawHideForPlayer(playerid, top3Times);
  1221. }
  1222.  
  1223. // ordinal
  1224. // Utility function to ordinalize a number; i.e. 1st, 2nd, 3rd, etc.
  1225. stock ordinal(iNumber )
  1226. {
  1227.     new szSuffix[3];
  1228.     if ((iNumber % 100) / 10 == 1)
  1229.     {
  1230.         szSuffix = "th";
  1231.     }
  1232.     else
  1233.     {
  1234.         new iMod = iNumber % 10;
  1235.         switch (iMod)
  1236.         {
  1237.             case 1:     szSuffix = "st";
  1238.             case 2:     szSuffix = "nd";
  1239.             case 3:     szSuffix = "rd";
  1240.             default:    szSuffix = "th";
  1241.         }
  1242.     }
  1243.     new str[16];
  1244.     format( str, 16, "%d%s", iNumber, szSuffix );
  1245.     return str;
  1246. }
  1247.  
  1248. // FormatTime
  1249. // Formats the  time for a player: minutes:seconds.xx
  1250. FormatTime( iTime )
  1251. {
  1252.     new str[128];
  1253.     if (iTime >= 60000) format( str, 128, "%d:%02d.%02d", iTime / 60000, ((iTime + 5) % 60000) / 1000, ((iTime + 5) / 10) % 100 ); // woo rounding
  1254.     else format( str, 128, "%d.%02d", ((iTime + 5) % 60000) / 1000, ((iTime + 5) / 10) % 100 );
  1255.     return str;
  1256. }
Add Comment
Please, Sign In to add comment