OnPlayerUpdate
#1

Код:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid,15.0,382.4741,2548.9509,20.1041))
    {
    if(IsPlayerInAnyVehicle(playerid))
    {
    SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.2, 0.2, 0.2);
	}
    }
    if(IsPlayerInRangeOfPoint(playerid,15.0,-1185.4705,27.1411,17.6159))
    {
    if(IsPlayerInAnyVehicle(playerid))
    {
    SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.2, 0.2, 0.2);
	}
    }

	new InfoString[512];
	if(IsPlayerConnected(playerid))
	{
	if(GetPlayerScore(playerid) >= 0 && GetPlayerScore(playerid) < 10)
	{
	    State[playerid] = "Noob";
	}
    if(GetPlayerScore(playerid) >= 10 && GetPlayerScore(playerid) < 50)
    {
	    State[playerid] = "Newbie";
	}
    if(GetPlayerScore(playerid) >= 51 && GetPlayerScore(playerid) < 101)
    {
	    State[playerid] = "Hero";
	}
    if(GetPlayerScore(playerid) >= 101 && GetPlayerScore(playerid) < 501)
    {
	    State[playerid] = "Adviser";
	}
    if(GetPlayerScore(playerid) >= 501 && GetPlayerScore(playerid) < 2001)
    {
	    State[playerid] = "Judge";
	}
    if(GetPlayerScore(playerid) >= 2001 && GetPlayerScore(playerid) < 5001)
    {
	    State[playerid] = "Advanced";
	}
    if(GetPlayerScore(playerid) >= 5001 && GetPlayerScore(playerid) < 10001)
    {
	    State[playerid] = "Dominator";
	}
    if(GetPlayerScore(playerid) >= 10001 && GetPlayerScore(playerid) < 100001)
    {
	    State[playerid] = "King";
	}
    if(GetPlayerScore(playerid) >= 100001)
    {
	    State[playerid] = "Minister";
	}
	if(IsPlayerNPC(playerid)) return 0;
	format(InfoString, sizeof(InfoString), "Kills: ~w~~W~%d~N~~r~Deaths: ~W~%d~N~~P~Ratio:~W~ %0.2f~N~~Y~Score: ~W~%d~N~~g~Rank:~W~ %s", pInfo[playerid][Kills],pInfo[playerid][Deaths],Float:pInfo[playerid][Kills]/Float:pInfo[playerid][Deaths],GetPlayerScore(playerid),State[playerid]);
	TextDrawSetString(PPing[playerid], InfoString);
	}
    #if PauseDetectSystem == true
    pTick[playerid] = GetTickCount();
    #endif
    #if MoveSystem == true
    if(pInfo[playerid][Move] == 1)
    GetPlayerHoldingKey(playerid);
    #endif
    return 1;
}
The above code is lagging my server when i get 90+ players anyone have idea to reduce the lags and examples please?
Reply
#2

I am just going to quote myself:
Quote:
Originally Posted by Vince
Посмотреть сообщение
There IS a lot of room for optimizations, however. Using a switch statement can reduce unnecessary calls to GetPlayerScore by 95%. IsPlayerConnected is also a completely redundant function call because callbacks are obviously only called if the player is connected.

But still, it'd be better to move the score part to a separate function entirely and invoke it whenever you use SetPlayerScore. You could write a hook to do it automatically.
Reply
#3

public OnPlayerUpdate(playerid)
{
if(IsPlayerInRangeOfPoint(playerid,15.0,382.4741,2 548.9509,20.1041))
{
if(IsPlayerInAnyVehicle(playerid))
{
SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.2, 0.2, 0.2);
}
}
if(IsPlayerInRangeOfPoint(playerid,15.0,-1185.4705,27.1411,17.6159))
{
if(IsPlayerInAnyVehicle(playerid))
{
SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.2, 0.2, 0.2);
}
}

