Advertisement
badjhbzi

CBug-Timer v1.0 FINAL by BadJ/hbzi

Jun 27th, 2013
2,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.03 KB | None | 0 0
  1. /*
  2. 888888888888888888888888888888888888888888
  3. 88              CBUG-TIMER              88
  4. 888888888888888888888888888888888888888888
  5. 88 - AUTHOR: Badjouras                  88
  6. 88         (aka hbzi @ forum.sa-mp.com) 88
  7. 88 - VERSION: 1.0                       88
  8. 88 - LAST UPDATE: 23/06                 88
  9. 888888888888888888888888888888888888888888
  10. 88 - CHANGELOG:                         88
  11. 88                                      88
  12. 888888888888888888888888888888888888888888
  13. */
  14.  
  15. // * INCLUDES * //
  16. #include <a_samp> //Credits to SA-MP Team
  17. #include <YSI\y_ini> //Credits to Y_Less
  18. #include <zcmd> //Credits to Zeex
  19.  
  20. // * DEFINES FUNCS * //
  21. #define Msg SendClientMessage
  22. #define MsgAll SendClientMessageToAll
  23. #define PRESSED(%0) \
  24.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  25. #define RELEASED(%0) \
  26.     (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  27.  
  28. // * CONSTANTES * //
  29. #define DIALOG_TOPS 874
  30.  
  31. // * CORES * //
  32.  
  33. // * VARS * //
  34. new isCbug[MAX_PLAYERS+1];
  35. new bool:disparou[MAX_PLAYERS+1] = false;
  36. new Float:ccount[4][MAX_PLAYERS+1];
  37. new sstr[128];
  38. new str1[256];
  39. new fileToWrite[] = "topcbug.ini";
  40. new Float:tops[5];
  41. new jogtops[5][MAX_PLAYER_NAME+1];
  42.  
  43. // * STOCKS * //
  44. stock GetPlayerN(playerid)
  45. {
  46.    new nomeJog[MAX_PLAYER_NAME];
  47.    GetPlayerName(playerid, nomeJog, MAX_PLAYER_NAME);
  48.    return nomeJog;
  49. }
  50.  
  51. WaitReset(playerid)
  52. {
  53.     SetTimerEx("FuncPart2", 2000, 0, "i", playerid);
  54. }
  55.  
  56.  
  57. // * FUNÇÕES * //
  58. forward FuncPart2(playerid);
  59. public FuncPart2(playerid)
  60. {
  61.     ccount[0][playerid] = 0; ccount[1][playerid] = 0; ccount[2][playerid] = 0; ccount[3][playerid] = 0;
  62.     ResetPlayerWeapons(playerid);
  63.     GivePlayerWeapon(playerid, 24, 7);
  64. }
  65.  
  66. forward ini_tempos_topcbug(name[], value[]);
  67. public ini_tempos_topcbug(name[], value[])
  68. {
  69.     INI_Float("1", tops[0]);
  70.     INI_Float("2", tops[1]);
  71.     INI_Float("3", tops[2]);
  72.     INI_Float("4", tops[3]);
  73.     INI_Float("5", tops[4]);
  74.     return 1;
  75. }
  76.  
  77. forward ini_jogadores_topcbug(name[], value[]);
  78. public ini_jogadores_topcbug(name[], value[])
  79. {
  80.     INI_String("j1", jogtops[0], MAX_PLAYER_NAME+1);
  81.     INI_String("j2", jogtops[1], MAX_PLAYER_NAME+1);
  82.     INI_String("j3", jogtops[2], MAX_PLAYER_NAME+1);
  83.     INI_String("j4", jogtops[3], MAX_PLAYER_NAME+1);
  84.     INI_String("j5", jogtops[4], MAX_PLAYER_NAME+1);
  85.     return 1;
  86. }
  87.  
  88. public OnFilterScriptInit()
  89. {
  90.     print("\n--------------------------------------");
  91.     print("   C-Bug Timer v1.0 FINAL by Badjouras");
  92.     print("--------------------------------------\n");
  93.    
  94.     if(!fexist(fileToWrite))
  95.     {
  96.         new INI:iniFile = INI_Open(fileToWrite);
  97.         INI_SetTag(iniFile, "tempos");
  98.         INI_WriteFloat(iniFile, "1", 9999999.0, 4);
  99.         INI_WriteFloat(iniFile, "2", 9999999.0, 4);
  100.         INI_WriteFloat(iniFile, "3", 9999999.0, 4);
  101.         INI_WriteFloat(iniFile, "4", 9999999.0, 4);
  102.         INI_WriteFloat(iniFile, "5", 9999999.0, 4);
  103.         INI_SetTag(iniFile, "jogadores");
  104.         INI_WriteString(iniFile, "j1", "N/D");
  105.         INI_WriteString(iniFile, "j2", "N/D");
  106.         INI_WriteString(iniFile, "j3", "N/D");
  107.         INI_WriteString(iniFile, "j4", "N/D");
  108.         INI_WriteString(iniFile, "j5", "N/D");
  109.         INI_Close(iniFile);
  110.     }
  111.    
  112.     return 1;
  113. }
  114.  
  115. public OnPlayerConnect(playerid)
  116. {
  117.     isCbug[playerid] = 0;
  118.     return 1;
  119. }
  120.  
  121. public OnPlayerDisconnect(playerid)
  122. {
  123.     isCbug[playerid] = 0;
  124.     return 1;
  125. }
  126.  
  127. public OnPlayerDeath(playerid, killerid, reason)
  128. {
  129.     if(isCbug[playerid] == 1) isCbug[playerid] = 0;
  130.     return 1;
  131. }
  132.  
  133. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  134. {
  135.     if(isCbug[playerid] == 1)
  136.     {
  137.         if(GetPlayerWeapon(playerid) == 24)
  138.         {
  139.             if(GetPlayerAmmo(playerid) == 7 && PRESSED(KEY_FIRE))
  140.             {
  141.                 ccount[0][playerid] = GetTickCount();
  142.                 disparou[playerid] = true;
  143.             }
  144.             else if(RELEASED(KEY_FIRE))
  145.             {
  146.                 if(GetPlayerAmmo(playerid) == 0)
  147.                 {
  148.                     ccount[1][playerid] = GetTickCount();
  149.                     ccount[2][playerid] = ccount[1][playerid] - ccount[0][playerid];
  150.                     ccount[3][playerid] = ccount[2][playerid] / 1000;
  151.                     disparou[playerid] = false;
  152.                     format(sstr, sizeof(sstr), "~r~C-Bug Time~w~:~n~%0.4f~y~s", ccount[3][playerid]);
  153.                     GameTextForPlayer(playerid, sstr, 2000, 4);
  154.                     format(str1, sizeof(str1), "{FF0000}C-Bug Time{FFFFFF}: %0.4f{FFFF00}s", ccount[3][playerid]);
  155.                     Msg(playerid, -1, str1);
  156.  
  157.                     // Y_INI
  158.                     INI_ParseFile(fileToWrite,"ini_%s_%s");
  159.                     if (ccount[3][playerid] < tops[4])
  160.                     {
  161.                         new INI:iniFile = INI_Open(fileToWrite);
  162.                         new nick[MAX_PLAYER_NAME+1];
  163.                         format(nick, sizeof(nick), GetPlayerN(playerid));
  164.                        
  165.                         if (ccount[3][playerid] < tops[0])
  166.                         {
  167.                             INI_SetTag(iniFile, "tempos");
  168.                             INI_WriteFloat(iniFile, "1", ccount[3][playerid], 4);
  169.                             INI_WriteFloat(iniFile, "2", tops[0], 4);
  170.                             INI_WriteFloat(iniFile, "3", tops[1], 4);
  171.                             INI_WriteFloat(iniFile, "4", tops[2], 4);
  172.                             INI_WriteFloat(iniFile, "5", tops[3], 4);
  173.                             INI_SetTag(iniFile, "jogadores");
  174.                             INI_WriteString(iniFile, "j1", nick);
  175.                             INI_WriteString(iniFile, "j2", jogtops[0]);
  176.                             INI_WriteString(iniFile, "j3", jogtops[1]);
  177.                             INI_WriteString(iniFile, "j4", jogtops[2]);
  178.                             INI_WriteString(iniFile, "j5", jogtops[3]);
  179.  
  180.                             format(str1, sizeof(str1), "[CBug-Time] {00FF00}%s{FFFFFF} is now in {00FF00}1st place{FFFFFF} with a time of {00FF00}%0.4f{FFFFFF} seconds!", nick, ccount[3][playerid]);
  181.                             MsgAll(0xFF0000FF, str1);
  182.                             INI_Close(iniFile);
  183.                         }
  184.                         else if (ccount[3][playerid] < tops[1])
  185.                         {
  186.                             INI_SetTag(iniFile, "tempos");
  187.                             INI_WriteFloat(iniFile, "2", ccount[3][playerid], 4);
  188.                             INI_WriteFloat(iniFile, "3", tops[1], 4);
  189.                             INI_WriteFloat(iniFile, "4", tops[2], 4);
  190.                             INI_WriteFloat(iniFile, "5", tops[3], 4);
  191.                             INI_SetTag(iniFile, "jogadores");
  192.                             INI_WriteString(iniFile, "j2", nick);
  193.                             INI_WriteString(iniFile, "j3", jogtops[1]);
  194.                             INI_WriteString(iniFile, "j4", jogtops[2]);
  195.                             INI_WriteString(iniFile, "j5", jogtops[3]);
  196.  
  197.                             format(str1, sizeof(str1), "[CBug-Time] {00FF00}%s{FFFFFF} is now in {00FF00}2nd place{FFFFFF} with a time of {00FF00}%0.4f{FFFFFF} seconds!", nick, ccount[3][playerid]);
  198.                             MsgAll(0xFF0000FF, str1);
  199.                             INI_Close(iniFile);
  200.                         }
  201.                         else if (ccount[3][playerid] < tops[2])
  202.                         {
  203.                             INI_SetTag(iniFile, "tempos");
  204.                             INI_WriteFloat(iniFile, "3", ccount[3][playerid], 4);
  205.                             INI_WriteFloat(iniFile, "4", tops[2], 4);
  206.                             INI_WriteFloat(iniFile, "5", tops[3], 4);
  207.                             INI_SetTag(iniFile, "jogadores");
  208.                             INI_WriteString(iniFile, "j3", nick);
  209.                             INI_WriteString(iniFile, "j4", jogtops[2]);
  210.                             INI_WriteString(iniFile, "j5", jogtops[3]);
  211.  
  212.                             format(str1, sizeof(str1), "[CBug-Time] {00FF00}%s{FFFFFF} is now in {00FF00}3rd place{FFFFFF} with a time of {00FF00}%0.4f{FFFFFF} seconds!", nick, ccount[3][playerid]);
  213.                             MsgAll(0xFF0000FF, str1);
  214.                             INI_Close(iniFile);
  215.                         }
  216.                         else if (ccount[3][playerid] < tops[3])
  217.                         {
  218.                             INI_SetTag(iniFile, "tempos");
  219.                             INI_WriteFloat(iniFile, "4", ccount[3][playerid], 4);
  220.                             INI_WriteFloat(iniFile, "5", tops[3], 4);
  221.                             INI_SetTag(iniFile, "jogadores");
  222.                             INI_WriteString(iniFile, "j4", nick);
  223.                             INI_WriteString(iniFile, "j5", jogtops[3]);
  224.  
  225.                             format(str1, sizeof(str1), "[CBug-Time] {00FF00}%s{FFFFFF} is now in {00FF00}4th place{FFFFFF} with a time of {00FF00}%0.4f{FFFFFF} seconds!", nick, ccount[3][playerid]);
  226.                             MsgAll(0xFF0000FF, str1);
  227.                             INI_Close(iniFile);
  228.                         }
  229.                         else
  230.                         {
  231.                             INI_SetTag(iniFile, "tempos");
  232.                             INI_WriteFloat(iniFile, "5", ccount[3][playerid], 4);
  233.                             INI_SetTag(iniFile, "jogadores");
  234.                             INI_WriteString(iniFile, "j5", nick);
  235.  
  236.                             format(str1, sizeof(str1), "[CBug-Time] {00FF00}%s{FFFFFF} is now in {00FF00}5th place{FFFFFF} with a time of {00FF00}%0.4f{FFFFFF} seconds!", nick, ccount[3][playerid]);
  237.                             MsgAll(0xFF0000FF, str1);
  238.  
  239.                             INI_Close(iniFile);
  240.                         }
  241.                     }
  242.  
  243.                     // Y_INI
  244.                     ccount[0][playerid] = 0; ccount[1][playerid] = 0; ccount[2][playerid] = 0; ccount[3][playerid] = 0;
  245.                     WaitReset(playerid);
  246.                 }
  247.             }
  248.            
  249.         }
  250.     }
  251.     return 1;
  252. }
  253.  
  254. // * COMANDOS * //
  255. CMD:cbug(playerid, params[])
  256. {
  257.     if(isCbug[playerid] == 1) return Msg(playerid, -1, "You are already in the CBug Arena!");
  258.     ccount[0][playerid] = 0; ccount[1][playerid] = 0; ccount[2][playerid] = 0; ccount[3][playerid] = 0;
  259.     isCbug[playerid] = 1;
  260.     SetPlayerPos(playerid, 1351.6174, 2183.8823, 11.0234);
  261.     ResetPlayerWeapons(playerid);
  262.     GivePlayerWeapon(playerid, 24, 7);
  263.     SetPlayerHealth(playerid, 9999999.0);
  264.     return 1;
  265. }
  266.  
  267. CMD:exitcbug(playerid, params[])
  268. {
  269.     ccount[0][playerid] = 0; ccount[1][playerid] = 0; ccount[2][playerid] = 0; ccount[3][playerid] = 0;
  270.     isCbug[playerid] = 0;
  271.     SetPlayerHealth(playerid, 0.0);
  272.     return 1;
  273. }
  274.  
  275. CMD:gdeagle(playerid, params[])
  276. {
  277.     if(isCbug[playerid] == 0) return Msg(playerid, -1, "You are not in the CBug Arena!");
  278.     if(GetPlayerWeapon(playerid) == 24) return Msg(playerid, -1, "You already have a deagle!");
  279.     ResetPlayerWeapons(playerid);
  280.     GivePlayerWeapon(playerid, 24, 7);
  281.     return 1;
  282. }
  283.  
  284. CMD:topcbug(playerid, params[])
  285. {
  286.     INI_ParseFile(fileToWrite,"ini_%s_%s");
  287.     for (new i=0; i<5; i++)
  288.     {
  289.         if(tops[i] == 9999999.0000) tops[i] = 0.0000;
  290.     }
  291.     format(str1, sizeof(str1), "{FFFFFF}#1 {FFFF00}%s {00FFFF}%0.4f\n{FFFFFF}#2 {FFFF00}%s {00FFFF}%0.4f\n{FFFFFF}#3 {FFFF00}%s {00FFFF}%0.4f\n{FFFFFF}#4 {FFFF00}%s {00FFFF}%0.4f\n{FFFFFF}#5 {FFFF00}%s {00FFFF}%0.4f", jogtops[0], tops[0], jogtops[1], tops[1], jogtops[2], tops[2], jogtops[3], tops[3], jogtops[4], tops[4]);
  292.     ShowPlayerDialog(playerid, DIALOG_TOPS, 0, "Top 5 CBug-Time", str1, "OK", "");
  293.     return 1;
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement