SA-MP Forums Archive
Server Stuck - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Server (https://sampforum.blast.hk/forumdisplay.php?fid=6)
+--- Forum: Server Support (https://sampforum.blast.hk/forumdisplay.php?fid=19)
+--- Thread: Server Stuck (/showthread.php?tid=614610)



Server Stuck - Nin9r - 10.08.2016

Hi there !

I saw that sometime my server go stuck for few seconds. Also, all the players / timers are out of sync ( show afk / clock stuck ). After 2-3 seconds it works again. But I don't know why. I guess there is a command which causing it but i don't know which one. How can I detect it?


Re: Server Stuck - Logic_ - 10.08.2016

Show us your OnPlayerUpdate callback


Re: Server Stuck - Nin9r - 10.08.2016

Код HTML:
public OnPlayerUpdate(playerid)
{
	new vehicleid = GetPlayerVehicleID(playerid);
	if(IsADmvCar(vehicleid))
	{
	    new Float:vhp;
		GetVehicleHealth(vehicleid,vhp);
		if(vhp < 600)
		{
			SetVehicleToRespawn(vehicleid);
			RemovePlayerFromVehicle(playerid);
			TakingLesson[playerid] = 0;
			DisablePlayerRaceCheckpoint(playerid);
		}
	}
    new drunk2 = GetPlayerDrunkLevel(playerid);
        if(drunk2 < 100)
        {
            SetPlayerDrunkLevel(playerid,2000);
        }
        else
        {
            if(DLlast[playerid] != drunk2)
            {
                new fps = DLlast[playerid] - drunk2;

                if((fps > 0) && (fps < 200))
                        FPS2[playerid] = fps;
                        DLlast[playerid] = drunk2;
                }
        }
	if(GetPlayerVehicleID(playerid) != 0 )
		 	{
				if(GetPlayerVehicleID(playerid) != GetPVarInt(playerid, "Vehicle_ID"))
				 {
					if(GetPVarInt(playerid, "Vehicle_Time") > gettime()) return  Kick(playerid);
					SetPVarInt(playerid, "Vehicle_ID", GetPlayerVehicleID(playerid));
					SetPVarInt(playerid, "Vehicle_Time", gettime() + 2);
				}
			}
	if (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
	{
		new Float:vec[3];
		GetPlayerCameraFrontVector(playerid, vec[0], vec[1], vec[2]);
		new bool:possible_crasher = false;
		for (new i = 0; !possible_crasher && i < sizeof(vec); i++)
			if (floatabs(vec[i]) > 10.0)
				possible_crasher = true;

		if (possible_crasher)
			return 0; //do not send fake data, prevents crash
	}
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid])
                {
                    new a, b, c;
                        GetPlayerKeys(playerid, a, b ,c);
                    if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid])
                    {
                        new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid];
                        ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
                    }
                }
    new
             iTick = GetTickCount( ),
             iAnimationIndex = GetPlayerAnimationIndex( playerid ),
             iWeapon = GetPlayerWeapon( playerid ),
             iKeys,
             iKeysUD,
             iKeysLR
    ;

    GetPlayerKeys( playerid, iKeys, iKeysUD, iKeysLR );

    if ( ( iKeys & KEY_FIRE ) || ( ( iKeys & KEY_ACTION ) && ( iKeys & KEY_AIM ) ) )
    {
        CBugPlayerInfo[ playerid ][ iLastFire ] = iTick;

        if ( !CBugPlayerInfo[ playerid ][ isFiring ] )
        {
            CBugPlayerInfo[ playerid ][ isFiring ] = true;

            CBugPlayerInfo[ playerid ][ iLastFiring ] = iTick;
        }
    }
    else if ( CBugPlayerInfo[ playerid ][ isFiring ] )
        CBugPlayerInfo[ playerid ][ isFiring ] = false;

    switch ( iAnimationIndex )
    {
        case 1274: // WEAPON_CROUCH
        {
            if ( !CBugPlayerInfo[ playerid ][ isCrouched ] )
            {
                CBugPlayerInfo[ playerid ][ isCrouched ] = true;

                CBugPlayerInfo[ playerid ][ iCrouchTime ] = iTick;
            }

            if ( iWeapon && ( iKeys & KEY_FIRE ) && iTick - CBugPlayerInfo[ playerid ][ iCrouchTime ] > 300 )
                ClearAnimations( playerid );
        }

        case 1160 .. 1163, 1167: // GUNMOVE_L/R/FWD/BWD, GUN_STAND
        {
            if ( ( iKeys & KEY_FIRE ) )
            {
                switch ( iWeapon )
                {
                    case
                        WEAPON_SILENCED,
                        WEAPON_DEAGLE,
                        WEAPON_SHOTGUN,
                        WEAPON_SHOTGSPA,
                        WEAPON_MP5,
                        WEAPON_M4,
                        WEAPON_AK47,
                        WEAPON_RIFLE,
                        WEAPON_SNIPER:
                    {
                        CBugPlayerInfo[ playerid ][ iLastStrafeFire ] = iTick;
                    }
                }
            }
        }

        case
            1231, // RUN_PLAYER
            1223, // RUN_ARMED
            1141, // FIGHTA_M
            478,  // FIGHTB_M
            489,  // FIGHTC_M
            500,  // FIGHTD_M
            759,  // KNIFE_PART
            27,   // BAT_PART
            1554  // SWORD_PART
            :
        {
            switch ( GetWeaponSlot( iWeapon ) )
            {
                case 0, 1, 8, 9, 10, 11, 12:
                {

                }
                default:
                {
                    if ( ( iKeys & KEY_AIM ) && ( iKeys & KEY_ACTION ) ) {
                        ClearAnimations( playerid );
						return 2;
					}
                    else if ( CBugPlayerInfo[ playerid ][ isFiring ] && iTick - CBugPlayerInfo[ playerid ][ iLastFiring ] > 150 ) {
                        ClearAnimations( playerid );
						return 2;
					}
                }
            }
        }
    }

    if ( ( iKeys & KEY_CROUCH ) && iTick - CBugPlayerInfo[ playerid ][ iLastStrafeFire ] < 500 )
    {
        ClearAnimations( playerid );

        ApplyAnimation( playerid, "PED", "XPRESSscratch", 0.0, 1, 0, 0, 0, 500 - ( iTick - CBugPlayerInfo[ playerid ][ iLastStrafeFire ] ), 1 );
		return 2;
    }

    if ( CBugPlayerInfo[ playerid ][ isCrouched ] && iAnimationIndex != 1274 ) // WEAPON_CROUCH
        CBugPlayerInfo[ playerid ][ isCrouched ] = false;
        
    if(GetPlayerSurfingVehicleID(playerid) != INVALID_VEHICLE_ID && GetPlayerWeapon(playerid) != 0)
	{
	    new Float: slx, Float: sly, Float:slz;
	    GetPlayerPos(playerid, slx, sly, slz);
		SetPlayerPosEx(playerid, slx, sly, slz+5);
	    SetPlayerArmedWeapon(playerid,0);
	}
	return 1;
}



Re: Server Stuck - Logic_ - 10.08.2016

use a global timer of a second and loop through it, using a lot of stuff in OnPlayerUpdate causes lag, and how many timers are you running?


Re: Server Stuck - Nin9r - 10.08.2016

7-12 in ongamemodeini - global timers


Re: Server Stuck - Logic_ - 10.08.2016

Reduce timers and reduce the usage of OnPlayerUpdate.


Re: Server Stuck - iKarim - 10.08.2016

Please. Don't misuse OnPlayerUpdate. That callback is called something nearly 33 times per second when the player doing activities such as running, swimming, or driving. Why do you need such a low interval? Create a global 1 or 2 second(s) timer and loop through players using foreach instead.


Re: Server Stuck - Logic_ - 10.08.2016

Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
Please. Don't misuse OnPlayerUpdate. That callback is called something nearly 33 times per second when the player doing activities such as running, swimming, or driving. Why do you need such a low interval? Create a global 1/2 second(s) timer and loop through players using foreach instead.
I don't understand why people use OnPlayerUpdate for everything and use FPS system/ textdraws... which is totally in-accurate, Tell them to use Fraps or a cleo mod...