Advertisement
Guest User

driftcount

a guest
Dec 18th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.12 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////
  2. /////////////// DRIFT POINTS COUNTER BY Luby ///////////////
  3. /////////////// A little editted by Florinca//////////////
  4. //-Keep Credits-//
  5.  
  6. //////////////NOW NEW updated by Florinca ////////////////
  7.  
  8. ////////////////////////////////////////////////////////////
  9.  
  10. #include <a_samp>// by I dont know .. :D lol
  11.  
  12. #define DRIFT_MINKAT 10.0 // by Florinca
  13. #define DRIFT_MAXKAT 90.0 // by Florinca
  14. #define DRIFT_SPEED 30.0 // by Luby
  15. #define PATH "/Driftscore/%s.ini"
  16.  
  17. //////////// Added by Florinca///////
  18. #define COLOR_Label 0xFFFFFFFF
  19. #define COLOR_LabelOut 0x00000040
  20. #define COLOR_ValueOut 0xFFFFFF40
  21. #define COLOR_Value 0x000000FF
  22.  
  23. /////////////////////////////////////
  24.  
  25. new DriftTimer[MAX_PLAYERS]; // Added by Florinca
  26. new TimerA,TimerB,TimerC; // Added by Abhinav
  27.  
  28. new DriftPointsNow[MAX_PLAYERS]; // by Florinca
  29. new PlayerDriftCancellation[MAX_PLAYERS]; // by Luby
  30. new Float:ppos[MAX_PLAYERS][3]; // by Luby
  31. enum Float:Pos{ Float:sX,Float:sY,Float:sZ }; // by Luby
  32. new Float:SavedPos[MAX_PLAYERS][Pos]; // by Luby
  33.  
  34. new bool:DriftMode[MAX_PLAYERS]=false; // Added by Florinca
  35. new DriftBonus[MAX_PLAYERS]=1; // Added by Abhinav
  36. new Float:HealthInit[MAX_PLAYERS]=1000.0; // Added by Abhinav
  37. new bool:AutoFixBool[MAX_PLAYERS]=true; // Added by Florinca
  38.  
  39. new Text:TDLabels[3]; // Added by Abhinav
  40. new Text:TDValueDrift[MAX_PLAYERS]; // Added by Abhinav
  41. new Text:TDValueBonus[MAX_PLAYERS]; // Added by Abhinav
  42. new Text:TDValueCash[MAX_PLAYERS]; // Added by Florinca
  43.  
  44. new Text:Textdraw0;
  45.  
  46. forward Drift(); // by Florinca
  47. forward AngleUpdate(); // by Luby
  48. forward DriftExit(playerid); // by Luby
  49. forward CheckPlayerState(); // Added by Florinca
  50. forward AutoFix(); // Added by Abhinav
  51.  
  52.  
  53. public OnFilterScriptInit(){
  54. TimerA=SetTimer("AngleUpdate", 200, true); // by Luby
  55. TimerB=SetTimer("AutoFix", 500, true); //by Florinca
  56. TimerC=SetTimer("CheckPlayerState", 100, true); //by Abhinav
  57. LoadTextDraws();
  58. return 1;
  59. }
  60.  
  61. public OnFilterScriptExit(){
  62. KillTimer(TimerA);
  63. KillTimer(TimerB);
  64. KillTimer(TimerC);
  65. return 1;
  66. }
  67.  
  68. Float:GetPlayerTheoreticAngle(i) // By Luby
  69. {
  70. new Float:sin;
  71. new Float:dis;
  72. new Float:angle2;
  73. new Float:x,Float:y,Float:z;
  74. new Float:tmp3;
  75. new Float:tmp4;
  76. new Float:MindAngle;
  77.  
  78. if(IsPlayerConnected(i)){
  79.  
  80. GetPlayerPos(i,x,y,z);
  81.  
  82. dis = floatsqroot(floatpower(floatabs(floatsub(x,ppos[i][0])),2)+floatpower(floatabs(floatsub(y,ppos[i][1])),2));
  83.  
  84. if(IsPlayerInAnyVehicle(i)){GetVehicleZAngle(GetPlayerVehicleID(i), angle2);}else{GetPlayerFacingAngle(i, angle2);}
  85.  
  86. if(x>ppos[i][0]){tmp3=x-ppos[i][0];}else{tmp3=ppos[i][0]-x;}
  87. if(y>ppos[i][1]){tmp4=y-ppos[i][1];}else{tmp4=ppos[i][1]-y;}
  88.  
  89. if(ppos[i][1]>y && ppos[i][0]>x){
  90. sin = asin(tmp3/dis);
  91. MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
  92. }
  93.  
  94. if(ppos[i][1]<y && ppos[i][0]>x){
  95. sin = asin(tmp3/dis);
  96. MindAngle = floatsub(floatadd(sin, 180), 180.0);
  97. }
  98.  
  99. if(ppos[i][1]<y && ppos[i][0]<x){
  100. sin = acos(tmp4/dis);
  101. MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
  102. }
  103.  
  104. if(ppos[i][1]>y && ppos[i][0]<x){
  105. sin = asin(tmp3/dis);
  106. MindAngle = floatadd(sin, 180);
  107. }
  108. }
  109.  
  110. if(MindAngle == 0.0){return angle2;}else{return MindAngle;}
  111. }
  112.  
  113. public DriftExit(playerid){ // By Florinca
  114. PlayerDriftCancellation[playerid] = 0;
  115.  
  116. ////////////////// by Florinca ///////////////////
  117. new Float:h;
  118. GetVehicleHealth(GetPlayerVehicleID(playerid),h);
  119. if(DriftPointsNow[playerid]>70 && DriftPointsNow[playerid]<100000 && h==HealthInit[playerid]) SetPlayerScore(playerid,DriftPointsNow[playerid]*DriftBonus[playerid]*3);
  120. TextDrawHideForPlayer(playerid,TDLabels[0]);
  121. TextDrawHideForPlayer(playerid,TDLabels[1]);
  122. TextDrawHideForPlayer(playerid,TDLabels[2]);
  123. TextDrawHideForPlayer(playerid,TDValueDrift[playerid]);
  124. TextDrawHideForPlayer(playerid,TDValueBonus[playerid]);
  125. TextDrawHideForPlayer(playerid,TDValueCash[playerid]);
  126.  
  127. TextDrawHideForPlayer(playerid,Textdraw0);//added by Jagat
  128.  
  129. DriftBonus[playerid]=1;
  130. AutoFixBool[playerid]=true;
  131. SetVehicleHealth(GetPlayerVehicleID(playerid),HealthInit[playerid]);
  132. ////////////////////////////////////////////////////
  133.  
  134. DriftPointsNow[playerid] = 0;
  135. }
  136.  
  137. Float:ReturnPlayerAngle(playerid){ // By Luby
  138. new Float:Ang;
  139. if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang); else GetPlayerFacingAngle(playerid, Ang);
  140. return Ang;
  141. }
  142.  
  143. public Drift(){ // By Florinca
  144. new Float:Angle1, Float:Angle2, Float:BySpeed;
  145. new Float:Z;
  146. new Float:X;
  147. new Float:Y;
  148. new Float:SpeedX;
  149. for(new g=0;g<200;g++){
  150. GetPlayerPos(g, X, Y, Z);
  151. 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)));
  152. Angle1 = ReturnPlayerAngle(g);
  153. Angle2 = GetPlayerTheoreticAngle(g);
  154. BySpeed = floatmul(SpeedX, 12);
  155. if(IsPlayerInAnyVehicle(g) && GetVType(GetPlayerVehicleID(g)) && floatabs(floatsub(Angle1, Angle2)) > DRIFT_MINKAT && floatabs(floatsub(Angle1, Angle2)) < DRIFT_MAXKAT && BySpeed > DRIFT_SPEED){
  156. if(PlayerDriftCancellation[g] > 0)KillTimer(PlayerDriftCancellation[g]);
  157. PlayerDriftCancellation[g] = 0;
  158. DriftPointsNow[g] += floatval( floatabs(floatsub(Angle1, Angle2)) * 4.1 * (BySpeed*0.2) )/10;
  159. PlayerDriftCancellation[g] = SetTimerEx("DriftExit", 3000, 0, "d", g);
  160. }
  161.  
  162. if(DriftPointsNow[g] > 70 && DriftPointsNow[g]<10000){
  163. ///////////// by Florinca ////////////////////
  164. if(DriftPointsNow[g]<500){
  165. DriftBonus[g]=1;
  166. }
  167. //edited all by Jagat
  168. if(DriftPointsNow[g]>=500 && DriftPointsNow[g]<700){
  169. DriftBonus[g]=2;
  170. }
  171. if(DriftPointsNow[g]>=700 && DriftPointsNow[g]<1200){
  172. DriftBonus[g]=3;
  173. }
  174. if(DriftPointsNow[g]>=1200 && DriftPointsNow[g]<1700){
  175. DriftBonus[g]=4;
  176. }
  177. if(DriftPointsNow[g]>=1700 && DriftPointsNow[g]<2500){
  178. DriftBonus[g]=5;
  179. }
  180. if(DriftPointsNow[g]>=2500 && DriftPointsNow[g]<3000){
  181. DriftBonus[g]=6;
  182. }
  183. if(DriftPointsNow[g]>=3000 && DriftPointsNow[g]<5000){
  184. DriftBonus[g]=7;
  185. }
  186. if(DriftPointsNow[g]>=5000 && DriftPointsNow[g]<7400){
  187. DriftBonus[g]=8;
  188. }
  189. if(DriftPointsNow[g]>=7400 && DriftPointsNow[g]<10000){
  190. DriftBonus[g]=9;
  191. }
  192. if(DriftPointsNow[g]>=10000 && DriftPointsNow[g]<13570){
  193. DriftBonus[g]=10;
  194. }
  195. if(DriftPointsNow[g]>=13570 && DriftPointsNow[g]<15345){
  196. DriftBonus[g]=11;
  197. }
  198. if(DriftPointsNow[g]>=17800 && DriftPointsNow[g]<19999){
  199. DriftBonus[g]=12;
  200. }
  201. if(DriftPointsNow[g]>=22085 && DriftPointsNow[g]<23467){
  202. DriftBonus[g]=13;
  203. }
  204. if(DriftPointsNow[g]>=23467 && DriftPointsNow[g]<25000){
  205. DriftBonus[g]=14;
  206. }
  207. if(DriftPointsNow[g]>=25000){
  208. DriftBonus[g]=15;
  209. }
  210.  
  211. TextDrawShowForPlayer(g,TDLabels[0]);
  212. TextDrawShowForPlayer(g,TDLabels[1]);
  213. TextDrawShowForPlayer(g,TDLabels[2]);
  214.  
  215. TextDrawShowForPlayer(g,TDValueDrift[g]);
  216. TextDrawShowForPlayer(g,TDValueBonus[g]);
  217. TextDrawShowForPlayer(g,TDValueCash[g]);
  218.  
  219. TextDrawShowForPlayer(g,Textdraw0);//added by Jagat
  220.  
  221.  
  222.  
  223. new DPs[128],DBn[128],Cash[128],csh;
  224.  
  225. valstr(DPs,DriftPointsNow[g],false);
  226. format(DBn,sizeof(DBn),"X%i",DriftBonus[g]);
  227. csh=DriftPointsNow[g]*DriftBonus[g];
  228. format(Cash,sizeof(Cash),"$%i",csh);
  229.  
  230. TextDrawSetString(TDValueDrift[g],DPs);
  231. TextDrawSetString(TDValueBonus[g],DBn);
  232. TextDrawSetString(TDValueCash[g],Cash);
  233. ////////////////////////////////////////
  234. }
  235. SavedPos[ g ][ sX ] = X;
  236. SavedPos[ g ][ sY ] = Y;
  237. SavedPos[ g ][ sZ ] = Z;
  238. }
  239. }
  240.  
  241. public AngleUpdate(){ // By Florinca
  242. for(new g=0;g<=MAX_PLAYERS;g++){
  243. new Float:x, Float:y, Float:z;
  244. if(IsPlayerInAnyVehicle(g))GetVehiclePos(GetPlayerVehicleID(g), x, y, z); else GetPlayerPos(g, x, y, z);
  245. ppos[g][0] = x;
  246. ppos[g][1] = y;
  247. ppos[g][2] = z;
  248. }
  249. }
  250.  
  251. floatval(Float:val){ // By Luby
  252. new str[256];
  253. format(str, 256, "%.0f", val);
  254. return todec(str);
  255. }
  256.  
  257. todec(str[]){ // By Luby
  258. return strval(str);
  259. }
  260.  
  261. LoadTextDraws(){// by Abhinav
  262. //edited all text draws by Jagat
  263.  
  264. Textdraw0 = TextDrawCreate(322.000000, 338.000000, "~n~");
  265. TextDrawLetterSize(Textdraw0, 1.600000, 6.359762);
  266. TextDrawSetOutline(Textdraw0, 3);
  267. TextDrawTextSize(Textdraw0, 146.000000, 4.000000);//-------------------------~|~
  268.  
  269. TDLabels[0]=TextDrawCreate(160.000000, 348.000000,"Drift Points:");
  270. TextDrawColor(TDLabels[0],0x33AA33AA);
  271. TextDrawSetShadow(TDLabels[0],0);
  272. TextDrawSetOutline(TDLabels[0],3);
  273. TextDrawLetterSize(TDLabels[0],0.36,1.123);
  274. TextDrawBackgroundColor(TDLabels[0],COLOR_LabelOut);
  275. TextDrawFont(TDLabels[0],1);
  276.  
  277.  
  278. TDLabels[1]=TextDrawCreate(160.000000, 365.000000,"Drift Bonus:");
  279. TextDrawColor(TDLabels[1],0xFF0000FF);
  280. TextDrawSetShadow(TDLabels[1],0);
  281. TextDrawSetOutline(TDLabels[1],3);
  282. TextDrawLetterSize(TDLabels[1],0.36,1.123);
  283. TextDrawBackgroundColor(TDLabels[1],COLOR_LabelOut);
  284. TextDrawFont(TDLabels[1],1);
  285.  
  286. TDLabels[2]=TextDrawCreate(160.000000, 382.000000,"Drift Cash:");
  287. TextDrawColor(TDLabels[2],0x6DC5F3FF);
  288. TextDrawSetShadow(TDLabels[2],0);
  289. TextDrawSetOutline(TDLabels[2],3);
  290. TextDrawLetterSize(TDLabels[2],0.36,1.123);
  291. TextDrawBackgroundColor(TDLabels[2],COLOR_LabelOut);
  292. TextDrawFont(TDLabels[2],1);
  293.  
  294.  
  295. new i;
  296. for(i=0;i<=MAX_PLAYERS;i++){
  297. TDValueDrift[i]=TextDrawCreate(246.000500, 347.000000,"0");
  298. TextDrawColor(TDValueDrift[i],0xFFFF00AA);
  299. TextDrawSetShadow(TDValueDrift[i],0);
  300. TextDrawLetterSize(TDValueDrift[i],0.37,1.2);
  301. TextDrawBackgroundColor(TDValueDrift[i],COLOR_ValueOut);
  302. TextDrawFont(TDValueDrift[i],3);
  303.  
  304.  
  305. TDValueBonus[i]=TextDrawCreate(246.005000, 364.000000," X1");
  306. TextDrawColor(TDValueBonus[i],0xFFFF00AA);
  307. TextDrawSetShadow(TDValueBonus[i],0);
  308. TextDrawLetterSize(TDValueBonus[i],0.37,1.2);
  309. TextDrawBackgroundColor(TDValueBonus[i],COLOR_ValueOut);
  310. TextDrawFont(TDValueBonus[i],3);
  311.  
  312.  
  313. TDValueCash[i]=TextDrawCreate(245.000600, 381.000000,"$0");
  314. TextDrawColor(TDValueCash[i],0xFFFF00AA);
  315. TextDrawSetShadow(TDValueCash[i],0);
  316. TextDrawLetterSize(TDValueCash[i],0.37,1.2);
  317. TextDrawBackgroundColor(TDValueCash[i],COLOR_ValueOut);
  318. TextDrawFont(TDValueCash[i],3);
  319.  
  320. }
  321.  
  322. return 1;
  323. }
  324.  
  325. //__//__removed drift stop function on big strike with any thing || by Florinca
  326. public CheckPlayerState(){ //by Florinca
  327. new i,cs;
  328.  
  329. for(i=0;i<=MAX_PLAYERS;i++){
  330. cs=GetPlayerState(i);
  331. if(DriftMode[i] && cs==PLAYER_STATE_DRIVER && DriftPointsNow[i]>70){
  332.  
  333. }
  334. if(cs==PLAYER_STATE_DRIVER && DriftMode[i]==false){
  335. if(GetVType(GetPlayerVehicleID(i))){
  336. DriftMode[i]=true;
  337. GetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
  338. AutoFixBool[i]=false;
  339. DriftTimer[i]=SetTimerEx("Drift", 200, true, "i", i);
  340. }
  341. }
  342. else if(cs!=PLAYER_STATE_DRIVER && DriftMode[i]==true){
  343. KillTimer(DriftTimer[i]);
  344. DriftMode[i]=false;
  345. AutoFixBool[i]=true;
  346. }
  347. else{}
  348. }
  349. return 1;
  350. }
  351. //---removed auto fix || not suitable with the script
  352. /*
  353. public AutoFix(){ // By abhinav
  354. new i;
  355. for(i=0;i<=MAX_PLAYERS;i++){
  356. if(AutoFixBool[i] && IsPlayerInAnyVehicle(i)){
  357. SetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
  358. }
  359. }
  360. }
  361. */
  362. //just remove /* and */ to enable auto fix
  363.  
  364. GetVType(vid){ // By Florinca
  365.  
  366. new Convertibles[4]={480, 533, 439, 555};
  367. 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};
  368. new LowRider[8]={536, 575, 534, 567, 535, 566, 576, 412};
  369. new OffRoad[13]={568, 424, 573, 579, 400, 500, 444, 556, 557, 470, 489, 505, 595};
  370. new Service[19]={416, 433, 431, 438, 437, 523, 427, 490, 528, 407, 544, 596, 596, 597, 598, 599, 432, 601, 420};
  371. 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};
  372. new Sports[20]={602, 429, 496, 402, 541, 415, 589, 587, 565, 494, 502, 503, 411, 559, 603, 475, 506, 451, 558, 477};
  373. new Wagons[5]={418, 404, 479, 458, 561};
  374.  
  375. new modelid=GetVehicleModel(vid);
  376. new i;
  377. for(i=0;i<3;i++){
  378. if(Convertibles[i]==modelid) return 1;
  379. }
  380. for(i=0;i<25;i++){
  381. if(Industrial[i]==modelid) return 1;
  382. }
  383. for(i=0;i<7;i++){
  384. if(LowRider[i]==modelid) return 1;
  385. }
  386. for(i=0;i<12;i++){
  387. if(OffRoad[i]==modelid) return 1;
  388. }
  389. for(i=0;i<19;i++){
  390. if(Service[i]==modelid) return 1;
  391. }
  392. for(i=0;i<35;i++){
  393. if(Saloon[i]==modelid) return 1;
  394. }
  395. for(i=0;i<20;i++){
  396. if(Sports[i]==modelid) return 1;
  397. }
  398. for(i=0;i<5;i++){
  399. if(Wagons[i]==modelid) return 1;
  400. }
  401. return 0;
  402. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement