Drift erkennen O.o

Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Moin, ich habe schon überall gesucht und gegooglet aber man findet einfach kein beispiel wie ich erkenne ob das Auto gerade driftet oder geradeaus fährt!
    Kann mir wer da behilflich sein?

  • Hi,


    also es gibt ein Filterscript bei dem man für's driften Geld bekommt.
    Wenn du dort reinschaust hilf dir das vielleicht.


    Ansonsten musst du mit Timern und der VehicleZAngle arbeiten.

  • Kopieren meinte ich auch nicht :)
    Einfach mal gucken und was du nicht verstehst kannst du ja hier
    fragen.

  • Script:


    Inhalt anzeigen
    ////////////////////////////////////////////////////////////
    /////////////// DRIFT POINTS COUNTER BY LUBY ///////////////
    /////////////// A little editted by Abhinav ////////////////
    ////////////////////////////////////////////////////////////

    Inhalt anzeigen

    Inhalt anzeigen
    #include <a_samp> // by I dont know .. :D lol

    Inhalt anzeigen

    Inhalt anzeigen
    #define DRIFT_MINKAT 10.0 // by Luby
    #define DRIFT_MAXKAT 90.0 // by Luby
    #define DRIFT_SPEED 30.0 // by Luby

    Inhalt anzeigen

    Inhalt anzeigen
    //////////// Added by Abhinav///////
    #define COLOR_Label 0xFFFFFFFF
    #define COLOR_LabelOut 0x00000040
    #define COLOR_ValueOut 0xFFFFFF40
    #define COLOR_Value 0x000000FF

    Inhalt anzeigen

    Inhalt anzeigen
    #define Label_X 500
    #define Value_X 500
    #define TD_Y 100
    /////////////////////////////////////

    Inhalt anzeigen

    Inhalt anzeigen
    new DriftTimer[MAX_PLAYERS]; // Added by Abhinav
    new TimerA,TimerB,TimerC; // Added by Abhinav

    Inhalt anzeigen

    Inhalt anzeigen
    new DriftPointsNow[MAX_PLAYERS]; // by Luby
    new PlayerDriftCancellation[MAX_PLAYERS]; // by Luby
    new Float:ppos[MAX_PLAYERS][3]; // by Luby
    enum Float:Pos{ Float:sX,Float:sY,Float:sZ }; // by Luby
    new Float:SavedPos[MAX_PLAYERS][Pos]; // by Luby

    Inhalt anzeigen

    Inhalt anzeigen
    new bool:DriftMode[MAX_PLAYERS]=false; // Added by Abhinav
    new DriftBonus[MAX_PLAYERS]=1; // Added by Abhinav
    new Float:HealthInit[MAX_PLAYERS]=1000.0; // Added by Abhinav
    new bool:AutoFixBool[MAX_PLAYERS]=true; // Added by Abhinav

    Inhalt anzeigen

    Inhalt anzeigen
    new Text:TDLabels[3]; // Added by Abhinav
    new Text:TDValueDrift[MAX_PLAYERS]; // Added by Abhinav
    new Text:TDValueBonus[MAX_PLAYERS]; // Added by Abhinav
    new Text:TDValueCash[MAX_PLAYERS]; // Added by Abhinav

    Inhalt anzeigen

    Inhalt anzeigen
    forward Drift(); // by Luby
    forward AngleUpdate(); // by Luby
    forward DriftExit(playerid); // by Luby
    forward CheckPlayerState(); // Added by Abhinav
    forward AutoFix(); // Added by Abhinav

    Inhalt anzeigen

    Inhalt anzeigen
    public OnFilterScriptInit(){
    TimerA=SetTimer("AngleUpdate", 200, true); // by Luby
    TimerB=SetTimer("AutoFix", 500, true); //by Abhinav
    TimerC=SetTimer("CheckPlayerState", 100, true); //by Abhinav
    LoadTextDraws();
    return 1;
    }

    Inhalt anzeigen

    Inhalt anzeigen
    public OnFilterScriptExit(){
    KillTimer(TimerA);
    KillTimer(TimerB);
    KillTimer(TimerC);
    return 1;
    }

    Inhalt anzeigen

    Inhalt anzeigen
    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;

    Inhalt anzeigen

    Inhalt anzeigen
    if(IsPlayerConnected(i)){

    Inhalt anzeigen

    Inhalt anzeigen
    GetPlayerPos(i,x,y,z);

    Inhalt anzeigen

    Inhalt anzeigen
    dis = floatsqroot(floatpower(floatabs(floatsub(x,ppos[i][0])),2)+floatpower(floatabs(floatsub(y,ppos[i][1])),2));

    Inhalt anzeigen

    Inhalt anzeigen
    if(IsPlayerInAnyVehicle(i)){GetVehicleZAngle(GetPlayerVehicleID(i), angle2);}else{GetPlayerFacingAngle(i, angle2);}

    Inhalt anzeigen

    Inhalt anzeigen
    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;}

    Inhalt anzeigen

    Inhalt anzeigen
    if(ppos[i][1]>y && ppos[i][0]>x){
    sin = asin(tmp3/dis);
    MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
    }

    Inhalt anzeigen

    Inhalt anzeigen
    if(ppos[i][1]<y && ppos[i][0]>x){
    sin = asin(tmp3/dis);
    MindAngle = floatsub(floatadd(sin, 180), 180.0);
    }

    Inhalt anzeigen

    Inhalt anzeigen
    if(ppos[i][1]<y && ppos[i][0]<x){
    sin = acos(tmp4/dis);
    MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
    }

    Inhalt anzeigen

    Inhalt anzeigen
    if(ppos[i][1]>y && ppos[i][0]<x){
    sin = asin(tmp3/dis);
    MindAngle = floatadd(sin, 180);
    }
    }

    Inhalt anzeigen

    Inhalt anzeigen
    if(MindAngle == 0.0){return angle2;}else{return MindAngle;}
    }

    Inhalt anzeigen

    Inhalt anzeigen
    public DriftExit(playerid){ // By Luby
    PlayerDriftCancellation[playerid] = 0;

    Inhalt anzeigen

    Inhalt anzeigen
    ////////////////// by Abhinav ///////////////////
    new Float:h;
    GetVehicleHealth(GetPlayerVehicleID(playerid),h);
    if(DriftPointsNow[playerid]>70 && DriftPointsNow[playerid]<10000 && h==HealthInit[playerid]) GivePlayerMoney(playerid,DriftPointsNow[playerid]*DriftBonus[playerid]);
    TextDrawHideForPlayer(playerid,TDLabels[0]);
    TextDrawHideForPlayer(playerid,TDLabels[1]);
    TextDrawHideForPlayer(playerid,TDLabels[2]);
    TextDrawHideForPlayer(playerid,TDValueDrift[playerid]);
    TextDrawHideForPlayer(playerid,TDValueBonus[playerid]);
    TextDrawHideForPlayer(playerid,TDValueCash[playerid]);
    DriftBonus[playerid]=1;
    AutoFixBool[playerid]=true;
    SetVehicleHealth(GetPlayerVehicleID(playerid),HealthInit[playerid]);
    ////////////////////////////////////////////////////

    Inhalt anzeigen

    Inhalt anzeigen
    DriftPointsNow[playerid] = 0;
    }

    Inhalt anzeigen

    Inhalt anzeigen
    Float:ReturnPlayerAngle(playerid){ // By Luby
    new Float:Ang;
    if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang); else GetPlayerFacingAngle(playerid, Ang);
    return Ang;
    }

    Inhalt anzeigen

    Inhalt anzeigen
    public Drift(){ // By Luby
    new Float:Angle1, Float:Angle2, Float:BySpeed;
    new Float:Z;
    new Float:X;
    new Float:Y;
    new Float:SpeedX;
    for(new g=0;g<200;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) && GetVType(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] += floatval( floatabs(floatsub(Angle1, Angle2)) * 3 * (BySpeed*0.1) )/10;
    PlayerDriftCancellation[g] = SetTimerEx("DriftExit", 3000, 0, "d", g);
    }

    Inhalt anzeigen

    Inhalt anzeigen
    if(DriftPointsNow[g] > 70 && DriftPointsNow[g]<10000){
    ///////////// by Abhinav ////////////////////
    if(DriftPointsNow[g]<500){
    DriftBonus[g]=1;
    }
    if(DriftPointsNow[g]>=500 && DriftPointsNow[g]<1000){
    DriftBonus[g]=2;
    }
    if(DriftPointsNow[g]>=1000 && DriftPointsNow[g]<1700){
    DriftBonus[g]=3;
    }
    if(DriftPointsNow[g]>=1700 && DriftPointsNow[g]<2500){
    DriftBonus[g]=4;
    }
    if(DriftPointsNow[g]>=2500){
    DriftBonus[g]=5;
    }

    Inhalt anzeigen

    Inhalt anzeigen
    TextDrawShowForPlayer(g,TDLabels[0]);
    TextDrawShowForPlayer(g,TDLabels[1]);
    TextDrawShowForPlayer(g,TDLabels[2]);

    Inhalt anzeigen

    Inhalt anzeigen
    TextDrawShowForPlayer(g,TDValueDrift[g]);
    TextDrawShowForPlayer(g,TDValueBonus[g]);
    TextDrawShowForPlayer(g,TDValueCash[g]);

    Inhalt anzeigen

    Inhalt anzeigen
    new DPs[128],DBn[128],Cash[128],csh;

    Inhalt anzeigen

    Inhalt anzeigen
    valstr(DPs,DriftPointsNow[g],false);
    format(DBn,sizeof(DBn),"X%i",DriftBonus[g]);
    csh=DriftPointsNow[g]*DriftBonus[g];
    format(Cash,sizeof(Cash),"$%i",csh);

    Inhalt anzeigen

    Inhalt anzeigen
    TextDrawSetString(TDValueDrift[g],DPs);
    TextDrawSetString(TDValueBonus[g],DBn);
    TextDrawSetString(TDValueCash[g],Cash);
    ////////////////////////////////////////
    }
    SavedPos[ g ][ sX ] = X;
    SavedPos[ g ][ sY ] = Y;
    SavedPos[ g ][ sZ ] = Z;
    }
    }

    Inhalt anzeigen

    Inhalt anzeigen
    public AngleUpdate(){ // By Luby
    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;
    }
    }

    Inhalt anzeigen

    Inhalt anzeigen
    floatval(Float:val){ // By Luby
    new str[256];
    format(str, 256, "%.0f", val);
    return todec(str);
    }

    Inhalt anzeigen

    Inhalt anzeigen
    todec(str[]){ // By Luby
    return strval(str);
    }

    Inhalt anzeigen

    Inhalt anzeigen
    LoadTextDraws(){ // by Abhinav
    TDLabels[0]=TextDrawCreate(Label_X,TD_Y,"Drift Points");
    TextDrawColor(TDLabels[0],COLOR_Label);
    TextDrawSetShadow(TDLabels[0],0);
    TextDrawSetOutline(TDLabels[0],1);
    TextDrawLetterSize(TDLabels[0],0.5,2);
    TextDrawBackgroundColor(TDLabels[0],COLOR_LabelOut);
    TextDrawFont(TDLabels[0],1);

    Inhalt anzeigen

    Inhalt anzeigen
    TDLabels[1]=TextDrawCreate(Label_X,TD_Y+50,"Drift Bonus");
    TextDrawColor(TDLabels[1],COLOR_Label);
    TextDrawSetShadow(TDLabels[1],0);
    TextDrawSetOutline(TDLabels[1],1);
    TextDrawLetterSize(TDLabels[1],0.5,2);
    TextDrawBackgroundColor(TDLabels[1],COLOR_LabelOut);
    TextDrawFont(TDLabels[1],1);

    Inhalt anzeigen

    Inhalt anzeigen
    TDLabels[2]=TextDrawCreate(Label_X,TD_Y+100,"Drift Cash");
    TextDrawColor(TDLabels[2],COLOR_Label);
    TextDrawSetShadow(TDLabels[2],0);
    TextDrawSetOutline(TDLabels[2],1);
    TextDrawLetterSize(TDLabels[2],0.5,2);
    TextDrawBackgroundColor(TDLabels[2],COLOR_LabelOut);
    TextDrawFont(TDLabels[2],1);

    Inhalt anzeigen

    Inhalt anzeigen
    new i;
    for(i=0;i<=MAX_PLAYERS;i++){
    TDValueDrift[i]=TextDrawCreate(Value_X,TD_Y+20,"0");
    TextDrawColor(TDValueDrift[i],COLOR_Value);
    TextDrawSetShadow(TDValueDrift[i],0);
    TextDrawSetOutline(TDValueDrift[i],1);
    TextDrawLetterSize(TDValueDrift[i],0.5,2);
    TextDrawBackgroundColor(TDValueDrift[i],COLOR_ValueOut);
    TextDrawFont(TDValueDrift[i],3);

    Inhalt anzeigen

    Inhalt anzeigen
    TDValueBonus[i]=TextDrawCreate(Value_X,TD_Y+70,"X1");
    TextDrawColor(TDValueBonus[i],COLOR_Value);
    TextDrawSetShadow(TDValueBonus[i],0);
    TextDrawSetOutline(TDValueBonus[i],1);
    TextDrawLetterSize(TDValueBonus[i],0.5,2);
    TextDrawBackgroundColor(TDValueBonus[i],COLOR_ValueOut);
    TextDrawFont(TDValueBonus[i],3);

    Inhalt anzeigen

    Inhalt anzeigen
    TDValueCash[i]=TextDrawCreate(Value_X,TD_Y+120,"$0");
    TextDrawColor(TDValueCash[i],COLOR_Value);
    TextDrawSetShadow(TDValueCash[i],0);
    TextDrawSetOutline(TDValueCash[i],1);
    TextDrawLetterSize(TDValueCash[i],0.5,2);
    TextDrawBackgroundColor(TDValueCash[i],COLOR_ValueOut);
    TextDrawFont(TDValueCash[i],3);
    }

    Inhalt anzeigen

    Inhalt anzeigen
    return 1;
    }

    Inhalt anzeigen

    Inhalt anzeigen
    public CheckPlayerState(){ //by Abhinav
    new i,cs;

    Inhalt anzeigen

    Inhalt anzeigen
    for(i=0;i<=MAX_PLAYERS;i++){
    cs=GetPlayerState(i);
    if(DriftMode[i] && cs==PLAYER_STATE_DRIVER && DriftPointsNow[i]>70){
    new Float:h;
    GetVehicleHealth(GetPlayerVehicleID(i),h);
    if(h<HealthInit[i]){
    KillTimer(DriftTimer[i]);
    DriftExit(i);
    GameTextForPlayer(i,"~n~~n~~n~~n~~n~~n~~n~~r~Boom",800,5);
    DriftMode[i]=false;
    }
    }
    if(cs==PLAYER_STATE_DRIVER && DriftMode[i]==false){
    if(GetVType(GetPlayerVehicleID(i))){
    DriftMode[i]=true;
    GetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
    AutoFixBool[i]=false;
    DriftTimer[i]=SetTimerEx("Drift", 200, true, "i", i);
    }
    }
    else if(cs!=PLAYER_STATE_DRIVER && DriftMode[i]==true){
    KillTimer(DriftTimer[i]);
    DriftMode[i]=false;
    AutoFixBool[i]=true;
    }
    else{}
    }
    return 1;
    }

    Inhalt anzeigen

    Inhalt anzeigen
    public AutoFix(){ // By abhinav
    new i;
    for(i=0;i<=MAX_PLAYERS;i++){
    if(AutoFixBool[i] && IsPlayerInAnyVehicle(i)){
    SetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
    }
    }
    }

    Inhalt anzeigen

    Inhalt anzeigen
    GetVType(vid){ // By Abhinav

    Inhalt anzeigen

    Inhalt anzeigen
    new Convertibles[4]={480, 533, 439, 555};
    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};
    new LowRider[8]={536, 575, 534, 567, 535, 566, 576, 412};
    new OffRoad[13]={568, 424, 573, 579, 400, 500, 444, 556, 557, 470, 489, 505, 595};
    new Service[19]={416, 433, 431, 438, 437, 523, 427, 490, 528, 407, 544, 596, 596, 597, 598, 599, 432, 601, 420};
    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};
    new Sports[20]={602, 429, 496, 402, 541, 415, 589, 587, 565, 494, 502, 503, 411, 559, 603, 475, 506, 451, 558, 477};
    new Wagons[5]={418, 404, 479, 458, 561};

    Inhalt anzeigen

    Inhalt anzeigen
    new modelid=GetVehicleModel(vid);
    new i;
    for(i=0;i<3;i++){
    if(Convertibles[i]==modelid) return 1;
    }
    for(i=0;i<25;i++){
    if(Industrial[i]==modelid) return 1;
    }
    for(i=0;i<7;i++){
    if(LowRider[i]==modelid) return 1;
    }
    for(i=0;i<12;i++){
    if(OffRoad[i]==modelid) return 1;
    }
    for(i=0;i<19;i++){
    if(Service[i]==modelid) return 1;
    }
    for(i=0;i<35;i++){
    if(Saloon[i]==modelid) return 1;
    }
    for(i=0;i<20;i++){
    if(Sports[i]==modelid) return 1;
    }
    for(i=0;i<5;i++){
    if(Wagons[i]==modelid) return 1;
    }
    return 0;
    }


    Ich finde einfach nicht den punkt wo abgefragt wird ob es driftet oder nicht O.o.
    Es soll ganz simpel sein erstmal den Rest füge ich dann noch ein, aber mein Problem ist nur die abfrage.

    Einmal editiert, zuletzt von Ghosti8 ()

  • Aber wo wird abgefragt ob das Auto gerade fährt und in welche Richtung es steht(driftet,fährt)?
    Ich will z.b abfragen ob das auto sich nach Norden bewegt und nach Osten kuckt^^. (Also ob es driftet.)

  • Versuch doch die Sache mit den Bonis einfach nach und nach rauszunehmen, dann musst du dich zwar länger damit befassen aber wirst den Code sicherlich besser verstehen.


    Jetzt ist die Frage wo fängt der Teil mit den Bonus etc Sachen an und wo endet er ;).
    Ich weis nicht warum aber ich kann einfach verdammt wenig daraus erkennen obwohl meine
    Kenntnisse gar nicht mal so schlecht sind^^


    Keine Lösung....

    Einmal editiert, zuletzt von Ghosti8 ()