Speedhack
#1

How can i make one BASIC and simple speedhack anti-cheat ?
Reply
#2

Look out for the GetPlayerSpeed function or something smiliar, then in a timer check if its over 1000 or whatever, kick/ban.
Reply
#3

Use this.

pawn Код:
stock Float:GetPlayerSpeed(playerid, bool:Z = true)
{
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
new Float:Speed;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid), SpeedX, SpeedY, SpeedZ);
else GetPlayerVelocity(playerid, SpeedX, SpeedY, SpeedZ);
if(Z) Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatadd(floatpower(SpeedY, 2.0), floatpower(SpeedZ, 2.0))));
else Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatpower(SpeedY, 2.0)));
return floatmul(Speed, 200.0);
}
pawn Код:
if(GetPlayerSpeed(playerid, false) > 300.5) Kick(playerid);
Or whatever...
Reply
#4

Quote:
Originally Posted by ¤Adas¤
Use this.

pawn Код:
stock Float:GetPlayerSpeed(playerid, bool:Z = true)
{
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
new Float:Speed;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid), SpeedX, SpeedY, SpeedZ);
else GetPlayerVelocity(playerid, SpeedX, SpeedY, SpeedZ);
if(Z) Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatadd(floatpower(SpeedY, 2.0), floatpower(SpeedZ, 2.0))));
else Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatpower(SpeedY, 2.0)));
return floatmul(Speed, 200.0);
}
pawn Код:
if(GetPlayerSpeed(playerid, false) > 300.5) Kick(playerid);
Or whatever...
i make on this way

Код:
stock Float:GetPlayerSpeed(playerid, bool:Z = true)
{
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
new Float:Speed;
if(GetPlayerSpeed(playerid, false) > 300.5) Kick(playerid);
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid), SpeedX, SpeedY, SpeedZ);
else GetPlayerVelocity(playerid, SpeedX, SpeedY, SpeedZ);
if(Z) Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatadd(floatpower(SpeedY, 2.0), floatpower(SpeedZ, 2.0))));
else Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatpower(SpeedY, 2.0)));
return floatmul(Speed, 200.0);
}
but it dosent work, can somebody help?!
Reply
#5

Not sure if this will work, but it's worth a try.

First add the code Adas gave you.
Код:
stock Float:GetPlayerSpeed(playerid, bool:Z = true)
{
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
new Float:Speed;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid), SpeedX, SpeedY, SpeedZ);
else GetPlayerVelocity(playerid, SpeedX, SpeedY, SpeedZ);
if(Z) Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatadd(floatpower(SpeedY, 2.0), floatpower(SpeedZ, 2.0))));
else Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatpower(SpeedY, 2.0)));
return floatmul(Speed, 200.0);
}
Then after that add:

Код:
public OnPlayerUpdate(playerid)
{
  if(GetPlayerSpeed(playerid, false) > 325.0)
  {
	if(!IsPlayerAdmin(playerid))
	{
	  // Anything here you'll add for a ban or kick.
	  return 1;
	}
	return 1;
  }
  return 1;
}
Hope it works.
Reply
#6

Quote:
Originally Posted by AK47KILLA
Код:
public OnPlayerUpdate(playerid)
{
    if(GetPlayerSpeed(playerid, false) > 325.0)
	{
	if(!IsPlayerAdmin(playerid))
	{
	  // Anything here you'll add for a ban or kick.
	  return 1;
	}
	return 1;
  }
	return 1;
}
Bad idea, OnPlayerUpdate gets called hundreds of times per second, rather do
pawn Код:
//at top of script
forward AntiSpeedHack();
//under OnGamemodeInit() or OnFilterscriptInit()
SetTimer("AntiSpeedHack",2000,true);

//at bottom of script
public AntiSpeedHack()
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerSpeed(i, false) > 325.0)
        {
             //your code here, maybe remove the player from his vehicle or kick/ban him
             return 1;
         }
     }
     return 1;
}
That will be much less CPU intensive.

EDIT: Make sure you also add that stock function to the script.
Reply
#7

Quote:
Originally Posted by biltong
Quote:
Originally Posted by AK47KILLA
Код:
public OnPlayerUpdate(playerid)
{
    if(GetPlayerSpeed(playerid, false) > 325.0)
	{
	if(!IsPlayerAdmin(playerid))
	{
	  // Anything here you'll add for a ban or kick.
	  return 1;
	}
	return 1;
  }
	return 1;
}
Bad idea, OnPlayerUpdate gets called hundreds of times per second, rather do
pawn Код:
//at top of script
forward AntiSpeedHack();
//under OnGamemodeInit() or OnFilterscriptInit()
SetTimer("AntiSpeedHack",2000,true);

//at bottom of script
public AntiSpeedHack()
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerSpeed(i, false) > 325.0)
        {
             //your code here, maybe remove the player from his vehicle or kick/ban him
             return 1;
         }
     }
     return 1;
}
That will be much less CPU intensive.

EDIT: Make sure you also add that stock function to the script.
Yeah, I know timers are better, thing is that I'm not good with timers yet. :P
Reply
#8

Time to learn :P

That was a really easy one. A timer basically calls a function or callback after the set time expires.
Let me break it down:

The function/callback you want to use goes in the ""s SetTimer("*your function here*",1000,false);

If it's a custom function you MUST forward the name of it at the top of your script and when you use it, it MUST be public. You don't put the public part in
the ""s, nor any parameters.

The time goes in the middle and is measured in milliseconds

The true/false part decides whether the timer repeats itself after the set time expires.

PM me if you want me to explain SetTimerEx

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)