Lag when Dissconect +rep rep rep!
#1

I Get Some Problem,

when player are disconnect the server will be lag and Crash,

the code:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    KillTimer(HospitalCountDown[playerid]);
    HospitalTime[playerid] = 0;
    IsDead[playerid] = -1;
    DestroyProgressBar(hungry[playerid]);
    DestroyProgressBar(haus[playerid]);
    DestroyProgressBar(energy[playerid]);
    if(PlayerInfo[playerid][pSpawnVehicle])
    {
        DestroyVehicle(PlayerInfo[playerid][pSpawnVehicle]);
    }
    if(aDuty[playerid] == 1)
    {
        new name[MAX_PLAYER_NAME];
        GetPVarString(playerid, "OldName", name, sizeof(name));
        SetPlayerName(playerid, name);
        aDuty[playerid] = 0;
    }
    SaveChar(playerid);
    new strings[128];
    switch(reason)
    {
        case 0: // Crashed
        {
            format(strings, sizeof(strings), "* %s {00C0FF}Telah Meninggalkan Server. {FF0000}(Koneksi Terputus)", RPN(playerid));
            SendClientMessageToAll(COLOR_YELLOW, strings);
        }
        case 1: // Leaving
        {
            format(strings, sizeof(strings), "* %s {00C0FF}Telah Meninggalkan Server. {FF0000}(/q atau exit)", RPN(playerid));
            SendClientMessageToAll(COLOR_YELLOW, strings);
        }
        case 2: // Kicked/Banned
        {
            format(strings, sizeof(strings), "* %s {00C0FF}Telah Meninggalkan Server. {FF0000}(Kicked atau Banned)", RPN(playerid));
            SendClientMessageToAll(COLOR_YELLOW, strings);
        }
    }
    if(PlayerInfo[playerid][pMasked] == 1)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            ShowPlayerNameTagForPlayer(i, playerid, 1); // ShowPlayerNameTagForPlayer(i, playerid, 1) show name back.
        }
    }
    ProdSell[playerid] = 0;
    PProdSell[playerid] = 0;
    //TextDrawDestroy(Fuelbox[playerid]);
    //TextDrawDestroy(Fspeed[playerid]);
    //TextDrawDestroy(Vhealth[playerid]);
    //TextDrawDestroy(fuel[playerid]);
    if(adostatus[playerid] == 1)
    {
        DestroyDynamic3DTextLabel(ado[playerid]);
        adostatus[playerid] = 0;
    }
    if(amestatus[playerid] == 1)
    {
        DestroyDynamic3DTextLabel(ame[playerid]);
        amestatus[playerid] = 0;
    }
    //amestatus[playerid] = 0;
    //adostatus[playerid] = 0;
    MusicStereo[playerid] = 0;
    MusicStereoPlayer[playerid] = -1;
    MusicStereoStream[playerid] = 0;
    bpos[playerid][0] = 0; bpos[playerid][1] = 0; bpos[playerid][2] = 0; bpos[playerid][3] = 0;
    format(MusicStereoURL[playerid], 256, "");
    if(IsValidDynamicObject(MusicStereoObject[playerid]))
    {
        DestroyDynamicObject(MusicStereoObject[playerid]);
    }
    for(new pp=0; pp<MAX_PLAYERS; pp++)
    {
        if(IsPlayerConnected(pp))
        {
            if(MusicStereoPlayer[pp] == playerid)
            {
                    MusicStereoStream[pp] = 0;
                    MusicStereoPlayer[pp] = -1;
                    StopAudioStreamForPlayer(pp);
                    SendClientMessage(pp, COLOR_GREY, " The MusicStereo creator has disconnected from the server.");
            }
        }
    }
    if(BankRobber[playerid])
    {
        new Rob = BankRobber[playerid]-1, string[128];
        DisablePlayerCheckpoint(playerid);
        BankRobbersCount --;
        format(BankRobbers[Rob], MAX_PLAYER_NAME, "");
        DeliverMoney[playerid] = 0;
        //
        format(string, sizeof(string), "** %s has disconnected and has failed the robbery. **", RPN(playerid));
        SendRobberyMessage(COLOR_LIGHTRED, string);
        SendCopMessage(COLOR_LIGHTRED, string);
        BankRobber[playerid] = 0;
        if(BankRobbersCount == 0)
        {
            TextDrawHideForAll(Textdraw0);
            TextDrawHideForAll(Textdraw1);
            TextDrawHideForAll(Textdraw2);
            TextDrawHideForAll(Textdraw3);
            TextDrawHideForAll(Textdraw4);
            TextDrawHideForAll(Textdraw5);
//          BankRobbery = 0;
            RobberyStarted = 0;
            format(string, sizeof(string), "** The bank robbery has ended, $%d were stolen and $%d were saved. **", TotalStolen*10000, (TotalRobbers*10000-(TotalStolen*10000)));
            SendClientMessageToAll(COLOR_YELLOW, string);
            TotalRobbers = 0;
            //new copsonline;
        }
    }
    RemovePlayerAttachedObject(playerid, 0);
    //paintball
    if(PlayerPaintballing[playerid] == 1)
    {
        ResetPlayerWeapons(playerid);
        ResetDodWeapons(playerid);
        SetPlayerPos(playerid,1310.1110,-1368.5656,13.517786);
        for(new w = 0; w < 13; w++)
        {
            GiveDodWeapon(playerid, PlayerInfo[playerid][pWeapon][w], PlayerInfo[playerid][pWeaponAmmo][w]);
        }
    }
    // Boxing
    new string[128];
    if(Boxing[playerid])
    {
        // Getting other boxer's ID
        new playerb = -1;
        if(playerb != -1)
        {
            format(string, sizeof(string), "Boxing Ring: The boxing match has ended, %s has won the match.", RPN(playerb));
            SendGymMessage(COLOR_WHITE, string);
            // Putting them out of the ring
            SetPlayerPos(playerb, 760.9759,4.7187,1000.7084);
            SetPlayerFacingAngle(playerb, 268.9407);
            SetPlayerPos(playerid, 760.9759,6.1794,1000.7093);
            SetPlayerFacingAngle(playerid, 268.9407);
            // Giving the winner extra skill point
            new oldj = strval(RPJL(playerb, JOB_BOXER));
            PlayerInfo[playerb][pJobSkill][JOB_BOXER] ++;
            new newj = strval(RPJL(playerb, JOB_BOXER));
            if(oldj < newj)
            {
                format(string, sizeof(string), "** Your Boxer level is now %d, you can now cause %d more damage. **", newj, (newj*2)-2);
                SendClientMessage(playerb, COLOR_YELLOW, string);
            }
            //
            SendClientMessage(playerb, COLOR_LIME, " You have won the boxing match.");
            SendClientMessage(playerid, COLOR_LIGHTRED, " You have lost the boxing match.");
            // Giving Bids
            for(new w = 0; w < 13; w++)
            {
                GiveDodWeapon(playerb, PlayerInfo[playerb][pWeapon][w], PlayerInfo[playerb][pWeaponAmmo][w]);
            }
        }
        for(new w = 0; w < 13; w++)
        {
            GiveDodWeapon(playerid, PlayerInfo[playerid][pWeapon][w], PlayerInfo[playerid][pWeaponAmmo][w]);
        }
        // Resetting Values
        BoxingMatch = 0;
        Boxer[1] = -1;
        pBoxer[playerb] = 0;
        Boxer[2] = -1;
        pBoxer[playerid] = 0;
        Boxing[playerb] = 0;
        Boxing[playerid] = 0;
        BoxerBid[1] = 0;
        BoxerBid[2] = 0;
        if(BoxTime)
        {
            TogglePlayerControllable(playerb, 1);
            KillTimer(BoxTimer);
        }
    }
    // The rest
    foreach(Player, i)
    {
        if(BankRobber[playerid])
        {
            new Rob = BankRobber[playerid]-1;
            new copsonline;
            if(BankRobber[i] || PlayerInfo[i][pFac] == 1)
            {
                if(Rob == 0) TextDrawHideForPlayer(i, Textdraw1);
                else if(Rob == 1) TextDrawHideForPlayer(i, Textdraw2);
                else if(Rob == 2) TextDrawHideForPlayer(i, Textdraw3);
                else if(Rob == 3) TextDrawHideForPlayer(i, Textdraw4);
                else if(Rob == 4) TextDrawHideForPlayer(i, Textdraw5);
            }
            if(IsACop(i))
            {
                    copsonline++;
                    new Saved = (TotalRobbers*10000-(TotalStolen*10000));
                    GivePlayerCash(i, Saved/copsonline);
                    new fstringz[128];
                    format(fstringz, sizeof(fstringz), "** You have received your cut from the saved money. ($%d)", Saved/copsonline);
                    SendClientMessage(i, COLOR_LIME, fstringz);
            }
        }
        new playerb = -1;
        if(Boxing[i] && i != playerid) playerb = i;
        new winner = pBoxer[playerb];
        if(BidBoxer[i] == winner)
        {
            new percent, profit;
            percent = (BidAmount[i]/BoxerBid[winner]) * 10000;
            profit = (percent * BoxerBid[pBoxer[playerid]]) / 10000;
            GivePlayerCash(i, BidAmount[i] + profit);
            format(string, sizeof(string), " You have won $%d from bidding in the match, the money you bid has been returned as well.", profit);
            SendClientMessage(i, COLOR_LIME, string);
        }
        BidAmount[i] = 0;
        BidBoxer[i] = 0;
        if(Specid[i] == playerid)
        {
            Spec[i] = 0;
            Specid[i] = -1;
            TogglePlayerSpectating(i, 0);
            SetPlayerVirtualWorld(i, PlayerInfo[playerid][pVW]);
            SetPlayerInterior(i, PlayerInfo[playerid][pInt]);
            SetPlayerPos(i, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
            SendClientMessage(i, COLOR_WHITE, " You have stopped spectating players.");
        }
    }
    // Clearing AD
    for(new i=0; i<MAX_ADS; i++)
    {
        if(strfind(AD[i], RPN(playerid)) != -1)
        {
            format(AD[i], 128, "");
        }
    }
    // End of Clearing AD
    ClearChar(playerid);
    if(Planted[playerid] == 1)
    {
        DestroyObject(C4[playerid]);
        Bomb[playerid] = 0;
        Planted[playerid] = 0;
    }
    return 1;
}
+ rep if fixed
Reply


Messages In This Thread
Lag when Dissconect +rep rep rep! - by mahardika - 07.03.2014, 12:21
Re: Lag when Dissconect +rep rep rep! - by tysanio - 07.03.2014, 13:23

Forum Jump:


Users browsing this thread: 1 Guest(s)