Advertisement
Rei_Ayanami

Drift Pontos

Nov 26th, 2020
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.20 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define DRIFT_MINKAT 5.0
  4. #define DRIFT_MAXKAT 30.0
  5. #define DRIFT_SPEED 10.0
  6.  
  7. #define COLOR_Label 0xFFFFFFFF
  8. #define COLOR_LabelOut 0x00000040
  9. #define COLOR_ValueOut 0xFFFFFF40
  10. #define COLOR_Value 0x000000FF
  11.  
  12. #define Label_X 500
  13. #define Value_X 500
  14. #define TD_Y 180
  15.  
  16. new DriftTimer[MAX_PLAYERS];
  17. new TimerA,TimerB,TimerC;
  18.  
  19. new Points[MAX_PLAYERS];
  20. new DriftPointsNow[MAX_PLAYERS];
  21. new PlayerDriftCancellation[MAX_PLAYERS];
  22. new Float:ppos[MAX_PLAYERS][3];
  23. enum Float:Pos{ Float:sX,Float:sY,Float:sZ };
  24. new Float:SavedPos[MAX_PLAYERS][Pos];
  25.  
  26. new bool:DriftMode[MAX_PLAYERS]=false;
  27. new DriftBonus[MAX_PLAYERS]=1;
  28. new Float:HealthInit[MAX_PLAYERS]=1000.0;
  29. new bool:AutoFixBool[MAX_PLAYERS]=true;
  30.  
  31. new Text:TDLabels[3];
  32. new Text:TDValueDrift[MAX_PLAYERS];
  33. new Text:TDValueBonus[MAX_PLAYERS];
  34. new Text:TDValueCash[MAX_PLAYERS];
  35.  
  36. forward Drift();
  37. forward AngleUpdate();
  38. forward DriftExit(playerid);
  39. forward CheckPlayerState();
  40. forward AutoFix();
  41. public OnFilterScriptInit(){
  42. TimerA=SetTimer("AngleUpdate", 200, true);
  43. TimerB=SetTimer("AutoFix", 500, true);
  44. TimerC=SetTimer("CheckPlayerState", 100, true);
  45. SetTimer("Atualizar",1000,true);
  46. LoadTextDraws();
  47. return 1;
  48. }
  49.  
  50. public OnFilterScriptExit(){
  51. KillTimer(TimerA);
  52. KillTimer(TimerB);
  53. KillTimer(TimerC);
  54. return 1;
  55. }
  56.  
  57. Float:GetPlayerTheoreticAngle(i)
  58. {
  59. new Float:sin;
  60. new Float:dis;
  61. new Float:angle2;
  62. new Float:x,Float:y,Float:z;
  63. new Float:tmp3;
  64. new Float:tmp4;
  65. new Float:MindAngle;
  66.  
  67. if(IsPlayerConnected(i)){
  68.  
  69. GetPlayerPos(i,x,y,z);
  70.  
  71. dis = floatsqroot(floatpower(floatabs(floatsub(x,ppos[i][0])),2)+floatpower(floatabs(floatsub(y,ppos[i][1])),2));
  72.  
  73. if(IsPlayerInAnyVehicle(i)){GetVehicleZAngle(GetPlayerVehicleID(i), angle2);}else{GetPlayerFacingAngle(i, angle2);}
  74.  
  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.  
  78. if(ppos[i][1]>y && ppos[i][0]>x){
  79. sin = asin(tmp3/dis);
  80. MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
  81. }
  82.  
  83. if(ppos[i][1]<y && ppos[i][0]>x){
  84. sin = asin(tmp3/dis);
  85. MindAngle = floatsub(floatadd(sin, 180), 180.0);
  86. }
  87.  
  88. if(ppos[i][1]<y && ppos[i][0]<x){
  89. sin = acos(tmp4/dis);
  90. MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
  91. }
  92.  
  93. if(ppos[i][1]>y && ppos[i][0]<x){
  94. sin = asin(tmp3/dis);
  95. MindAngle = floatadd(sin, 180);
  96. }
  97. }
  98.  
  99. if(MindAngle == 0.0){return angle2;}else{return MindAngle;}
  100. }
  101.  
  102. public DriftExit(playerid){
  103. PlayerDriftCancellation[playerid] = 0;
  104. new Float:h;
  105. GetVehicleHealth(GetPlayerVehicleID(playerid),h);
  106. if(DriftPointsNow[playerid]>70 && DriftPointsNow[playerid]<50000 && h==HealthInit[playerid]) GivePlayerMoney(playerid,DriftPointsNow[playerid]*DriftBonus[playerid]);
  107. TextDrawHideForPlayer(playerid,TDLabels[0]);
  108. TextDrawHideForPlayer(playerid,TDLabels[1]);
  109. TextDrawHideForPlayer(playerid,TDLabels[2]);
  110. TextDrawHideForPlayer(playerid,TDValueDrift[playerid]);
  111. TextDrawHideForPlayer(playerid,TDValueBonus[playerid]);
  112. TextDrawHideForPlayer(playerid,TDValueCash[playerid]);
  113. DriftBonus[playerid]=1;
  114. AutoFixBool[playerid]=true;
  115. SetVehicleHealth(GetPlayerVehicleID(playerid),HealthInit[playerid]);
  116. DriftPointsNow[playerid] = 0;
  117. }
  118.  
  119. Float:ReturnPlayerAngle(playerid){
  120. new Float:Ang;
  121. if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang); else GetPlayerFacingAngle(playerid, Ang);
  122. return Ang;
  123. }
  124.  
  125. public Drift(){
  126. new Float:Angle1, Float:Angle2, Float:BySpeed;
  127. new Float:Z;
  128. new Float:X;
  129. new Float:Y;
  130. new Float:SpeedX;
  131. for(new g=0;g<80;g++){
  132. GetPlayerPos(g, X, Y, Z);
  133. 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)));
  134. Angle1 = ReturnPlayerAngle(g);
  135. Angle2 = GetPlayerTheoreticAngle(g);
  136. BySpeed = floatmul(SpeedX, 12);
  137. if(IsPlayerInAnyVehicle(g) && GetVType(GetPlayerVehicleID(g)) && floatabs(floatsub(Angle1, Angle2)) > DRIFT_MINKAT && floatabs(floatsub(Angle1, Angle2)) < DRIFT_MAXKAT && BySpeed > DRIFT_SPEED){
  138. if(PlayerDriftCancellation[g] > 0)KillTimer(PlayerDriftCancellation[g]);
  139. PlayerDriftCancellation[g] = 0;
  140. DriftPointsNow[g] += floatval( floatabs(floatsub(Angle1, Angle2)) * 3 * (BySpeed*0.1) )/10;
  141. Points[g] += floatval( floatabs(floatsub(Angle1, Angle2)) * 3 * (BySpeed*0.1) )/10;
  142. PlayerDriftCancellation[g] = SetTimerEx("DriftExit", 3000, 0, "d", g);
  143. }
  144.  
  145. if(DriftPointsNow[g] > 70 && DriftPointsNow[g]<50000){
  146. if(DriftPointsNow[g]<500){
  147. DriftBonus[g]=1;
  148. }
  149. if(DriftPointsNow[g]>=500 && DriftPointsNow[g]<1000){
  150. DriftBonus[g]=2;
  151. }
  152. if(DriftPointsNow[g]>=1000 && DriftPointsNow[g]<1700){
  153. DriftBonus[g]=3;
  154. }
  155. if(DriftPointsNow[g]>=1700 && DriftPointsNow[g]<2500){
  156. DriftBonus[g]=4;
  157. }
  158. if(DriftPointsNow[g]>=2500 && DriftPointsNow[g]<4000){
  159. DriftBonus[g]=5;
  160. }
  161. if(DriftPointsNow[g]>=4000 && DriftPointsNow[g]<5000){
  162. DriftBonus[g]=6;
  163. }
  164. if(DriftPointsNow[g]>=5000 && DriftPointsNow[g]<6000){
  165. DriftBonus[g]=7;
  166. }
  167. if(DriftPointsNow[g]>=6000 && DriftPointsNow[g]<7000){
  168. DriftBonus[g]=8;
  169. }
  170. if(DriftPointsNow[g]>=8000 && DriftPointsNow[g]<9000){
  171. DriftBonus[g]=9;
  172. }
  173. if(DriftPointsNow[g]>=9000 && DriftPointsNow[g]<10000){
  174. DriftBonus[g]=10;
  175. }
  176. if(DriftPointsNow[g]>=10000 && DriftPointsNow[g]<11000){
  177. DriftBonus[g]=11;
  178. }
  179. if(DriftPointsNow[g]>=11000 && DriftPointsNow[g]<12000){
  180. DriftBonus[g]=12;
  181. }
  182. if(DriftPointsNow[g]>=12000 && DriftPointsNow[g]<13000){
  183. DriftBonus[g]=13;
  184. }
  185. if(DriftPointsNow[g]>=13000 && DriftPointsNow[g]<14000){
  186. DriftBonus[g]=14;
  187. }
  188. if(DriftPointsNow[g]>=14000 && DriftPointsNow[g]<15000){
  189. DriftBonus[g]=15;
  190. }
  191. if(DriftPointsNow[g]>=15000 && DriftPointsNow[g]<16000){
  192. DriftBonus[g]=16;
  193. }
  194. if(DriftPointsNow[g]>=16000 && DriftPointsNow[g]<17000){
  195. DriftBonus[g]=17;
  196. }
  197. if(DriftPointsNow[g]>=17000 && DriftPointsNow[g]<18000){
  198. DriftBonus[g]=18;
  199. }
  200. if(DriftPointsNow[g]>=18000 && DriftPointsNow[g]<19000){
  201. DriftBonus[g]=19;
  202. }
  203. if(DriftPointsNow[g]>=19000 && DriftPointsNow[g]<20000){
  204. DriftBonus[g]=20;
  205. }
  206. if(DriftPointsNow[g]>=20000 && DriftPointsNow[g]<21000){
  207. DriftBonus[g]=21;
  208. }
  209. if(DriftPointsNow[g]>=21000 && DriftPointsNow[g]<22000){
  210. DriftBonus[g]=22;
  211. }
  212. if(DriftPointsNow[g]>=22000 && DriftPointsNow[g]<23000){
  213. DriftBonus[g]=23;
  214. }
  215. if(DriftPointsNow[g]>=23000 && DriftPointsNow[g]<24000){
  216. DriftBonus[g]=24;
  217. }
  218. if(DriftPointsNow[g]>=24000 && DriftPointsNow[g]<25000){
  219. DriftBonus[g]=25;
  220. }
  221. if(DriftPointsNow[g]>=25000 && DriftPointsNow[g]<26000){
  222. DriftBonus[g]=26;
  223. }
  224. if(DriftPointsNow[g]>=26000 && DriftPointsNow[g]<27000){
  225. DriftBonus[g]=27;
  226. }
  227. if(DriftPointsNow[g]>=27000 && DriftPointsNow[g]<28000){
  228. DriftBonus[g]=28;
  229. }
  230. if(DriftPointsNow[g]>=28000 && DriftPointsNow[g]<29000){
  231. DriftBonus[g]=29;
  232. }
  233. if(DriftPointsNow[g]>=29000 && DriftPointsNow[g]<30000){
  234. DriftBonus[g]=30;
  235. }
  236. if(DriftPointsNow[g]>=30000 && DriftPointsNow[g]<31000){
  237. DriftBonus[g]=31;
  238. }
  239. if(DriftPointsNow[g]>=31000 && DriftPointsNow[g]<32000){
  240. DriftBonus[g]=32;
  241. }
  242. if(DriftPointsNow[g]>=32000 && DriftPointsNow[g]<33000){
  243. DriftBonus[g]=33;
  244. }
  245. if(DriftPointsNow[g]>=33000 && DriftPointsNow[g]<34000){
  246. DriftBonus[g]=34;
  247. }
  248. if(DriftPointsNow[g]>=34000 && DriftPointsNow[g]<35000){
  249. DriftBonus[g]=35;
  250. }
  251. if(DriftPointsNow[g]>=35000 && DriftPointsNow[g]<36000){
  252. DriftBonus[g]=36;
  253. }
  254. if(DriftPointsNow[g]>=36000 && DriftPointsNow[g]<37000){
  255. DriftBonus[g]=37;
  256. }
  257. if(DriftPointsNow[g]>=37000 && DriftPointsNow[g]<38000){
  258. DriftBonus[g]=38;
  259. }
  260. if(DriftPointsNow[g]>=38000 && DriftPointsNow[g]<39000){
  261. DriftBonus[g]=39;
  262. }
  263. if(DriftPointsNow[g]>=39000 && DriftPointsNow[g]<40000){
  264. DriftBonus[g]=40;
  265. }
  266. if(DriftPointsNow[g]>=40000 && DriftPointsNow[g]<41000){
  267. DriftBonus[g]=41;
  268. }
  269. if(DriftPointsNow[g]>=41000 && DriftPointsNow[g]<42000){
  270. DriftBonus[g]=42;
  271. }
  272. if(DriftPointsNow[g]>=42000 && DriftPointsNow[g]<43000){
  273. DriftBonus[g]=43;
  274. }
  275. if(DriftPointsNow[g]>=43000 && DriftPointsNow[g]<44000){
  276. DriftBonus[g]=44;
  277. }
  278. if(DriftPointsNow[g]>=44000 && DriftPointsNow[g]<45000){
  279. DriftBonus[g]=45;
  280. }
  281. if(DriftPointsNow[g]>=45000 && DriftPointsNow[g]<46000){
  282. DriftBonus[g]=46;
  283. }
  284. if(DriftPointsNow[g]>=46000 && DriftPointsNow[g]<47000){
  285. DriftBonus[g]=47;
  286. }
  287. if(DriftPointsNow[g]>=47000 && DriftPointsNow[g]<48000){
  288. DriftBonus[g]=48;
  289. }
  290. if(DriftPointsNow[g]>=48000 && DriftPointsNow[g]<49000){
  291. DriftBonus[g]=49;
  292. }
  293. if(DriftPointsNow[g]>=49000 && DriftPointsNow[g]<50000){
  294. DriftBonus[g]=50;
  295. }if(DriftPointsNow[g]>=50000){
  296. DriftBonus[g]=51;
  297. }
  298.  
  299. TextDrawShowForPlayer(g,TDLabels[0]);
  300. TextDrawShowForPlayer(g,TDLabels[1]);
  301. TextDrawShowForPlayer(g,TDLabels[2]);
  302.  
  303. TextDrawShowForPlayer(g,TDValueDrift[g]);
  304. TextDrawShowForPlayer(g,TDValueBonus[g]);
  305. TextDrawShowForPlayer(g,TDValueCash[g]);
  306.  
  307. new DPs[128],DBn[128],Cash[128],csh;
  308.  
  309. valstr(DPs,DriftPointsNow[g],false);
  310. format(DBn,sizeof(DBn),"X%i",DriftBonus[g]);
  311. csh=DriftPointsNow[g]*DriftBonus[g];
  312. format(Cash,sizeof(Cash),"$%i",csh);
  313.  
  314. new PointsD[20];
  315. format(PointsD,sizeof(PointsD),"%d",Points[g]);
  316. setproperty(0, "", 1235, PointsD);
  317.  
  318. TextDrawSetString(TDValueDrift[g],DPs);
  319. TextDrawSetString(TDValueBonus[g],DBn);
  320. TextDrawSetString(TDValueCash[g],Cash);
  321. }
  322. SavedPos[ g ][ sX ] = X;
  323. SavedPos[ g ][ sY ] = Y;
  324. SavedPos[ g ][ sZ ] = Z;
  325. }
  326. }
  327.  
  328.  
  329. public AngleUpdate(){
  330. for(new g=0;g<=MAX_PLAYERS;g++){
  331. new Float:x, Float:y, Float:z;
  332. if(IsPlayerInAnyVehicle(g))GetVehiclePos(GetPlayerVehicleID(g), x, y, z); else GetPlayerPos(g, x, y, z);
  333. ppos[g][0] = x;
  334. ppos[g][1] = y;
  335. ppos[g][2] = z;
  336. }
  337. }
  338.  
  339. floatval(Float:val){
  340. new str[256];
  341. format(str, 256, "%.0f", val);
  342. return todec(str);
  343. }
  344.  
  345. todec(str[]){
  346. return strval(str);
  347. }
  348.  
  349. LoadTextDraws(){
  350. TDLabels[0]=TextDrawCreate(Label_X,TD_Y,"Drift Pontos");
  351. TextDrawColor(TDLabels[0],COLOR_Label);
  352. TextDrawSetShadow(TDLabels[0],0);
  353. TextDrawSetOutline(TDLabels[0],1);
  354. TextDrawLetterSize(TDLabels[0],0.5,2);
  355. TextDrawBackgroundColor(TDLabels[0],COLOR_LabelOut);
  356. TextDrawFont(TDLabels[0],1);
  357.  
  358. TDLabels[1]=TextDrawCreate(Label_X,TD_Y+50,"Drift Bonus");
  359. TextDrawColor(TDLabels[1],COLOR_Label);
  360. TextDrawSetShadow(TDLabels[1],0);
  361. TextDrawSetOutline(TDLabels[1],1);
  362. TextDrawLetterSize(TDLabels[1],0.5,2);
  363. TextDrawBackgroundColor(TDLabels[1],COLOR_LabelOut);
  364. TextDrawFont(TDLabels[1],1);
  365.  
  366. TDLabels[2]=TextDrawCreate(Label_X,TD_Y+100,"Drift Pagamento");
  367. TextDrawColor(TDLabels[2],COLOR_Label);
  368. TextDrawSetShadow(TDLabels[2],0);
  369. TextDrawSetOutline(TDLabels[2],1);
  370. TextDrawLetterSize(TDLabels[2],0.5,2);
  371. TextDrawBackgroundColor(TDLabels[2],COLOR_LabelOut);
  372. TextDrawFont(TDLabels[2],1);
  373.  
  374. new i;
  375. for(i=0;i<=MAX_PLAYERS;i++){
  376. TDValueDrift[i]=TextDrawCreate(Value_X,TD_Y+20,"0");
  377. TextDrawColor(TDValueDrift[i],COLOR_Value);
  378. TextDrawSetShadow(TDValueDrift[i],0);
  379. TextDrawSetOutline(TDValueDrift[i],1);
  380. TextDrawLetterSize(TDValueDrift[i],0.5,2);
  381. TextDrawBackgroundColor(TDValueDrift[i],COLOR_ValueOut);
  382. TextDrawFont(TDValueDrift[i],3);
  383.  
  384. TDValueBonus[i]=TextDrawCreate(Value_X,TD_Y+70,"X1");
  385. TextDrawColor(TDValueBonus[i],COLOR_Value);
  386. TextDrawSetShadow(TDValueBonus[i],0);
  387. TextDrawSetOutline(TDValueBonus[i],1);
  388. TextDrawLetterSize(TDValueBonus[i],0.5,2);
  389. TextDrawBackgroundColor(TDValueBonus[i],COLOR_ValueOut);
  390. TextDrawFont(TDValueBonus[i],3);
  391.  
  392. TDValueCash[i]=TextDrawCreate(Value_X,TD_Y+120,"$0");
  393. TextDrawColor(TDValueCash[i],COLOR_Value);
  394. TextDrawSetShadow(TDValueCash[i],0);
  395. TextDrawSetOutline(TDValueCash[i],1);
  396. TextDrawLetterSize(TDValueCash[i],0.5,2);
  397. TextDrawBackgroundColor(TDValueCash[i],COLOR_ValueOut);
  398. TextDrawFont(TDValueCash[i],3);
  399. }
  400.  
  401. return 1;
  402. }
  403.  
  404. public CheckPlayerState(){
  405. new i,cs;
  406.  
  407. for(i=0;i<=MAX_PLAYERS;i++){
  408. cs=GetPlayerState(i);
  409. if(DriftMode[i] && cs==PLAYER_STATE_DRIVER && DriftPointsNow[i]>70 && Points[i]>70){
  410. new Float:h;
  411. GetVehicleHealth(GetPlayerVehicleID(i),h);
  412. if(h<HealthInit[i]){
  413. KillTimer(DriftTimer[i]);
  414. Points[i] = Points[i]-DriftPointsNow[i];
  415. new PointsD[20];
  416. format(PointsD,sizeof(PointsD),"%d",Points[i]);
  417. setproperty(0, "", 1235, PointsD);
  418. GameTextForPlayer(i,"~n~~n~~n~~n~~n~~n~~n~~r~Bateu!",800,5);
  419. DriftExit(i);
  420. DriftMode[i]=false;
  421. }
  422. }
  423. if(cs==PLAYER_STATE_DRIVER && DriftMode[i]==false){
  424. if(GetVType(GetPlayerVehicleID(i))){
  425. DriftMode[i]=true;
  426. GetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
  427. AutoFixBool[i]=false;
  428. DriftTimer[i]=SetTimerEx("Drift", 200, true, "i", i);
  429. }
  430. }
  431. else if(cs!=PLAYER_STATE_DRIVER && DriftMode[i]==true){
  432. KillTimer(DriftTimer[i]);
  433. DriftMode[i]=false;
  434. AutoFixBool[i]=true;
  435. }
  436. else{}
  437. }
  438. return 1;
  439. }
  440.  
  441. public AutoFix(){
  442. new i;
  443. for(i=0;i<=MAX_PLAYERS;i++){
  444. if(AutoFixBool[i] && IsPlayerInAnyVehicle(i)){
  445. SetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
  446. }
  447. }
  448. }
  449.  
  450. GetVType(vid){
  451.  
  452. new Convertibles[4]={480, 533, 439, 555};
  453. 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};
  454. new LowRider[8]={536, 575, 534, 567, 535, 566, 576, 412};
  455. new OffRoad[13]={568, 424, 573, 579, 400, 500, 444, 556, 557, 470, 489, 505, 595};
  456. new Service[19]={416, 433, 431, 438, 437, 523, 427, 490, 528, 407, 544, 596, 596, 597, 598, 599, 432, 601, 420};
  457. 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};
  458. new Sports[20]={602, 429, 496, 402, 541, 415, 589, 587, 565, 494, 502, 503, 411, 559, 603, 475, 506, 451, 558, 477};
  459. new Wagons[5]={418, 404, 479, 458, 561};
  460.  
  461. new modelid=GetVehicleModel(vid);
  462. new i;
  463. for(i=0;i<3;i++){
  464. if(Convertibles[i]==modelid) return 1;
  465. }
  466. for(i=0;i<25;i++){
  467. if(Industrial[i]==modelid) return 1;
  468. }
  469. for(i=0;i<7;i++){
  470. if(LowRider[i]==modelid) return 1;
  471. }
  472. for(i=0;i<12;i++){
  473. if(OffRoad[i]==modelid) return 1;
  474. }
  475. for(i=0;i<19;i++){
  476. if(Service[i]==modelid) return 1;
  477. }
  478. for(i=0;i<35;i++){
  479. if(Saloon[i]==modelid) return 1;
  480. }
  481. for(i=0;i<20;i++){
  482. if(Sports[i]==modelid) return 1;
  483. }
  484. for(i=0;i<5;i++){
  485. if(Wagons[i]==modelid) return 1;
  486. }
  487. return 0;
  488. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement