#include <a_samp> new FlyHack[MAX_PLAYERS]; forward anticheat(playerid); public anticheat(playerid) { for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i)) { new Float:Vel[3], Float:Pos[3]; GetPlayerVelocity(playerid, Vel[0], Vel[1], Vel[2]); new nombre[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME]; GetPlayerName(playerid, nombre, sizeof(nombre)); GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]); if(Vel[0] <= -0.800000 || Vel[1] <= -0.800000 || Vel[2] <= -0.800000) { SetPlayerPos(playerid, Pos[0], Pos[1]-10, Pos[2]); format(string, sizeof(string), "El jugador (%s) esta a una velocidad de X: %f, Y: %f, Z: %f", nombre, Vel[0], Vel[1], Vel[2]); SendClientMessage(playerid, 0xFFFFFFFF, string); FlyHack[playerid] = SetTimerEx("anticheat",10000,0,"d",playerid);//10 segundos return 1; } } } return 1; } public OnPlayerUpdate(playerid) { anticheat(playerid); return 1; }
SetTimer("anticheat", 10000, true);
Lo puedes poner en OnGameModeInit, pero sacalo de OnPlayerUpdate |
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new Float:Vel[3], Float:Pos[3];
GetPlayerVelocity(playerid, Vel[0], Vel[1], Vel[2]);
new nombre[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, nombre, sizeof(nombre));
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
if(Vel[0] <= -0.800000 || Vel[1] <= -0.800000 || Vel[2] <= -0.800000)
{
SetPlayerPos(playerid, Pos[0], Pos[1]-10, Pos[2]);
format(string, sizeof(string), "El jugador (%s) esta a una velocidad de X: %f, Y: %f, Z: %f", nombre, Vel[0], Vel[1], Vel[2]);
SendClientMessage(playerid, 0xFFFFFFFF, string);
FlyHack[playerid] = SetTimerEx("anticheat",10000,0,"d",playerid);//10 segundos
return 1;
}
}
}
forward anticheat();
public anticheat()
{
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if(IsPlayerConnected(playerid))
{
new Float:Vel[3], Float:Pos[3];
GetPlayerVelocity(playerid, Vel[0], Vel[1], Vel[2]);
new nombre[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, nombre, sizeof(nombre));
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
if(Vel[0] <= -0.800000 || Vel[1] <= -0.800000 || Vel[2] <= -0.800000)
{
SetPlayerPos(playerid, Pos[0], Pos[1]-10, Pos[2]);
format(string, sizeof(string), "El jugador (%s) esta a una velocidad de X: %f, Y: %f, Z: %f", nombre, Vel[0], Vel[1], Vel[2]);
SendClientMessage(playerid, 0xFFFFFFFF, string);
}
}
}
return 1;
}
public OnGameModeInit() { SetTimer("AntiCheat", 1000, true); return 1; } forward AntiCheat(); public AntiCheat() { new Float:velocity[3], Float:pos[3], UserName[MAX_PLAYER_NAME], message[100]; for (new i = 0; i != MAX_PLAYERS; i++) { if (! IsPlayerConnected(i)) continue; GetPlayerVelocity(i, velocity[0], velocity[1], velocity[2]); GetPlayerPos(i, pos[0], pos[1], pos[2]); if (velocity[0] <= -0.800000 || velocity[1] <= -0.800000 || velocity[2] <= -0.800000) { if (GetPVarInt(i, "AnticheatMessage") < gettime()) { SetPlayerPos(i, pos[0], pos[1], pos[2]); GetPlayerName(i, UserName, sizeof (UserName)); format(message, sizeof (message), "El jugador (%s) esta a una velocidad de X: %f, Y: %f, Z: %f", UserName, velocity[0], velocity[1], velocity[2]); SendClientMessage(i, 0xFFFFFFFF, message); SetPVarInt(i, "AnticheatMessage", (gettime() +10)); } } } return 1; }
Esta forma de hacerlo serнa la mas indicada. No obstante, a mi punto de vista, es mejor darle las ideas estructuradas a las personas en vez de darles un cуdigo para copiar y pegar con el cual no aprenderбn absolutamente nada.
|
Ni uno ni lo otro serнa mejor porque el cуdigo estб mal.
Con el cуdigo de FelipeAndres el anticheat harнa su funciуn cada diez segundos y йl sуlo quiere enviar el mensaje cada diez segundos pero estar comprobando constantemente. El ъnico buen consejo de FelipeAndres es no utilizar un temporizador por cada jugador. Troydere comentу su idea pero no arreglo el cуdigo, no es un pedido de un cуdigo pero si dejas uno; es porque asн lo tomaste y tu cуdigo deberнa funcionar(y el tuyo no lo hace correctamente). Lo correcto es comprobar constantemente y enviar un mensaje cada diez segundos, serнa con un solo temporizador para todos los jugadores y comprobando con una PVAR para enviar el mensaje cada diez segundos, tambiйn puedes agregar las variables fuera del bucle para no crear las variables que utilizas en la funciуn anticheat por la cantidad de todos tus jugadores, las creas una vez y ya, en lugar de hasta 1000 veces. Код:
public OnGameModeInit() { SetTimer("AntiCheat", 1000, true); return 1; } forward AntiCheat(); public AntiCheat() { new Float:velocity[3], Float:pos[3], UserName[MAX_PLAYER_NAME], message[100]; for (new i = 0; i != MAX_PLAYERS; i++) { if (! IsPlayerConnected(i)) continue; GetPlayerVelocity(i, velocity[0], velocity[1], velocity[2]); GetPlayerPos(i, pos[0], pos[1], pos[2]); if (velocity[0] <= -0.800000 || velocity[1] <= -0.800000 || velocity[2] <= -0.800000) { if (GetPVarInt(i, "AnticheatMessage") < gettime()) { SetPlayerPos(i, pos[0], pos[1], pos[2]); GetPlayerName(i, UserName, sizeof (UserName)); format(message, sizeof (message), "El jugador (%s) esta a una velocidad de X: %f, Y: %f, Z: %f", UserName, velocity[0], velocity[1], velocity[2]); SendClientMessage(i, 0xFFFFFFFF, message); SetPVarInt(i, "AnticheatMessage", (gettime() +10)); } } } return 1; } |