Advertisement
Shiny_

Untitled

Sep 12th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.19 KB | None | 0 0
  1.     float floatadd(float val_1, float val_2) {
  2.         return val_2 = val_1 + val_2;
  3.     }
  4.  
  5.     float floatsub(float val_1, float val_2) {
  6.         return val_2 = val_2 - val_1;
  7.     }
  8.  
  9.     float floatmul(float val_1, float val_2) {
  10.         return val_2 = val_1 * val_2;
  11.     }
  12.  
  13.     float ReturnPlayerAngle(int playerid) {
  14.         float Ang;
  15.         IsPlayerInAnyVehicle(playerid)? GetVehicleZAngle(GetPlayerVehicleID(playerid), &Ang): GetPlayerFacingAngle(playerid, &Ang);
  16.         return Ang;
  17.     }
  18.  
  19.     float GetPlayerTheoreticAngle(int i) {
  20.         float Sin_Dis[2];
  21.         float Positions[5];
  22.         float Temporary[2];
  23.        
  24.         if(IsPlayerConnected(i)) {
  25.             GetPlayerPos(i, &Positions[0], &Positions[1], &Positions[2]);
  26.             Sin_Dis[1] = sqrtf(powf(fabs(floatsub(Positions[0], ppos[i][0])), 2)
  27.                 +
  28.                 powf(fabs(floatsub(Positions[1], ppos[i][1])), 2));
  29.             IsPlayerInAnyVehicle(i)? GetVehicleZAngle(GetPlayerVehicleID(i), &Positions[3]): GetPlayerFacingAngle(i, &Positions[3]);
  30.             Positions[0] > ppos[i][0]? Temporary[0] = Positions[0] - ppos[i][0]: Temporary[0] = ppos[i][0] - Positions[0];
  31.             Positions[1] > ppos[i][1]? Temporary[1] = Positions[1] - ppos[i][1]: Temporary[1] = ppos[i][1] - Positions[1];
  32.            
  33.             if(ppos[i][1] > Positions[1] && ppos[i][0] > Positions[0]) {
  34.                 Sin_Dis[0] = asin(Temporary[0] / Sin_Dis[1]);
  35.                 Positions[4] = floatsub(floatsub(floatadd(Sin_Dis[0], 90), floatmul(Sin_Dis[0], 2)), -90.0);
  36.             }
  37.             else if(ppos[i][1] < Positions[1] && ppos[i][0] > Positions[0]) {
  38.                 Sin_Dis[0] = asin(Temporary[0] / Sin_Dis[1]);
  39.                 Positions[4] = floatsub(floatadd(Sin_Dis[0], 180), 180.0);
  40.             }
  41.             else if(ppos[i][1] < Positions[1] && ppos[i][0] < Positions[0]) {
  42.                 Sin_Dis[0] = acos(Temporary[1] / Sin_Dis[1]);
  43.                 Positions[4] = floatsub(floatadd(Sin_Dis[0], 360), floatmul(Sin_Dis[0], 2));
  44.             }
  45.             else if(ppos[i][1] > Positions[1] && ppos[i][0] < Positions[0]) {
  46.                 Sin_Dis[0] = asin(Temporary[0] / Sin_Dis[1]);
  47.                 Positions[4] = floatadd(Sin_Dis[0], 180);
  48.             }
  49.         }
  50.         Positions[4] == 0.0? Positions[3]: Positions[4];
  51.     }
  52.  
  53.     bool IsCar(int veh_id) {
  54.         switch(GetVehicleModel(veh_id)) {
  55.             case 443: case 448: case 461: case 462: case 463: case 468:
  56.             case 521: case 522: case 523: case 581: case 586: case 481:
  57.             case 509: case 510: case 430: case 446: case 452: case 453:
  58.             case 454: case 472: case 473: case 484: case 493: case 595:
  59.             case 417: case 425: case 447: case 465: case 469: case 487:
  60.             case 488: case 497: case 501: case 548: case 563: case 406:
  61.             case 444: case 556: case 557: case 573: case 460: case 464:
  62.             case 476: case 511: case 512: case 513: case 519: case 520:
  63.             case 539: case 553: case 577: case 592: case 593: case 471:
  64.             return false;
  65.             break;
  66.         }
  67.         return true;
  68.     }
  69.  
  70.     float floatval(float val) {
  71.         char str[128];
  72.         sprintf(str, "%.0f", val);
  73.         return (float) atoi(str);
  74.     }
  75.  
  76. // Timers:
  77.     function void SAMPGDK_CALL Clear3DTexts(int, void *) {
  78.         int playerid = NULL;
  79.         foreach(playerid, MAX_PLAYERS + 1) {
  80.             UpdatePlayer3DTextLabelText(playerid, Drift3DText[playerid], -1, " ");
  81.             IsValidObject(CarFireObject[playerid])? DestroyObject(CarFireObject[playerid]): false;
  82.             RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  83.         }
  84.     }
  85.  
  86.     function void SAMPGDK_CALL LoadDrift(int, void *) {
  87.         int playerid;
  88.         foreach(playerid, MAX_PLAYERS + 1) {
  89.             Timer_PlayerDriftPoints[playerid] = 0;
  90.             GivePlayerMoney(playerid, PointsFromDrift[playerid] / 2);
  91.             GivePlayerScore(playerid, PointsFromDrift[playerid]);
  92.             PointsFromDrift[playerid] = 0;
  93.             Timer_Clear3DTexts[playerid] = SetTimer(Clear3DTexts, 100, false);
  94.             // = SetTimer(Clear3DTexts, 100, false);
  95.         }
  96.     }
  97.  
  98.     function void SAMPGDK_CALL CountDrift(int, void *) {
  99.         int playerid = 0;
  100.         float Angle[2];
  101.         float Speed[2];
  102.         float Position[3];
  103.         char s[96];
  104.         float sX[MAX_PLAYERS];
  105.         float sY[MAX_PLAYERS];
  106.         float sZ[MAX_PLAYERS];
  107.            
  108.         foreach(playerid, MAX_PLAYERS + 1) {
  109.             GetPlayerPos(playerid, &Position[0], &Position[1], &Position[2]);
  110.             Speed[1] = sqrtf(floatadd(floatadd(powf(fabs(floatsub(Position[0], sX[playerid])), 2), powf(fabs(floatsub(Position[1], sY[playerid])), 2)), powf(fabs(floatsub(Position[2], sZ[playerid])), 2)));
  111.             Angle[0] = ReturnPlayerAngle(playerid);
  112.             Angle[1] = GetPlayerTheoreticAngle(playerid);
  113.             Speed[0] = floatmul(Speed[1], 12);
  114.            
  115.             if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && IsCar(GetPlayerVehicleID(playerid)) && fabs(floatsub(Angle[0], Angle[1])) > MinAngle_Drift && fabs(floatsub(Angle[0], Angle[1])) < MaxAngle_Drift && Speed[0] > MaxSpeed_Drift) {
  116.                 if(Timer_PlayerDriftPoints[playerid] > 0) KillTimer(Timer_PlayerDriftPoints[playerid]);
  117.                 Timer_PlayerDriftPoints[playerid] = 0;
  118.                 PointsFromDrift[playerid] += floatval(fabs(floatsub(Angle[0], Angle[1])) * 3 * (Speed[0] * 0.1)) / 10.0;
  119.                 Timer_PlayerDriftPoints[playerid] = SetTimer(LoadDrift, 3000, 0);
  120.             }
  121.  
  122.             if(PointsFromDrift[playerid] > 0) {
  123.                 sprintf(s, "\n\n\n%d $\n%d %s\n~k~~VEHICLE_FIREWEAPON~ - {FF0000}Nitro{FFFFFF}!", PointsFromDrift[playerid] / 2, PointsFromDrift[playerid], dli(PointsFromDrift[playerid], "Punkt", "Punkty", "Punktów"));
  124.                 UpdatePlayer3DTextLabelText(playerid, Drift3DText[playerid], -1, s);
  125.             }
  126.             sX[playerid] = Position[0];
  127.             sY[playerid] = Position[1];
  128.             sZ[playerid] = Position[2];
  129.         }
  130.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement