Advertisement
Ranchend

Licznik Driftu V2

Feb 14th, 2014
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2.  
  3. new Text:ServerTextDrawOne;
  4. new Text:ServerTextDrawTwo;
  5. new Text:ServerTextDrawThree[MAX_PLAYERS];
  6. new Text:ServerTextDrawFour[MAX_PLAYERS];
  7. new Text:ServerTextDrawFive[MAX_PLAYERS];
  8. new ServerTimerOne;
  9. new ServerTimerTwo;
  10. new PlayerUseDriftCounter[MAX_PLAYERS];
  11. new PlayerMoney[MAX_PLAYERS];
  12. new PlayerScore[MAX_PLAYERS];
  13. new PlayerCombo[MAX_PLAYERS];
  14. new Float:PlayerPositionX[MAX_PLAYERS];
  15. new Float:PlayerPositionY[MAX_PLAYERS];
  16. new Float:PlayerPositionZ[MAX_PLAYERS];
  17. new PlayerTimerOne[MAX_PLAYERS];
  18.  
  19. forward PlayerUpdate();
  20. forward PlayerDrift();
  21. forward PlayerDriftEnd(Player);
  22.  
  23. Float:PlayerTheoreticAngle(Player)
  24. {
  25.     new Float:X;
  26.     new Float:Y;
  27.     new Float:Z;
  28.     GetVehiclePos(GetPlayerVehicleID(Player),X,Y,Z);
  29.     new Float:NewX;
  30.     if(X > PlayerPositionX[Player]) NewX = X - PlayerPositionX[Player];
  31.     if(X < PlayerPositionX[Player]) NewX = PlayerPositionX[Player] - X;
  32.     new Float:NewY;
  33.     if(Y > PlayerPositionY[Player]) NewY = Y - PlayerPositionY[Player];
  34.     if(Y < PlayerPositionY[Player]) NewY = PlayerPositionY[Player] - Y;
  35.     new Float:Sinus;
  36.     new Float:Cosinus;
  37.     Cosinus = floatsqroot(floatpower(floatabs(floatsub(X,PlayerPositionX[Player])),2) + floatpower(floatabs(floatsub(Y,PlayerPositionY[Player])),2));
  38.     new Float:TheoreticAngle;
  39.     if(PlayerPositionX[Player] > X && PlayerPositionY[Player] > Y)
  40.     {
  41.         Sinus = asin(NewX / Cosinus);
  42.         TheoreticAngle = floatsub(floatsub(floatadd(Sinus,90),floatmul(Sinus,2)),-90.0);
  43.     }
  44.     if(PlayerPositionX[Player] > X && PlayerPositionY[Player] < Y)
  45.     {
  46.         Sinus = asin(NewX / Cosinus);
  47.         TheoreticAngle = floatsub(floatadd(Sinus,180),180.0);
  48.     }
  49.     if(PlayerPositionX[Player] < X && PlayerPositionY[Player] < Y)
  50.     {
  51.         Sinus = acos(NewY / Cosinus);
  52.         TheoreticAngle = floatsub(floatadd(Sinus,360),floatmul(Sinus,2));
  53.     }
  54.     if(PlayerPositionX[Player] < X && PlayerPositionY[Player] > Y)
  55.     {
  56.         Sinus = asin(NewX / Cosinus);
  57.         TheoreticAngle = floatadd(Sinus,180);
  58.     }
  59.     if(TheoreticAngle == 0.0) GetVehicleZAngle(GetPlayerVehicleID(Player),TheoreticAngle);
  60.     return TheoreticAngle;
  61. }
  62.  
  63. stock VehicleIsCar(Vehicle)
  64. {
  65.     switch(GetVehicleModel(Vehicle))
  66.     {
  67.         case 480: return 1;
  68.         case 533: return 1;
  69.         case 439: return 1;
  70.         case 555: return 1;
  71.         case 536: return 1;
  72.         case 575: return 1;
  73.         case 534: return 1;
  74.         case 567: return 1;
  75.         case 535: return 1;
  76.         case 566: return 1;
  77.         case 576: return 1;
  78.         case 412: return 1;
  79.         case 445: return 1;
  80.         case 504: return 1;
  81.         case 401: return 1;
  82.         case 518: return 1;
  83.         case 527: return 1;
  84.         case 542: return 1;
  85.         case 507: return 1;
  86.         case 562: return 1;
  87.         case 585: return 1;
  88.         case 419: return 1;
  89.         case 526: return 1;
  90.         case 604: return 1;
  91.         case 466: return 1;
  92.         case 492: return 1;
  93.         case 474: return 1;
  94.         case 546: return 1;
  95.         case 517: return 1;
  96.         case 410: return 1;
  97.         case 551: return 1;
  98.         case 516: return 1;
  99.         case 467: return 1;
  100.         case 426: return 1;
  101.         case 436: return 1;
  102.         case 547: return 1;
  103.         case 405: return 1;
  104.         case 580: return 1;
  105.         case 560: return 1;
  106.         case 550: return 1;
  107.         case 549: return 1;
  108.         case 540: return 1;
  109.         case 491: return 1;
  110.         case 529: return 1;
  111.         case 421: return 1;
  112.         case 602: return 1;
  113.         case 429: return 1;
  114.         case 496: return 1;
  115.         case 402: return 1;
  116.         case 541: return 1;
  117.         case 415: return 1;
  118.         case 589: return 1;
  119.         case 587: return 1;
  120.         case 565: return 1;
  121.         case 494: return 1;
  122.         case 502: return 1;
  123.         case 503: return 1;
  124.         case 411: return 1;
  125.         case 559: return 1;
  126.         case 603: return 1;
  127.         case 475: return 1;
  128.         case 506: return 1;
  129.         case 451: return 1;
  130.         case 558: return 1;
  131.         case 477: return 1;
  132.         case 418: return 1;
  133.         case 404: return 1;
  134.         case 479: return 1;
  135.         case 458: return 1;
  136.         case 561: return 1;
  137.     }
  138.     return 0;
  139. }
  140.  
  141. stock VehicleSpeed(Vehicle)
  142. {
  143.     new Float:X;
  144.     new Float:Y;
  145.     new Float:Z;
  146.     GetVehicleVelocity(Vehicle,X,Y,Z);
  147.     new Float:Speed;
  148.     Speed = floatsqroot(floatpower(floatabs(X),2.0) + floatpower(floatabs(Y),2.0) + floatpower(floatabs(Z),2.0)) * 200.0;
  149.     return floatround(Speed);
  150. }
  151.  
  152. public OnFilterScriptInit()
  153. {
  154.     ServerTextDrawOne = TextDrawCreate(320.000000,250.000000,"-");
  155.     TextDrawAlignment(ServerTextDrawOne,2);
  156.     TextDrawBackgroundColor(ServerTextDrawOne,80);
  157.     TextDrawFont(ServerTextDrawOne,1);
  158.     TextDrawLetterSize(ServerTextDrawOne,15.000000,30.000000);
  159.     TextDrawColor(ServerTextDrawOne,80);
  160.     TextDrawSetOutline(ServerTextDrawOne,0);
  161.     TextDrawSetProportional(ServerTextDrawOne,1);
  162.     TextDrawSetShadow(ServerTextDrawOne,1);
  163.     ServerTextDrawTwo = TextDrawCreate(320.000000,395.000000,"~W~~H~Licznik Driftu");
  164.     TextDrawAlignment(ServerTextDrawTwo,2);
  165.     TextDrawBackgroundColor(ServerTextDrawTwo,255);
  166.     TextDrawFont(ServerTextDrawTwo,3);
  167.     TextDrawLetterSize(ServerTextDrawTwo,0.500000,1.000000);
  168.     TextDrawColor(ServerTextDrawTwo,-1);
  169.     TextDrawSetOutline(ServerTextDrawTwo,1);
  170.     TextDrawSetProportional(ServerTextDrawTwo,1);
  171.     for(new Player; Player < GetMaxPlayers(); Player++)
  172.     {
  173.         ServerTextDrawThree[Player] = TextDrawCreate(250.000000,405.000000," ");
  174.         TextDrawBackgroundColor(ServerTextDrawThree[Player],255);
  175.         TextDrawFont(ServerTextDrawThree[Player],2);
  176.         TextDrawLetterSize(ServerTextDrawThree[Player],0.200000,1.000000);
  177.         TextDrawColor(ServerTextDrawThree[Player],-1);
  178.         TextDrawSetOutline(ServerTextDrawThree[Player],1);
  179.         TextDrawSetProportional(ServerTextDrawThree[Player],1);
  180.         ServerTextDrawFour[Player] = TextDrawCreate(250.000000,415.000000," ");
  181.         TextDrawBackgroundColor(ServerTextDrawFour[Player],255);
  182.         TextDrawFont(ServerTextDrawFour[Player],2);
  183.         TextDrawLetterSize(ServerTextDrawFour[Player],0.200000,1.000000);
  184.         TextDrawColor(ServerTextDrawFour[Player],-1);
  185.         TextDrawSetOutline(ServerTextDrawFour[Player],1);
  186.         TextDrawSetProportional(ServerTextDrawFour[Player],1);
  187.         ServerTextDrawFive[Player] = TextDrawCreate(250.000000,425.000000," ");
  188.         TextDrawBackgroundColor(ServerTextDrawFive[Player],255);
  189.         TextDrawFont(ServerTextDrawFive[Player],2);
  190.         TextDrawLetterSize(ServerTextDrawFive[Player],0.200000,1.000000);
  191.         TextDrawColor(ServerTextDrawFive[Player],-1);
  192.         TextDrawSetOutline(ServerTextDrawFive[Player],1);
  193.         TextDrawSetProportional(ServerTextDrawFive[Player],1);
  194.     }
  195.     ServerTimerOne = SetTimer("PlayerUpdate",1000,1);
  196.     ServerTimerTwo = SetTimer("PlayerDrift",500,1);
  197.     return 1;
  198. }
  199.  
  200. public OnFilterScriptExit()
  201. {
  202.     TextDrawDestroy(ServerTextDrawOne);
  203.     TextDrawDestroy(ServerTextDrawTwo);
  204.     for(new Player; Player < GetMaxPlayers(); Player++)
  205.     {
  206.         TextDrawDestroy(ServerTextDrawThree[Player]);
  207.         TextDrawDestroy(ServerTextDrawFour[Player]);
  208.         TextDrawDestroy(ServerTextDrawFive[Player]);
  209.     }
  210.     KillTimer(ServerTimerOne);
  211.     KillTimer(ServerTimerTwo);
  212.     return 1;
  213. }
  214.  
  215. public OnPlayerConnect(playerid)
  216. {
  217.     TextDrawHideForPlayer(playerid,ServerTextDrawOne);
  218.     TextDrawHideForPlayer(playerid,ServerTextDrawTwo);
  219.     TextDrawHideForPlayer(playerid,ServerTextDrawThree[playerid]);
  220.     TextDrawHideForPlayer(playerid,ServerTextDrawFour[playerid]);
  221.     TextDrawHideForPlayer(playerid,ServerTextDrawFive[playerid]);
  222.     TextDrawSetString(ServerTextDrawThree[playerid]," ");
  223.     TextDrawSetString(ServerTextDrawFour[playerid]," ");
  224.     TextDrawSetString(ServerTextDrawFive[playerid]," ");
  225.     PlayerUseDriftCounter[playerid] = 1;
  226.     PlayerMoney[playerid] = 0;
  227.     PlayerScore[playerid] = 0;
  228.     PlayerCombo[playerid] = 1;
  229.     PlayerPositionX[playerid] = 0.0;
  230.     PlayerPositionY[playerid] = 0.0;
  231.     PlayerPositionZ[playerid] = 0.0;
  232.     KillTimer(PlayerTimerOne[playerid]);
  233.     return 1;
  234. }
  235.  
  236. public OnPlayerDisconnect(playerid)
  237. {
  238.     TextDrawHideForPlayer(playerid,ServerTextDrawOne);
  239.     TextDrawHideForPlayer(playerid,ServerTextDrawTwo);
  240.     TextDrawHideForPlayer(playerid,ServerTextDrawThree[playerid]);
  241.     TextDrawHideForPlayer(playerid,ServerTextDrawFour[playerid]);
  242.     TextDrawHideForPlayer(playerid,ServerTextDrawFive[playerid]);
  243.     TextDrawSetString(ServerTextDrawThree[playerid]," ");
  244.     TextDrawSetString(ServerTextDrawFour[playerid]," ");
  245.     TextDrawSetString(ServerTextDrawFive[playerid]," ");
  246.     PlayerUseDriftCounter[playerid] = 1;
  247.     PlayerMoney[playerid] = 0;
  248.     PlayerScore[playerid] = 0;
  249.     PlayerCombo[playerid] = 1;
  250.     PlayerPositionX[playerid] = 0.0;
  251.     PlayerPositionY[playerid] = 0.0;
  252.     PlayerPositionZ[playerid] = 0.0;
  253.     KillTimer(PlayerTimerOne[playerid]);
  254.     return 1;
  255. }
  256.  
  257. public OnPlayerCommandText(playerid,cmdtext[])
  258. {
  259.     if(!strcmp(cmdtext,"/LicznikDriftu",true))
  260.     {
  261.         if(PlayerUseDriftCounter[playerid] == 0) PlayerUseDriftCounter[playerid] = 1 & SendClientMessage(playerid,0x00FF00FF,"Licznik driftu został włączony.");
  262.         else PlayerUseDriftCounter[playerid] = 0 & SendClientMessage(playerid,0x00FF00FF,"Licznik driftu został wyłączony.") & CallLocalFunction("PlayerDriftEnd","d",playerid);
  263.         return 1;
  264.     }
  265.     return 0;
  266. }
  267.  
  268. public PlayerUpdate()
  269. {
  270.     for(new Player; Player < GetMaxPlayers(); Player++)
  271.     {
  272.         if(IsPlayerConnected(Player) && GetPlayerState(Player) == PLAYER_STATE_DRIVER && VehicleIsCar(GetPlayerVehicleID(Player)) && PlayerUseDriftCounter[Player] == 1) GetVehiclePos(GetPlayerVehicleID(Player),PlayerPositionX[Player],PlayerPositionY[Player],PlayerPositionZ[Player]);
  273.     }
  274.     return 1;
  275. }
  276.  
  277. public PlayerDrift()
  278. {
  279.     for(new Player; Player < GetMaxPlayers(); Player++)
  280.     {
  281.         if(IsPlayerConnected(Player) && GetPlayerState(Player) == PLAYER_STATE_DRIVER && VehicleIsCar(GetPlayerVehicleID(Player)) && PlayerUseDriftCounter[Player] == 1)
  282.         {
  283.             new Float:Angle;
  284.             GetVehicleZAngle(GetPlayerVehicleID(Player),Angle);
  285.             if(floatabs(floatsub(Angle,PlayerTheoreticAngle(Player))) < 90.0 && floatabs(floatsub(Angle,PlayerTheoreticAngle(Player))) > 10.0 && VehicleSpeed(GetPlayerVehicleID(Player)) < 300 && VehicleSpeed(GetPlayerVehicleID(Player)) > 30)
  286.             {
  287.                 if(PlayerMoney[Player] == 0 && PlayerScore[Player] == 0 && PlayerCombo[Player] == 1)
  288.                 {
  289.                     TextDrawShowForPlayer(Player,ServerTextDrawOne);
  290.                     TextDrawShowForPlayer(Player,ServerTextDrawTwo);
  291.                     TextDrawShowForPlayer(Player,ServerTextDrawThree[Player]);
  292.                     TextDrawShowForPlayer(Player,ServerTextDrawFour[Player]);
  293.                     TextDrawShowForPlayer(Player,ServerTextDrawFive[Player]);
  294.                     TextDrawSetString(ServerTextDrawThree[Player]," ");
  295.                     TextDrawSetString(ServerTextDrawFour[Player]," ");
  296.                     TextDrawSetString(ServerTextDrawFive[Player]," ");
  297.                 }
  298.                 PlayerMoney[Player] += floatround(floatabs(floatsub(Angle,PlayerTheoreticAngle(Player))) * (VehicleSpeed(GetPlayerVehicleID(Player)) * 0.1)) / 10;
  299.                 PlayerScore[Player] += floatround(floatabs(floatsub(Angle,PlayerTheoreticAngle(Player))) * 3 * (VehicleSpeed(GetPlayerVehicleID(Player)) * 0.1)) / 10;
  300.                 PlayerCombo[Player] = PlayerScore[Player] / 1000;
  301.                 if(PlayerCombo[Player] < 1) PlayerCombo[Player] = 1;
  302.                 new String[100];
  303.                 format(String,sizeof(String),"~R~~H~Pieniadze Za Drift: ~W~~H~%d$",PlayerMoney[Player]);
  304.                 TextDrawSetString(ServerTextDrawThree[Player],String);
  305.                 format(String,sizeof(String),"~R~~H~Punkty Za Drift: ~W~~H~%d",PlayerScore[Player]);
  306.                 TextDrawSetString(ServerTextDrawFour[Player],String);
  307.                 format(String,sizeof(String),"~R~~H~Kombo: ~W~~H~X%d",PlayerCombo[Player]);
  308.                 TextDrawSetString(ServerTextDrawFive[Player],String);
  309.                 KillTimer(PlayerTimerOne[Player]);
  310.                 PlayerTimerOne[Player] = SetTimerEx("PlayerDriftEnd",3000,0,"d",Player);
  311.             }
  312.         }
  313.     }
  314.     return 1;
  315. }
  316.  
  317. public PlayerDriftEnd(Player)
  318. {
  319.     TextDrawHideForPlayer(Player,ServerTextDrawOne);
  320.     TextDrawHideForPlayer(Player,ServerTextDrawTwo);
  321.     TextDrawHideForPlayer(Player,ServerTextDrawThree[Player]);
  322.     TextDrawHideForPlayer(Player,ServerTextDrawFour[Player]);
  323.     TextDrawHideForPlayer(Player,ServerTextDrawFive[Player]);
  324.     TextDrawSetString(ServerTextDrawThree[Player]," ");
  325.     TextDrawSetString(ServerTextDrawFour[Player]," ");
  326.     TextDrawSetString(ServerTextDrawFive[Player]," ");
  327.     GivePlayerMoney(Player,PlayerMoney[Player]);
  328.     SetPlayerScore(Player,GetPlayerScore(Player) + PlayerScore[Player] * PlayerCombo[Player]);
  329.     PlayerMoney[Player] = 0;
  330.     PlayerScore[Player] = 0;
  331.     PlayerCombo[Player] = 1;
  332.     return 1;
  333. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement