Advertisement
Guest User

Drift Score

a guest
Apr 3rd, 2010
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.83 KB | None | 0 0
  1. #include <a_samp> // by I dont know .. :D lol
  2.  
  3. #define DRIFT_MINKAT 10.0 // by
  4. #define DRIFT_MAXKAT 90.0 // by
  5. #define DRIFT_SPEED 30.0 // by
  6.  
  7. //////////// ///////
  8. #define COLOR_Label 0xFFFFFFFF
  9. #define COLOR_LabelOut 0x00000040
  10. #define COLOR_ValueOut 0xFFFFFF40
  11. #define COLOR_Value 0x000000FF
  12.  
  13. #define Label_X 500
  14. #define Value_X 500
  15. #define TD_Y 100
  16. /////////////////////////////////////
  17.  
  18. new DriftTimer[MAX_PLAYERS]; //
  19. new TimerA,TimerB,TimerC; //
  20.  
  21. new DriftPointsNow[MAX_PLAYERS]; // by
  22. new PlayerDriftCancellation[MAX_PLAYERS]; // by
  23. new Float:ppos[MAX_PLAYERS][3]; // by
  24. enum Float:Pos{ Float:sX,Float:sY,Float:sZ }; // by
  25. new Float:SavedPos[MAX_PLAYERS][Pos]; // by
  26.  
  27. new bool:DriftMode[MAX_PLAYERS]=false; // Added b
  28. new DriftBonus[MAX_PLAYERS]=1; // Added by
  29. new Float:HealthInit[MAX_PLAYERS]=1000.0; // Added b
  30. new bool:AutoFixBool[MAX_PLAYERS]=true; // Added by
  31.  
  32. new Text:TDLabels[3]; // Added by
  33. new Text:TDValueDrift[MAX_PLAYERS]; // Added by
  34. new Text:TDValueBonus[MAX_PLAYERS]; // Added by
  35. new Text:TDValueCash[MAX_PLAYERS]; // Added by
  36. new score;
  37.  
  38. forward Drift(playerid); // by
  39. forward AngleUpdate(); // by
  40. forward DriftExit(playerid); // by
  41. forward CheckPlayerState(); // Added
  42. forward AutoFix(); // Added by
  43.  
  44. public OnFilterScriptInit()
  45. {
  46.         TimerA=SetTimer("AngleUpdate", 200, true); // by
  47.         TimerB=SetTimer("AutoFix", 500, true); //by A
  48.         TimerC=SetTimer("CheckPlayerState", 100, true); //b
  49.         LoadTextDraws();
  50.         return 1;
  51. }
  52.  
  53. public OnFilterScriptExit(){
  54. KillTimer(TimerA);
  55. KillTimer(TimerB);
  56. KillTimer(TimerC);
  57. return 1;
  58. }
  59.  
  60. Float:GetPlayerTheoreticAngle(i) // By
  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.  
  74.                 dis = floatsqroot(floatpower(floatabs(floatsub(x,ppos[i][0])),2)+floatpower(floatabs(floatsub(y,ppos[i][1])),2));
  75.  
  76.                 if(IsPlayerInAnyVehicle(i)){GetVehicleZAngle(GetPlayerVehicleID(i), angle2);}else{GetPlayerFacingAngle(i, angle2);}
  77.  
  78.                 if(x>ppos[i][0]){tmp3=x-ppos[i][0];}else{tmp3=ppos[i][0]-x;}
  79.                 if(y>ppos[i][1]){tmp4=y-ppos[i][1];}else{tmp4=ppos[i][1]-y;}
  80.  
  81.                 if(ppos[i][1]>y && ppos[i][0]>x){
  82.                 sin = asin(tmp3/dis);
  83.                 MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
  84.                 }
  85.  
  86.                 if(ppos[i][1]<y && ppos[i][0]>x){
  87.                     sin = asin(tmp3/dis);
  88.                     MindAngle = floatsub(floatadd(sin, 180), 180.0);
  89.                 }
  90.  
  91.                 if(ppos[i][1]<y && ppos[i][0]<x){
  92.                     sin = acos(tmp4/dis);
  93.                     MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
  94.                 }
  95.  
  96.                 if(ppos[i][1]>y && ppos[i][0]<x){
  97.                     sin = asin(tmp3/dis);
  98.                     MindAngle = floatadd(sin, 180);
  99.                 }
  100.         }
  101.  
  102.         if(MindAngle == 0.0){return angle2;}else{return MindAngle;}
  103. }
  104.  
  105. public DriftExit(playerid){ // By
  106.         PlayerDriftCancellation[playerid] = 0;
  107.  
  108. ////////////////// by ///////////////////
  109.         new Float:h;
  110.         GetVehicleHealth(GetPlayerVehicleID(playerid),h);
  111.         if(DriftPointsNow[playerid]>70 && DriftPointsNow[playerid]<10000 && h==HealthInit[playerid]) GivePlayerMoney(playerid,DriftPointsNow[playerid]*DriftBonus[playerid]);
  112.         TextDrawHideForPlayer(playerid,TDLabels[0]);
  113.         TextDrawHideForPlayer(playerid,TDLabels[1]);
  114.         TextDrawHideForPlayer(playerid,TDLabels[2]);
  115.         TextDrawHideForPlayer(playerid,TDValueDrift[playerid]);
  116.         TextDrawHideForPlayer(playerid,TDValueBonus[playerid]);
  117.         TextDrawHideForPlayer(playerid,TDValueCash[playerid]);
  118.         DriftBonus[playerid]=1;
  119.         AutoFixBool[playerid]=true;
  120.         SetVehicleHealth(GetPlayerVehicleID(playerid),HealthInit[playerid]);
  121.         ////////////////////////////////////////////////////
  122.  
  123.         DriftPointsNow[playerid] = 0;
  124. }
  125.  
  126. Float:ReturnPlayerAngle(playerid){ // By
  127.         new Float:Ang;
  128.         if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang); else GetPlayerFacingAngle(playerid, Ang);
  129.         return Ang;
  130. }
  131.  
  132. public Drift(playerid){ // By Luby
  133.         new Float:Angle1, Float:Angle2, Float:BySpeed;
  134.         new Float:Z;
  135.         new Float:X;
  136.         new Float:Y;
  137.         new Float:SpeedX;
  138.         for(new g=0;g<200;g++){
  139.                 GetPlayerPos(g, X, Y, Z);
  140.                 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)));
  141.                 Angle1 = ReturnPlayerAngle(g);
  142.                 Angle2 = GetPlayerTheoreticAngle(g);
  143.                 BySpeed = floatmul(SpeedX, 12);
  144.                 if(IsPlayerInAnyVehicle(g) && GetVType(GetPlayerVehicleID(g)) && floatabs(floatsub(Angle1, Angle2)) > DRIFT_MINKAT && floatabs(floatsub(Angle1, Angle2)) < DRIFT_MAXKAT && BySpeed > DRIFT_SPEED){
  145.                         if(PlayerDriftCancellation[g] > 0)KillTimer(PlayerDriftCancellation[g]);
  146.                         PlayerDriftCancellation[g] = 0;
  147.                         DriftPointsNow[g] += floatval( floatabs(floatsub(Angle1, Angle2)) * 3 * (BySpeed*0.1) )/10;
  148.                         PlayerDriftCancellation[g] = SetTimerEx("DriftExit", 3000, 0, "d", g);
  149.                 }
  150.  
  151.                 if(DriftPointsNow[g] > 70 && DriftPointsNow[g]<10000){
  152.                     ///////////// by A////////////////////
  153.                     if(DriftPointsNow[g]<200){
  154.                         DriftBonus[g]=1;
  155. }
  156. if(DriftPointsNow[g]>=200 && DriftPointsNow[g]<500){
  157. DriftBonus[g]=2;
  158. SetPlayerScore(playerid, score + 20); // <<<<<<<<< SCORE AKI
  159. }
  160. if(DriftPointsNow[g]>=500 && DriftPointsNow[g]<1000){
  161. DriftBonus[g]=3;
  162. SetPlayerScore(playerid, score + 30); // <<<<<<<<< SCORE AKI
  163. }
  164. if(DriftPointsNow[g]>=1000 && DriftPointsNow[g]<1500){
  165. DriftBonus[g]=4;
  166. SetPlayerScore(playerid, score + 40); // <<<<<<<<< SCORE AKI
  167. }
  168. if(DriftPointsNow[g]>=1500){
  169. DriftBonus[g]=5;
  170. SetPlayerScore(playerid, score + 50); // <<<<<<<<< SCORE AKI
  171. }
  172.  
  173. TextDrawShowForPlayer(g,TDLabels[0]);
  174. TextDrawShowForPlayer(g,TDLabels[1]);
  175. TextDrawShowForPlayer(g,TDLabels[2]);
  176.  
  177. TextDrawShowForPlayer(g,TDValueDrift[g]);
  178. TextDrawShowForPlayer(g,TDValueBonus[g]);
  179. TextDrawShowForPlayer(g,TDValueCash[g]);
  180.  
  181. new DPs[128],DBn[128],Cash[128],csh;
  182.  
  183. valstr(DPs,DriftPointsNow[g],false);
  184. format(DBn,sizeof(DBn),"X%i",DriftBonus[g]);
  185. csh=DriftPointsNow[g]*DriftBonus[g];
  186. format(Cash,sizeof(Cash),"$%i",csh);
  187.  
  188. TextDrawSetString(TDValueDrift[g],DPs);
  189. TextDrawSetString(TDValueBonus[g],DBn);
  190. TextDrawSetString(TDValueCash[g],Cash);
  191. ////////////////////////////////////////
  192.                 }
  193.                 SavedPos[ g ][ sX ] = X;
  194.                 SavedPos[ g ][ sY ] = Y;
  195.                 SavedPos[ g ][ sZ ] = Z;
  196.         }
  197. }
  198.  
  199. public AngleUpdate(){ // By
  200.         for(new g=0;g<=MAX_PLAYERS;g++){
  201.                 new Float:x, Float:y, Float:z;
  202.                 if(IsPlayerInAnyVehicle(g))GetVehiclePos(GetPlayerVehicleID(g), x, y, z); else GetPlayerPos(g, x, y, z);
  203.                 ppos[g][0] = x;
  204.                 ppos[g][1] = y;
  205.                 ppos[g][2] = z;
  206.         }
  207. }
  208.  
  209. floatval(Float:val){ // By
  210.         new str[256];
  211.         format(str, 256, "%.0f", val);
  212.         return todec(str);
  213. }
  214.  
  215. todec(str[]){ // By Luby
  216.         return strval(str);
  217. }
  218.  
  219. LoadTextDraws(){ // by
  220. TDLabels[0]=TextDrawCreate(Label_X,TD_Y,"Pontos No Drift");
  221. TextDrawColor(TDLabels[0],COLOR_Label);
  222. TextDrawSetShadow(TDLabels[0],0);
  223. TextDrawSetOutline(TDLabels[0],1);
  224. TextDrawLetterSize(TDLabels[0],0.5,2);
  225. TextDrawBackgroundColor(TDLabels[0],COLOR_LabelOut);
  226. TextDrawFont(TDLabels[0],1);
  227.  
  228. TDLabels[1]=TextDrawCreate(Label_X,TD_Y+50,"Bonus Do Drift");
  229. TextDrawColor(TDLabels[1],COLOR_Label);
  230. TextDrawSetShadow(TDLabels[1],0);
  231. TextDrawSetOutline(TDLabels[1],1);
  232. TextDrawLetterSize(TDLabels[1],0.5,2);
  233. TextDrawBackgroundColor(TDLabels[1],COLOR_LabelOut);
  234. TextDrawFont(TDLabels[1],1);
  235.  
  236. TDLabels[2]=TextDrawCreate(Label_X,TD_Y+100,"Grana Do Drift");
  237. TextDrawColor(TDLabels[2],COLOR_Label);
  238. TextDrawSetShadow(TDLabels[2],0);
  239. TextDrawSetOutline(TDLabels[2],1);
  240. TextDrawLetterSize(TDLabels[2],0.5,2);
  241. TextDrawBackgroundColor(TDLabels[2],COLOR_LabelOut);
  242. TextDrawFont(TDLabels[2],1);
  243.  
  244. new i;
  245. for(i=0;i<=MAX_PLAYERS;i++){
  246. TDValueDrift[i]=TextDrawCreate(Value_X,TD_Y+20,"0");
  247. TextDrawColor(TDValueDrift[i],COLOR_Value);
  248. TextDrawSetShadow(TDValueDrift[i],0);
  249. TextDrawSetOutline(TDValueDrift[i],1);
  250. TextDrawLetterSize(TDValueDrift[i],0.5,2);
  251. TextDrawBackgroundColor(TDValueDrift[i],COLOR_ValueOut);
  252. TextDrawFont(TDValueDrift[i],3);
  253.  
  254. TDValueBonus[i]=TextDrawCreate(Value_X,TD_Y+70,"X1");
  255. TextDrawColor(TDValueBonus[i],COLOR_Value);
  256. TextDrawSetShadow(TDValueBonus[i],0);
  257. TextDrawSetOutline(TDValueBonus[i],1);
  258. TextDrawLetterSize(TDValueBonus[i],0.5,2);
  259. TextDrawBackgroundColor(TDValueBonus[i],COLOR_ValueOut);
  260. TextDrawFont(TDValueBonus[i],3);
  261.  
  262. TDValueCash[i]=TextDrawCreate(Value_X,TD_Y+120,"$0");
  263. TextDrawColor(TDValueCash[i],COLOR_Value);
  264. TextDrawSetShadow(TDValueCash[i],0);
  265. TextDrawSetOutline(TDValueCash[i],1);
  266. TextDrawLetterSize(TDValueCash[i],0.5,2);
  267. TextDrawBackgroundColor(TDValueCash[i],COLOR_ValueOut);
  268. TextDrawFont(TDValueCash[i],3);
  269. }
  270.  
  271. return 1;
  272. }
  273.  
  274. public CheckPlayerState(){ //by
  275. new i,cs;
  276.  
  277. for(i=0;i<=MAX_PLAYERS;i++){
  278.    cs=GetPlayerState(i);
  279.    if(DriftMode[i] && cs==PLAYER_STATE_DRIVER && DriftPointsNow[i]>70){
  280.        new Float:h;
  281.        GetVehicleHealth(GetPlayerVehicleID(i),h);
  282.        if(h<HealthInit[i]){
  283.         KillTimer(DriftTimer[i]);
  284.         DriftExit(i);
  285.         GameTextForPlayer(i,"~n~~n~~n~~n~~n~~r~Bateu PerdeO",800,5);
  286.         DriftMode[i]=false;
  287. }
  288. }
  289.    if(cs==PLAYER_STATE_DRIVER && DriftMode[i]==false){
  290.        if(GetVType(GetPlayerVehicleID(i))){
  291.        DriftMode[i]=true;
  292.        GetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
  293.        AutoFixBool[i]=false;
  294.        DriftTimer[i]=SetTimerEx("Drift", 200, true, "i", i);
  295. }
  296. }
  297.     else if(cs!=PLAYER_STATE_DRIVER && DriftMode[i]==true){
  298.    KillTimer(DriftTimer[i]);
  299.    DriftMode[i]=false;
  300.    AutoFixBool[i]=true;
  301. }
  302.     else{}
  303. }
  304. return 1;
  305. }
  306.  
  307. public AutoFix(){ // By
  308. new i;
  309. for(i=0;i<=MAX_PLAYERS;i++){
  310. if(AutoFixBool[i] && IsPlayerInAnyVehicle(i)){
  311. SetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
  312. }
  313. }
  314. }
  315.  
  316. GetVType(vid){ // By
  317.  
  318. new Convertibles[4]={480, 533, 439, 555};
  319. new Industrial[26]={499, 422, 482, 498, 609, 524, 578, 455, 403, 414, 582, 443, 514, 413, 515, 440, 543, 605, 459, 531, 408, 552, 478, 456, 554};
  320. new LowRider[8]={536, 575, 534, 567, 535, 566, 576, 412};
  321. new OffRoad[13]={568, 424, 573, 579, 400, 500, 444, 556, 557, 470, 489, 505, 595};
  322. new Service[19]={416, 433, 431, 438, 437, 523, 427, 490, 528, 407, 544, 596, 596, 597, 598, 599, 432, 601, 420};
  323. new Saloon[35]={445, 504, 401, 518, 527, 542, 507, 562, 585, 419, 526, 604, 466, 492, 474, 546, 517, 410, 551, 516, 467, 600, 426, 436, 547, 405, 580, 560, 550, 549, 540, 491, 529, 421};
  324. new Sports[20]={602, 429, 496, 402, 541, 415, 589, 587, 565, 494, 502, 503, 411, 559, 603, 475, 506, 451, 558, 477};
  325. new Wagons[5]={418, 404, 479, 458, 561};
  326.  
  327. new modelid=GetVehicleModel(vid);
  328. new i;
  329. for(i=0;i<3;i++){
  330.    if(Convertibles[i]==modelid) return 1;
  331. }
  332. for(i=0;i<25;i++){
  333.    if(Industrial[i]==modelid) return 1;
  334. }
  335. for(i=0;i<7;i++){
  336.    if(LowRider[i]==modelid) return 1;
  337. }
  338. for(i=0;i<12;i++){
  339.    if(OffRoad[i]==modelid) return 1;
  340. }
  341. for(i=0;i<19;i++){
  342.    if(Service[i]==modelid) return 1;
  343. }
  344. for(i=0;i<35;i++){
  345.    if(Saloon[i]==modelid) return 1;
  346. }
  347. for(i=0;i<20;i++){
  348.    if(Sports[i]==modelid) return 1;
  349. }
  350. for(i=0;i<5;i++){
  351.    if(Wagons[i]==modelid) return 1;
  352. }
  353. return 0;
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement