Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=====================Driftcounter By Lotuz=======================
- //===================Do not change any credits=====================
- //=========================2012-06-13==============================
- //====include
- #include <a_samp>
- #include <zcmd>
- //====define
- #define DRIFT_MINKAT 10.0
- #define DRIFT_MAXKAT 90.0
- #define DRIFT_SPEED 30.0
- #define dc 1117
- //====new
- new atimer, dtimer;
- new Text:Chet[MAX_PLAYERS];
- new DriftPointsNow[200];
- new PlayerDriftCancellation[200];
- new Float:ppos[200][3];
- new scores[MAX_PLAYERS];
- new scplay[MAX_PLAYERS], chets[MAX_PLAYERS];
- enum Float:Pos{ Float:sX,Float:sY,Float:sZ };
- new Float:SavedPos[MAX_PLAYERS][Pos];
- //====forward
- forward Drift();
- forward AngleUpdate();
- forward DriftCancellation(playerid);
- public OnGameModeInit()
- {
- dtimer = SetTimer("Drift", 200, true);
- atimer = SetTimer("AngleUpdate", 200, true);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- scplay[playerid] = 1;
- chets[playerid] = 1;
- //==========================================
- Chet[playerid] = TextDrawCreate(500,170,"-");
- TextDrawAlignment(Chet[playerid],0);
- TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
- TextDrawFont(Chet[playerid],3);
- TextDrawLetterSize(Chet[playerid],0.5,1.7);
- TextDrawColor(Chet[playerid],0x0000CDFF);
- TextDrawSetOutline(Chet[playerid],1);
- TextDrawSetProportional(Chet[playerid],1);
- TextDrawSetShadow(Chet[playerid],1);
- SendClientMessage(playerid, 0x008000FF, "This server use Lotuz Driftcounter. Use /dc");
- return 1;
- }
- CMD:dc(playerid, params[])
- {
- ShowPlayerDialog(playerid, dc, DIALOG_STYLE_LIST, "DriftCounter", "{0004FF}Blue\n{040524}Black\n{FF9305}Orange\n{5BE93B}Green\n{FF00FF}Pink", "Okey", "Back");
- return 1;
- }
- Float:GetPlayerTheoreticAngle(i) // By Luby
- {
- new Float:sin;
- new Float:dis;
- new Float:angle2;
- new Float:x,Float:y,Float:z;
- new Float:tmp3;
- new Float:tmp4;
- new Float:MindAngle;
- if(IsPlayerConnected(i))
- {
- GetPlayerPos(i,x,y,z);
- dis = floatsqroot(floatpower(floatabs(floatsub(x,ppos[i][0])),2)+floatpower(floatabs(floatsub(y,ppos[i][1])),2));
- if(IsPlayerInAnyVehicle(i)){GetVehicleZAngle(GetPlayerVehicleID(i), angle2);}else{GetPlayerFacingAngle(i, angle2);}
- if(x>ppos[i][0]){tmp3=x-ppos[i][0];}else{tmp3=ppos[i][0]-x;}
- if(y>ppos[i][1]){tmp4=y-ppos[i][1];}else{tmp4=ppos[i][1]-y;}
- if(ppos[i][1]>y && ppos[i][0]>x)
- {
- sin = asin(tmp3/dis);
- MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
- }
- if(ppos[i][1]<y && ppos[i][0]>x)
- {
- sin = asin(tmp3/dis);
- MindAngle = floatsub(floatadd(sin, 180), 180.0);
- }
- if(ppos[i][1]<y && ppos[i][0]<x)
- {
- sin = acos(tmp4/dis);
- MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
- }
- if(ppos[i][1]>y && ppos[i][0]<x)
- {
- sin = asin(tmp3/dis);
- MindAngle = floatadd(sin, 180);
- }
- }
- if(MindAngle == 0.0)
- {
- return angle2;
- }
- else
- {
- return MindAngle;
- }
- }
- //------------------------------------------------
- stock strrest(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[128];
- while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- stock strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- public DriftCancellation(playerid)
- {
- PlayerDriftCancellation[playerid] = 0;
- GivePlayerMoney(playerid,DriftPointsNow[playerid]);
- DriftPointsNow[playerid] = 0;
- scores[playerid] = 0;
- TextDrawHideForPlayer(playerid, Chet[playerid]);
- }
- Float:ReturnPlayerAngle(playerid)
- {
- new Float:Ang;
- if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang); else GetPlayerFacingAngle(playerid, Ang);
- return Ang;
- }
- public Drift()
- {
- new Float:Angle1, Float:Angle2, Float:BySpeed, s[128];
- new Float:Z;
- new Float:X;
- new Float:Y;
- new Float:SpeedX;
- for(new g=0;g<MAX_PLAYERS;g++)
- {
- GetPlayerPos(g, X, Y, Z);
- 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)));
- Angle1 = ReturnPlayerAngle(g);
- Angle2 = GetPlayerTheoreticAngle(g);
- BySpeed = floatmul(SpeedX, 12);
- if(IsPlayerInAnyVehicle(g) && IsCar(GetPlayerVehicleID(g)) && floatabs(floatsub(Angle1, Angle2)) > DRIFT_MINKAT && floatabs(floatsub(Angle1, Angle2)) < DRIFT_MAXKAT && BySpeed > DRIFT_SPEED)
- {
- if(PlayerDriftCancellation[g] > 0)KillTimer(PlayerDriftCancellation[g]);
- PlayerDriftCancellation[g] = 0;
- DriftPointsNow[g] += 10;
- scores[g]++;
- PlayerDriftCancellation[g] = SetTimerEx("DriftCancellation", 2000, 0, "d", g);
- }
- if(DriftPointsNow[g] > 0)
- {
- if(scplay[g] == 1)
- {
- TextDrawShowForPlayer(g,Chet[g]);
- format(s, sizeof(s), "Drift: %d$", DriftPointsNow[g]);
- TextDrawSetString(Chet[g], s);
- }
- }
- SavedPos[ g ][ sX ] = X;
- SavedPos[ g ][ sY ] = Y;
- SavedPos[ g ][ sZ ] = Z;
- }
- }
- IsCar(model)
- {
- switch(model)
- {
- case 443:return 0;
- case 448:return 0;
- case 461:return 0;
- case 462:return 0;
- case 463:return 0;
- case 468:return 0;
- case 521:return 0;
- case 522:return 0;
- case 523:return 0;
- case 581:return 0;
- case 586:return 0;
- case 481:return 0;
- case 509:return 0;
- case 510:return 0;
- case 430:return 0;
- case 446:return 0;
- case 452:return 0;
- case 453:return 0;
- case 454:return 0;
- case 472:return 0;
- case 473:return 0;
- case 484:return 0;
- case 493:return 0;
- case 595:return 0;
- case 417:return 0;
- case 425:return 0;
- case 447:return 0;
- case 465:return 0;
- case 469:return 0;
- case 487:return 0;
- case 488:return 0;
- case 497:return 0;
- case 501:return 0;
- case 548:return 0;
- case 563:return 0;
- case 406:return 0;
- case 444:return 0;
- case 556:return 0;
- case 557:return 0;
- case 573:return 0;
- case 460:return 0;
- case 464:return 0;
- case 476:return 0;
- case 511:return 0;
- case 512:return 0;
- case 513:return 0;
- case 519:return 0;
- case 520:return 0;
- case 539:return 0;
- case 553:return 0;
- case 577:return 0;
- case 592:return 0;
- case 593:return 0;
- case 471:return 0;
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == dc) // == Driftcounter Color's
- {
- if(response)
- {
- if(listitem == 0)
- {
- TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
- SendClientMessage(playerid, 0x0000CDFF, "You Driftcounter are now Blue");
- TextDrawColor(Chet[playerid],0x0000CDFF);
- }
- if(listitem == 1)
- {
- TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
- SendClientMessage(playerid, 0x000000FF, "You Driftcounter are now Black");
- TextDrawColor(Chet[playerid],0x000000FF);
- }
- if(listitem == 2)
- {
- TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
- SendClientMessage(playerid, 0xFF4500FF, "You Driftcounter are now Orange");
- TextDrawColor(Chet[playerid],0xFF4500FF);
- }
- if(listitem == 3)
- {
- TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
- SendClientMessage(playerid, 0x008000FF, "You Driftcounter are now Green");
- TextDrawColor(Chet[playerid],0x008000FF);
- return 1;
- }
- if(listitem == 4)
- {
- TextDrawBackgroundColor(Chet[playerid],0xFFFFFFAA);
- SendClientMessage(playerid, 0xFF1493FF, "You Driftcounter are now Pink");
- TextDrawColor(Chet[playerid],0xFF1493FF);
- return 1;
- }
- }
- }
- return 1;
- }
- public AngleUpdate()
- {
- for(new g=0;g<=MAX_PLAYERS;g++)
- {
- new Float:x, Float:y, Float:z;
- if(IsPlayerInAnyVehicle(g))GetVehiclePos(GetPlayerVehicleID(g), x, y, z); else GetPlayerPos(g, x, y, z);
- ppos[g][0] = x;
- ppos[g][1] = y;
- ppos[g][2] = z;
- }
- }
- public OnVehicleDamageStatusUpdate(vehicleid, playerid)
- {
- if(DriftPointsNow[playerid] > 0)
- {
- DriftPointsNow[playerid] = 0;
- scores[playerid] = 0;
- TextDrawSetString(Chet[playerid], "~r~Crash");
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement