SA-MP Forums Archive
DeBug: Script is crashing server. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: DeBug: Script is crashing server. (/showthread.php?tid=355083)



DeBug: Script is crashing server. - TyThaBomb - 28.06.2012

So, I'm getting these two lines when my server's running:

Code:
8:31] [debug]   Accessing element at index 40 past array upper bound 39
[17:28:31] [debug] Run time error 4: "Array index out of bounds"
[17:28:31] [debug] #0  00034744 in public CheckPlayerState () from ApocalypticDrift.amx
[17:28:31] [debug] AMX backtrace:

[17:28:31] [debug]   Accessing element at index 40 past array upper bound 39
[17:28:31] [debug] Run time error 4: "Array index out of bounds"
[17:28:31] [debug] #0  00032da8 in public Drift () from ApocalypticDrift.amx
[17:28:31] [debug] AMX backtrace:
I don't know what's wrong with the Drift() and CheckPlayerState(), but here's the codes:

pawn Code:
public Drift(){
        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);
                }

                if(DriftPointsNow[g] > 70 && DriftPointsNow[g]<10000){
                    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;
                    }

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

                    TextDrawShowForPlayer(g,TDValueDrift[g]);
                    TextDrawShowForPlayer(g,TDValueBonus[g]);

                    new DPs[128],DBn[128];

                    valstr(DPs,DriftPointsNow[g],false);
                    format(DBn,sizeof(DBn),"X%i",DriftBonus[g]);

                    TextDrawSetString(TDValueDrift[g],DPs);
                    TextDrawSetString(TDValueBonus[g],DBn);
                }
                SavedPos[ g ][ sX ] = X;
                SavedPos[ g ][ sY ] = Y;
                SavedPos[ g ][ sZ ] = Z;
            }
}
pawn Code:
public CheckPlayerState(){
    new i,cs;

    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<1000){
                KillTimer(DriftTimer[i]);
                DriftExit(i);
                GameTextForPlayer(i,"~n~~n~~n~~n~~n~~n~~n~~r~Drift Lost!",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]);
                DriftTimer[i]=SetTimerEx("Drift", 200, true, "i", i);
            }
        }
        else if(cs!=PLAYER_STATE_DRIVER && DriftMode[i]==true){
            KillTimer(DriftTimer[i]);
            DriftMode[i]=false;
        } else{ }
    }
    return 1;
}
Any help would be greatly appreciated, this is an edited version of Luby's driftscript, for your information.