19.11.2010, 13:54
Well i came to point of hearing every people saying that's OnPlayerUpdate lags my server. Some people say to not use it. Well i probably don't know what to do. Ofc my server lags like hell but i didn't even thought that this code may lag it. So i decided to show my OnPlayerUpdate callback. This really lags? Or it's everything good?
To not being pointless i'll say you whats on this callback. It's just simple scripts for anti team kill, anti money hack and anti airbreak. OFC i wont show all the scripts variables etc. So i need to remove it and my server won't lag again?
To not being pointless i'll say you whats on this callback. It's just simple scripts for anti team kill, anti money hack and anti airbreak. OFC i wont show all the scripts variables etc. So i need to remove it and my server won't lag again?
pawn Код:
public OnPlayerUpdate(playerid)
{
SetPlayerTeam(playerid,gTeam[playerid]);
AntiMoneyCheat(playerid);
pupdates[playerid]++;
if(pupdates[playerid] > UPDATE_COUNT && running == 1){
pupdates[playerid]=0;
new check;
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && IsVehicleValid(GetPlayerVehicleID(playerid))){
new Float:vx,Float:vy,Float:vz;
GetVehicleVelocity(GetPlayerVehicleID(playerid),vx,vy,vz);
if(vx==0.0 && vy==0.0 && vz < -0.0032 && vz > -0.022){
if(IsPlayerInWater(playerid)==0){
check=1;
}
else
{
check=3;
}
}
}
else
{
if(GetPlayerState(playerid)==PLAYER_STATE_ONFOOT && GetPlayerSurfingVehicleID(playerid)==INVALID_VEHICLE_ID){
new Float:vx,Float:vy,Float:vz,Float:px,Float:py,Float:pz;
GetPlayerVelocity(playerid,vx,vy,vz);
pupdates[playerid]=0;
new keys,ud,lr;
GetPlayerKeys(playerid,keys,ud,lr);
if (keys & KEY_SPRINT)
{
if(-0.022 < vz < -0.0040 && -0.235 < vx < 0.235 && -0.235 < vy < 0.235)
{
if(!IsPlayerInRangeOfPoint(playerid,2.0,GetPVarFloat(playerid,"oposx"),GetPVarFloat(playerid,"oposy"),GetPVarFloat(playerid,"oposz")) || -0.5>(GetPVarFloat(playerid,"oposz")-pz)>-0.1 || 0.075>(GetPVarFloat(playerid,"oposz")-pz)>-0.075)
{
if(IsPlayerInWater(playerid)==0)
{
check=2;
if(airbreakcount[playerid] > (POSSIBLE_AIRBREAK_COUNT_ONFOOT-2))
{
SetPlayerVelocity(playerid,0.3,0.3,0.3);
}
}
else
{
check=3;
}
}
SetPVarFloat(playerid,"oposx",px);
SetPVarFloat(playerid,"oposy",py);
SetPVarFloat(playerid,"oposz",pz);
}
}
else
{
if(-0.022 < vz < -0.0040 && -0.121 < vx < 0.121 && -0.121 < vy < 0.121)
{
if(!IsPlayerInRangeOfPoint(playerid,2.0,GetPVarFloat(playerid,"oposx"),GetPVarFloat(playerid,"oposy"),GetPVarFloat(playerid,"oposz")) || -0.5>(GetPVarFloat(playerid,"oposz")-pz)>-0.1 || 0.075>(GetPVarFloat(playerid,"oposz")-pz)>-0.075)
{
if(IsPlayerInWater(playerid)==0)
{
check=2;
if(airbreakcount[playerid] > (POSSIBLE_AIRBREAK_COUNT_ONFOOT-2))
{
SetPlayerVelocity(playerid,0.3,0.3,0.3);
}
}
else
{
check=3;
}
}
SetPVarFloat(playerid,"oposx",px);
SetPVarFloat(playerid,"oposy",py);
SetPVarFloat(playerid,"oposz",pz);
}
}
}
}
if(check > 0)
{
if(check < 3)
{
new POSSIBLE_AIRBREAK_COUNT;
switch(check)
{
case 1: POSSIBLE_AIRBREAK_COUNT=POSSIBLE_AIRBREAK_COUNT_CAR;
case 2: POSSIBLE_AIRBREAK_COUNT=POSSIBLE_AIRBREAK_COUNT_ONFOOT;
}
airbreakcount[playerid]++;
if(airbreakcount[playerid] > POSSIBLE_AIRBREAK_COUNT)
{
airbreakcount[playerid]=0;
new string[60], name[24];
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string),"* %s was been banned (Reason:airbreak)",name);
SendClientMessageToAll(color,string);
SaveToFile("BanLog",string); Ban(playerid);
}
}
}
else
{
airbreakcount[playerid]=0;
}
}
return 1;
}