new InfoString[512];
if(GetPlayerScore(playerid) >= 0 && GetPlayerScore(playerid) < 10)
{
State[playerid] = "Noob";
}
if(GetPlayerScore(playerid) >= 10 && GetPlayerScore(playerid) < 50)
{
State[playerid] = "Newbie";
}
if(GetPlayerScore(playerid) >= 51 && GetPlayerScore(playerid) < 101)
{
State[playerid] = "Hero";
}
if(GetPlayerScore(playerid) >= 101 && GetPlayerScore(playerid) < 501)
{
State[playerid] = "Adviser";
}
if(GetPlayerScore(playerid) >= 501 && GetPlayerScore(playerid) < 2001)
{
State[playerid] = "Judge";
}
if(GetPlayerScore(playerid) >= 2001 && GetPlayerScore(playerid) < 5001)
{
State[playerid] = "Advanced";
}
if(GetPlayerScore(playerid) >= 5001 && GetPlayerScore(playerid) < 10001)
{
State[playerid] = "Dominator";
}
if(GetPlayerScore(playerid) >= 10001 && GetPlayerScore(playerid) < 100001)
{
State[playerid] = "King";
}
if(GetPlayerScore(playerid) >= 100001)
{
State[playerid] = "Minister";
}
if(IsPlayerNPC(playerid)) return 0;
format(InfoString, sizeof(InfoString), "Kills: ~w~~W~%d~N~~r~Deaths: ~W~%d~N~~P~Ratio:~W~ %0.2f~N~~Y~Score: ~W~%d~N~~g~Rank:~W~ %s", pInfo[playerid][Kills],pInfo[playerid][Deaths],FloatInfo[playerid][Kills]/FloatInfo[playerid][Deaths],GetPlayerScore(playerid),State[playerid]);
TextDrawSetString(PPing[playerid], InfoString);
}
#if PauseDetectSystem == true
pTick[playerid] = GetTickCount();
#endif
#if MoveSystem == true
if(pInfo[playerid][Move] == 1)
GetPlayerHoldingKey(playerid);
#endif
return 1;
}
Reply
#4

Sry what about that:
Код:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid,15.0,382.4741,2548.9509,20.1041))
    {
    if(IsPlayerInAnyVehicle(playerid))
    {
    SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.2, 0.2, 0.2);
	}
    }
    if(IsPlayerInRangeOfPoint(playerid,15.0,-1185.4705,27.1411,17.6159))
    {
    if(IsPlayerInAnyVehicle(playerid))
    {
    SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.2, 0.2, 0.2);
	}
    }

	new InfoString[512];
	if(IsPlayerNPC(playerid)) return 0;
	format(InfoString, sizeof(InfoString), "Kills: ~w~~W~%d~N~~r~Deaths: ~W~%d~N~~P~Ratio:~W~ %0.2f~N~~Y~Score: ~W~%d", pInfo[playerid][Kills],pInfo[playerid][Deaths],Float:pInfo[playerid][Kills]/Float:pInfo[playerid][Deaths],GetPlayerScore(playerid));
	TextDrawSetString(PPing[playerid], InfoString);
	}
    #if PauseDetectSystem == true
    pTick[playerid] = GetTickCount();
    #endif
    #if MoveSystem == true
    if(pInfo[playerid][Move] == 1)
    GetPlayerHoldingKey(playerid);
    #endif
    return 1;
}
Reply
#5

a omtimized version of this
pawn Код:
public OnPlayerUpdate(playerid)
{  if(IsPlayerInAnyVehicle(playerid))
    {
    if(IsPlayerInRangeOfPoint(playerid,15.0,382.4741,2548.9509,20.1041))SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.2, 0.2, 0.2);
 if(IsPlayerInRangeOfPoint(playerid,15.0,-1185.4705,27.1411,17.6159))SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.2, 0.2, 0.2);
    }

    new InfoString[512];
    if(IsPlayerNPC(playerid)) return 0;
    format(InfoString, sizeof(InfoString), "Kills: ~w~~W~%d~N~~r~Deaths: ~W~%d~N~~P~Ratio:~W~ %0.2f~N~~Y~Score: ~W~%d", pInfo[playerid][Kills],pInfo[playerid][Deaths],Float:pInfo[playerid][Kills]/Float:pInfo[playerid][Deaths],GetPlayerScore(playerid));
    TextDrawSetString(PPing[playerid], InfoString);
   
    #if PauseDetectSystem == true
    pTick[playerid] = GetTickCount();
    #endif
    #if MoveSystem == true
    if(pInfo[playerid][Move] == 1)
    GetPlayerHoldingKey(playerid);
    #endif
    return 1;
}
Reply
#6

Thanks both + rep.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)