Advertisement
Guest User

Lotuz DriftCounter

a guest
Jun 14th, 2012
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.92 KB | None | 0 0
  1. //=====================Driftcounter By Lotuz=======================
  2. //===================Do not change any credits=====================
  3. //=========================2012-06-13==============================
  4.  
  5. //====include
  6. #include <a_samp>
  7. #include <zcmd>
  8.  
  9. //====define
  10. #define DRIFT_MINKAT 10.0
  11. #define DRIFT_MAXKAT 90.0
  12. #define DRIFT_SPEED 30.0
  13. #define dc 1117
  14.  
  15. //====new
  16. new atimer, dtimer;
  17. new Text:Chet[MAX_PLAYERS];
  18. new DriftPointsNow[200];
  19. new PlayerDriftCancellation[200];
  20. new Float:ppos[200][3];
  21. new scores[MAX_PLAYERS];
  22. new scplay[MAX_PLAYERS], chets[MAX_PLAYERS];
  23. enum Float:Pos{ Float:sX,Float:sY,Float:sZ };
  24. new Float:SavedPos[MAX_PLAYERS][Pos];
  25.  
  26. //====forward
  27. forward Drift();
  28. forward AngleUpdate();
  29. forward DriftCancellation(playerid);
  30.  
  31.  
  32. public OnGameModeInit()
  33. {
  34.     dtimer = SetTimer("Drift", 200, true);
  35.     atimer = SetTimer("AngleUpdate", 200, true);
  36.     return 1;
  37. }
  38. public OnPlayerConnect(playerid)
  39. {
  40.     scplay[playerid] = 1;
  41.     chets[playerid] = 1;
  42.     //==========================================
  43.     Chet[playerid] = TextDrawCreate(500,170,"-");
  44.     TextDrawAlignment(Chet[playerid],0);
  45.     TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
  46.     TextDrawFont(Chet[playerid],3);
  47.     TextDrawLetterSize(Chet[playerid],0.5,1.7);
  48.     TextDrawColor(Chet[playerid],0x0000CDFF);
  49.     TextDrawSetOutline(Chet[playerid],1);
  50.     TextDrawSetProportional(Chet[playerid],1);
  51.     TextDrawSetShadow(Chet[playerid],1);
  52.     SendClientMessage(playerid, 0x008000FF, "This server use Lotuz Driftcounter. Use /dc");
  53.     return 1;
  54. }
  55. CMD:dc(playerid, params[])
  56. {
  57.     ShowPlayerDialog(playerid, dc, DIALOG_STYLE_LIST, "DriftCounter", "{0004FF}Blue\n{040524}Black\n{FF9305}Orange\n{5BE93B}Green\n{FF00FF}Pink", "Okey", "Back");
  58.     return 1;
  59. }
  60. Float:GetPlayerTheoreticAngle(i) // By Luby
  61. {
  62.         new Float:sin;
  63.         new Float:dis;
  64.         new Float:angle2;
  65.         new Float:x,Float:y,Float:z;
  66.         new Float:tmp3;
  67.         new Float:tmp4;
  68.         new Float:MindAngle;
  69.  
  70.         if(IsPlayerConnected(i))
  71.         {
  72.                 GetPlayerPos(i,x,y,z);
  73.                 dis = floatsqroot(floatpower(floatabs(floatsub(x,ppos[i][0])),2)+floatpower(floatabs(floatsub(y,ppos[i][1])),2));
  74.                 if(IsPlayerInAnyVehicle(i)){GetVehicleZAngle(GetPlayerVehicleID(i), angle2);}else{GetPlayerFacingAngle(i, angle2);}
  75.                 if(x>ppos[i][0]){tmp3=x-ppos[i][0];}else{tmp3=ppos[i][0]-x;}
  76.                 if(y>ppos[i][1]){tmp4=y-ppos[i][1];}else{tmp4=ppos[i][1]-y;}
  77.                 if(ppos[i][1]>y && ppos[i][0]>x)
  78.                 {
  79.                     sin = asin(tmp3/dis);
  80.                     MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
  81.                 }
  82.                 if(ppos[i][1]<y && ppos[i][0]>x)
  83.                 {
  84.                     sin = asin(tmp3/dis);
  85.                     MindAngle = floatsub(floatadd(sin, 180), 180.0);
  86.                 }
  87.                 if(ppos[i][1]<y && ppos[i][0]<x)
  88.                 {
  89.                     sin = acos(tmp4/dis);
  90.                     MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
  91.                 }
  92.                 if(ppos[i][1]>y && ppos[i][0]<x)
  93.                 {
  94.                     sin = asin(tmp3/dis);
  95.                     MindAngle = floatadd(sin, 180);
  96.                 }
  97.         }
  98.  
  99.         if(MindAngle == 0.0)
  100.         {
  101.             return angle2;
  102.         }
  103.         else
  104.         {
  105.             return MindAngle;
  106.         }
  107. }
  108. //------------------------------------------------
  109.  
  110. stock strrest(const string[], &index)
  111. {
  112.     new length = strlen(string);
  113.     while ((index < length) && (string[index] <= ' '))
  114.     {
  115.         index++;
  116.     }
  117.     new offset = index;
  118.     new result[128];
  119.     while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
  120.     {
  121.         result[index - offset] = string[index];
  122.         index++;
  123.     }
  124.     result[index - offset] = EOS;
  125.     return result;
  126. }
  127.  
  128. stock strtok(const string[], &index)
  129. {
  130.     new length = strlen(string);
  131.     while ((index < length) && (string[index] <= ' '))
  132.     {
  133.         index++;
  134.     }
  135.  
  136.     new offset = index;
  137.     new result[20];
  138.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  139.     {
  140.         result[index - offset] = string[index];
  141.         index++;
  142.     }
  143.     result[index - offset] = EOS;
  144.     return result;
  145. }
  146. public DriftCancellation(playerid)
  147. {
  148.     PlayerDriftCancellation[playerid] = 0;
  149.     GivePlayerMoney(playerid,DriftPointsNow[playerid]);
  150.     DriftPointsNow[playerid] = 0;
  151.     scores[playerid] = 0;
  152.     TextDrawHideForPlayer(playerid, Chet[playerid]);
  153. }
  154.  
  155. Float:ReturnPlayerAngle(playerid)
  156. {
  157.     new Float:Ang;
  158.     if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang); else GetPlayerFacingAngle(playerid, Ang);
  159.     return Ang;
  160. }
  161.  
  162. public Drift()
  163. {
  164.     new Float:Angle1, Float:Angle2, Float:BySpeed, s[128];
  165.     new Float:Z;
  166.     new Float:X;
  167.     new Float:Y;
  168.     new Float:SpeedX;
  169.     for(new g=0;g<MAX_PLAYERS;g++)
  170.     {
  171.         GetPlayerPos(g, X, Y, Z);
  172.         SpeedX = floatsqroot(floatadd(floatadd(floatpower(floatabs(floatsub(X,SavedPos[ g ][ sX ])),2),floatpower(floatabs(floatsub(Y,SavedPos[ g ][ sY ])),2)),floatpower(floatabs(floatsub(Z,SavedPos[ g ][ sZ ])),2)));
  173.         Angle1 = ReturnPlayerAngle(g);
  174.         Angle2 = GetPlayerTheoreticAngle(g);
  175.         BySpeed = floatmul(SpeedX, 12);
  176.         if(IsPlayerInAnyVehicle(g) && IsCar(GetPlayerVehicleID(g)) && floatabs(floatsub(Angle1, Angle2)) > DRIFT_MINKAT && floatabs(floatsub(Angle1, Angle2)) < DRIFT_MAXKAT && BySpeed > DRIFT_SPEED)
  177.         {
  178.             if(PlayerDriftCancellation[g] > 0)KillTimer(PlayerDriftCancellation[g]);
  179.             PlayerDriftCancellation[g] = 0;
  180.             DriftPointsNow[g] += 10;
  181.             scores[g]++;
  182.             PlayerDriftCancellation[g] = SetTimerEx("DriftCancellation", 2000, 0, "d", g);
  183.         }
  184.         if(DriftPointsNow[g] > 0)
  185.         {
  186.             if(scplay[g] == 1)
  187.             {
  188.                 TextDrawShowForPlayer(g,Chet[g]);
  189.                 format(s, sizeof(s), "Drift: %d$", DriftPointsNow[g]);
  190.                 TextDrawSetString(Chet[g], s);
  191.             }
  192.         }
  193.         SavedPos[ g ][ sX ] = X;
  194.         SavedPos[ g ][ sY ] = Y;
  195.         SavedPos[ g ][ sZ ] = Z;
  196.     }
  197. }
  198.  
  199. IsCar(model)
  200. {
  201.     switch(model)
  202.     {
  203.         case 443:return 0;
  204.         case 448:return 0;
  205.         case 461:return 0;
  206.         case 462:return 0;
  207.         case 463:return 0;
  208.         case 468:return 0;
  209.         case 521:return 0;
  210.         case 522:return 0;
  211.         case 523:return 0;
  212.         case 581:return 0;
  213.         case 586:return 0;
  214.         case 481:return 0;
  215.         case 509:return 0;
  216.         case 510:return 0;
  217.         case 430:return 0;
  218.         case 446:return 0;
  219.         case 452:return 0;
  220.         case 453:return 0;
  221.         case 454:return 0;
  222.         case 472:return 0;
  223.         case 473:return 0;
  224.         case 484:return 0;
  225.         case 493:return 0;
  226.         case 595:return 0;
  227.         case 417:return 0;
  228.         case 425:return 0;
  229.         case 447:return 0;
  230.         case 465:return 0;
  231.         case 469:return 0;
  232.         case 487:return 0;
  233.         case 488:return 0;
  234.         case 497:return 0;
  235.         case 501:return 0;
  236.         case 548:return 0;
  237.         case 563:return 0;
  238.         case 406:return 0;
  239.         case 444:return 0;
  240.         case 556:return 0;
  241.         case 557:return 0;
  242.         case 573:return 0;
  243.         case 460:return 0;
  244.         case 464:return 0;
  245.         case 476:return 0;
  246.         case 511:return 0;
  247.         case 512:return 0;
  248.         case 513:return 0;
  249.         case 519:return 0;
  250.         case 520:return 0;
  251.         case 539:return 0;
  252.         case 553:return 0;
  253.         case 577:return 0;
  254.         case 592:return 0;
  255.         case 593:return 0;
  256.         case 471:return 0;
  257.     }
  258.     return 1;
  259. }
  260. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  261. {
  262.     if(dialogid == dc) // == Driftcounter Color's
  263.     {
  264.         if(response)
  265.         {
  266.             if(listitem == 0)
  267.             {
  268.                 TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
  269.                 SendClientMessage(playerid, 0x0000CDFF, "You Driftcounter are now Blue");
  270.                 TextDrawColor(Chet[playerid],0x0000CDFF);
  271.             }
  272.             if(listitem == 1)
  273.             {
  274.                 TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
  275.                 SendClientMessage(playerid, 0x000000FF, "You Driftcounter are now Black");
  276.                 TextDrawColor(Chet[playerid],0x000000FF);
  277.             }
  278.             if(listitem == 2)
  279.             {
  280.                 TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
  281.                 SendClientMessage(playerid, 0xFF4500FF, "You Driftcounter are now Orange");
  282.                 TextDrawColor(Chet[playerid],0xFF4500FF);
  283.             }
  284.             if(listitem == 3)
  285.             {
  286.                 TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
  287.                 SendClientMessage(playerid, 0x008000FF, "You Driftcounter are now Green");
  288.                 TextDrawColor(Chet[playerid],0x008000FF);
  289.                 return 1;
  290.             }
  291.             if(listitem == 4)
  292.             {
  293.                 TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
  294.                 SendClientMessage(playerid, 0xFF1493FF, "You Driftcounter are now Pink");
  295.                 TextDrawColor(Chet[playerid],0xFF1493FF);
  296.                 return 1;
  297.             }
  298.         }
  299.     }
  300.     return 1;
  301. }
  302. public AngleUpdate()
  303. {
  304.     for(new g=0;g<=MAX_PLAYERS;g++)
  305.     {
  306.         new Float:x, Float:y, Float:z;
  307.         if(IsPlayerInAnyVehicle(g))GetVehiclePos(GetPlayerVehicleID(g), x, y, z); else GetPlayerPos(g, x, y, z);
  308.         ppos[g][0] = x;
  309.         ppos[g][1] = y;
  310.         ppos[g][2] = z;
  311.     }
  312. }
  313.  
  314. public OnVehicleDamageStatusUpdate(vehicleid, playerid)
  315. {
  316.     if(DriftPointsNow[playerid] > 0)
  317.     {
  318.         DriftPointsNow[playerid] = 0;
  319.         scores[playerid] = 0;
  320.         TextDrawSetString(Chet[playerid], "~r~Crash");
  321.     }
  322.     return 1;
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement