SA-MP Forums Archive
anticheat not working - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: anticheat not working (/showthread.php?tid=400081)



anticheat not working - PDChaseOfficial - 16.12.2012

Hello. I am working on a anticheat that would check if person is using health cheats. Basically, it creates a bang around him and after 500 miliseconds it checks if the health decreased or not. However, everytime I do it, it tells me im a cheater, even if I dont have cheats on. Any ideas please?

Code:
forward healthcheckinveh(playerid,targetid,oldhealth,newhealth,vid,seat);
forward healthcheck(playerid,targetid,oldhealth,newhealth);

CMD:explode(playerid,params[])
{
	if(PlayerInfo[playerid][pAdmin]<3) return SendClientMessage(playerid,COLOR_RED,"Acces denied.");
	new targetid;
	if(sscanf(params,"u",targetid)) return SendClientMessage(playerid,COLOR_RED,"usage: /explode [id].");
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED,"Invalid ID.");
	if(!IsPlayerInAnyVehicle(targetid))
	{
            new Float:x,Float:y,Float:z;
	    new Float:oldhealth;
	    GetPlayerPos(targetid,x,y,z);
    	    GetPlayerHealth(targetid,oldhealth);
	    CreateExplosion(x,y,z,8,10);
	    SetTimer("healthcheck",500,0);
	}
	else // if player is in vehicle
	{
		new vid=GetPlayerVehicleID(targetid);
		new seat=GetPlayerVehicleSeat(targetid);
		new Float:x,Float:y,Float:z;
		new Float:oldhealth;
		GetPlayerPos(targetid,x,y,z);
		SetPlayerPos(targetid,x,y+100,z);
		GetPlayerHealth(targetid,oldhealth);
		CreateExplosion(x,y,z,8,10);
		SetTimer("healthcheckinveh",500,0);
	}
	return 1;
}

public healthcheckinveh(playerid,targetid,oldhealth,newhealth,vid,seat)
{
	new Float:newhealth;
        GetPlayerHealth(targetid,newhealth);
        if(newhealth>=oldhealth) SendClientMessage(playerid,COLOR_RED,"Cheater.");
	SetPlayerHealth(targetid,oldhealth);
	PutPlayerInVehicle(targetid,vid,seat);
	return 1;
}

public healthcheck(playerid,targetid,oldhealth,newhealth)
{
        new Float:newhealth;
        GetPlayerHealth(targetid,newhealth);
   	if(newhealth>=oldhealth) SendClientMessage(playerid,COLOR_RED,"Cheater.");
   	SetPlayerHealth(targetid,oldhealth);
   	return 1;
}



Re: anticheat not working - [KHK]Khalid - 16.12.2012

Use SetTimerEx instead of SetTimer so you can pass arguments. Also create a per-player global variable to hold timers.


Re: anticheat not working - PDChaseOfficial - 16.12.2012

Thanks buddy. Works.