05.07.2013, 15:33
I tested it on localhost with no false positives so far, but I wanna know if it'll be troublesome on a server full of players. The first part is checking for god-mode toggle on foot and in vehicle, second one is for restoring health, armor and vehicle health. Also, how could I optimize it?
pawn Код:
forward CheckGod(playerid);
public CheckGod(playerid)
{
GetPlayerHealth(playerid, Float:gHealth);
SetPlayerHealth(playerid, gHealth -1);
vehGOD = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehGOD, Float:wHealth);
SetVehicleHealth(vehGOD, wHealth -10);
isgod[playerid] = SetTimerEx("IsGod",2000,0,"i",playerid);
return 1;
}
forward IsGod(playerid);
public IsGod(playerid)
{
GetPlayerHealth(playerid, Float:cHealth);
if(GetTickCount() < (lastupdate[playerid]+2000) && gHealth == cHealth)
{
SendClientMessageToAll(-1, "GOD HACKS");
}
else
{
SetPVarFloat(playerid, "faPlayerHealth", gHealth);
SetPlayerHealth(playerid, gHealth);
}
GetVehicleHealth(vehGOD, Float:wwHealth);
if(GetTickCount() < (lastupdate[playerid]+2000) && wHealth == wwHealth && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SendClientMessageToAll(-1, "VEH GOD HACKS");
}
else
{
SetPVarFloat(playerid, "faPlayerVHealth", wHealth);
SetVehicleHealth(vehGOD, wHealth);
}
return 1;
}
forward CheckHealth(playerid);
public CheckHealth(playerid)
{
new Float:fHealth;
GetPlayerHealth(playerid, Float:fHealth);
if(GetPlayerAnimationIndex(playerid))
{
new animlib[32];
new animname[32];
GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
if(!strcmp(animname, "VEND_USE", true))
{
SetPVarFloat(playerid, "faPlayerHealth", 100.0);
SetPlayerHealth(playerid, 100.0);
GivePlayerCash(playerid, -500);
}
}
if(fHealth != GetPVarFloat(playerid, "faPlayerHealth"))
{
if(GetTickCount() < (lastupdate[playerid]+2000) && fHealth > GetPVarFloat(playerid, "faPlayerHealth"))
{
SendClientMessageToAll(-1, "HACKS");
}
else
{
//player lost health && GetPlayerInterior(playerid) == 0
}
SetPVarFloat(playerid, "faPlayerHealth", fHealth);
}
}
forward CheckArmor(playerid);
public CheckArmor(playerid)
{
new Float:fArmor;
GetPlayerArmour(playerid, Float:fArmor);
if(fArmor != GetPVarFloat(playerid, "faPlayerArmor"))
{
if(GetTickCount() < (lastupdate[playerid]+2000) && fArmor > GetPVarFloat(playerid, "faPlayerArmor"))
{
SendClientMessageToAll(-1, "ARMOR HACKS");
}
else
{
//player has lost armor
}
SetPVarFloat(playerid, "faPlayerArmor", fArmor);
}
new Float:vHealth;
new veh1;
veh1 = GetPlayerVehicleID(playerid);
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
GetVehicleHealth(veh1, Float:vHealth);
if(vHealth != GetPVarFloat(playerid, "faPlayerVHealth"))
{
if(GetTickCount() < (lastupdate[playerid]+2000) && vHealth > GetPVarFloat(playerid, "faPlayerVHealth"))
{
SendClientMessageToAll(-1, "VEHICLE HACKS");
}
else
{
//veh lost
}
SetPVarFloat(playerid, "faPlayerVHealth", vHealth);
}
}
for(new i=0; i<sizeof(paynspray); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 10, paynspray[i][0], paynspray[i][1], paynspray[i][2]))
{
CallRemoteFunction("OnVehicleRespray", "iiii", playerid, GetPlayerVehicleID(playerid), -1, -1);
return 1;
}
}
return 1;
}