18.08.2010, 21:22
Bem, eu criei um tуpico anteriormente sobre essa mesma duvida, mais alйm de nгo achar ele, tambйm estб faltando coisas para que o meu problema seja resolvido. Entгo criei esse novo com o Anto-Afk por completo postado.
Aqui vai: Estou com o seguinte problema, o depois que o Anti-Afk detecta que o player estб Afk, ele manda o player digitar umas letras (Parecendo com Captcha) entгo o player digita corretamente e й liberado para andar e fica tudo normal caso ele nгo esteje Afk, porйm, depois que o player digita as letras/numeros corretamente, as mensagens do player nao aparecem masi no chat, ele volta a Andar e tal, mais as mensagens nгo aparecem. Como arrumo isso?
Aqui vai: Estou com o seguinte problema, o depois que o Anti-Afk detecta que o player estб Afk, ele manda o player digitar umas letras (Parecendo com Captcha) entгo o player digita corretamente e й liberado para andar e fica tudo normal caso ele nгo esteje Afk, porйm, depois que o player digita as letras/numeros corretamente, as mensagens do player nao aparecem masi no chat, ele volta a Andar e tal, mais as mensagens nгo aparecem. Como arrumo isso?
pawn Код:
// --- INTRO/INFORMATION ---
/*
IMPORTANT:
-By using this code in any way, you agree to the license provided.
-Requires foreach
AGREEMENT:
Copyright © 2010 Adam "Chaprnks" Chaprnka
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the SA:MP efficient anti-afk code.
The Initial Developer of the Original Code is Adam "Chaprnks" Chaprnka.
Efficient anti-AFK
by Chaprnks (zZ PacMan Zz)
-In short words, what does this do?
It checks the players velocity and counts up how long it has
been since they haven't moved. When they haven't been moving
for more than the set time, it asks them to put a random set
of characters into the chat. Confirming they are not AFK.
-Why this better towards the traditional method?
The usual anti-AFK methods are pretty unefficient. Numerous
problems can occur. Kicking them when they are actually still
active on the server!
-PVar List
AFKKickTimer - INTEGER
IsAFK - INTEGER
AFKTime - INTEGER
ReturnKey - STRING
OldPosX - FLOAT
OldPosY - FLOAT
OldPosZ - FLOAT
*/
#include <a_samp>
#define FILTERSCRIPT
#include <foreach>
// --- SETTINGS ---
// These current settings will work completely fine, but this
// is for your own customization =)
// If the random message given to the player will be in mixed
// case, or all uppercase.
// Original = 1
#define MIXED_CASE (1)
// If the random message given to the player has to be same
// case. Ex: AAA != aaa.
// Original = 1
#define CASE_SENSITIVE (1)
// The length of random characters presented to the player
// that is suspected to be AFK.
// Original = 10
#define MSG_LENGTH (10)
// The type of time the player can be not moving before
// the server asks for an input.
// 1 = Milliseconds, 2 = Seconds, 3 = Minutes, 4 = Hours
// Original = 3
#define AFK_TIMER_TYPE (3)
// The time the player can be not moving before
// the server asks for an input.
// Original = 15
#define AFK_TIMER_AMOUNT (4)
// The amount of times the player is checked as AFK before
// asking for input.
// Example: 1 minute timer, 15 times = 15 minutes afk
// Original = 15
#define AFK_TIMES (1)
// The type of time the player has until the server kicks.
// 1 = Milliseconds, 2 = Seconds, 3 = Minutes, 4 = Hours
// Original = 3
#define AFK_DELAYKICK_TYPE (2)
// The amount of time the player has until the server kicks.
// Original = 2
#define AFK_DELAYKICK_AMOUNT (40)
// If you want any messages inputed by the player to reset
// the afk timer.
// Original = 0
#define CMD_RESET (0)
// The method of detecting movement. 1 = Velocity, 2 = Coordinate change
// Original = 1
#define MOVEMENT_TYPE (1)
// Exclude any RCON admins from the afk check
// Original = 1
#define EXCLUDE_RCON (1)
// --- CODE START ---
#if !defined MIXED_CASE || !defined CASE_SENSITIVE || !defined MSG_LENGTH || !defined AFK_TIMER_TYPE || !defined AFK_TIMER_AMOUNT || !defined AFK_DELAYKICK_TYPE || !defined AFK_DELAYKICK_AMOUNT || !defined CMD_RESET || !defined MOVEMENT_TYPE || !defined EXCLUDE_RCON
#error "One of the settings is commented out / removed!"
#endif
#if AFK_TIMER_AMOUNT <= 0
#error "AFK timer cannot be zero!"
#endif
#define FUNCTION:%1(%2) \
forward %1(%2); \
public %1(%2)
#define COLOR_LIGHTRED (0xFF6347FF)
new
MainTimer;
public OnFilterScriptInit()
{
#if AFK_TIMER_TYPE == 1
MainTimer = SetTimer("MainAFKLoop", AFK_TIMER_AMOUNT, true);
#elseif AFK_TIMER_TYPE == 2
MainTimer = SetTimer("MainAFKLoop", (AFK_TIMER_AMOUNT*1000), true);
#elseif AFK_TIMER_TYPE == 3
MainTimer = SetTimer("MainAFKLoop", (AFK_TIMER_AMOUNT*60000), true);
#elseif AFK_TIMER_TYPE == 4
MainTimer = SetTimer("MainAFKLoop", (AFK_TIMER_AMOUNT*3600000), true);
#endif
return 1;
}
public OnFilterScriptExit()
{
KillTimer(MainTimer);
return 1;
}
#if CMD_RESET == 1
public OnPlayerCommandText(playerid, cmdtext[])
{
SetPVarInt(playerid, "AFKTime", 0);
}
#endif
public OnPlayerText(playerid, text[])
{
if(GetPVarInt(playerid, "IsAFK") == 1)
{
new tempkey[MSG_LENGTH+1];
GetPVarString(playerid, "ReturnKey", tempkey, MSG_LENGTH+1);
#if CASE_SENSITIVE == 1
if(strcmp(text, tempkey, false) == 0)
#elseif CASE_SENSITIVE == 0
if(strcmp(text, tempkey, true) == 0)
#endif
{
SendClientMessage(playerid, COLOR_LIGHTRED, "| Anti-Afk | Ok, vocк nгo estб AFK.");
TogglePlayerControllable(playerid, 1);
KillTimer(GetPVarInt(playerid, "AFKKickTimer"));
SetPVarInt(playerid, "IsAFK", 0);
}
else
{
SendClientMessage(playerid, COLOR_LIGHTRED, "| Anti-Afk | O Texto que vocк digitou estб incorreto!");
}
}
}
FUNCTION:MainAFKLoop()
{
foreach(Player, i)
{
new string[128];
#if EXCLUDE_RCON == 1
if(IsPlayerAdmin(i))
{
return 1;
}
#endif
#if MOVEMENT_TYPE == 1
new
speed,
Float:velx, Float:vely, Float:velz,
vehicleid = GetPlayerVehicleID(i);
if(!vehicleid)
{
GetPlayerVelocity(i, velx, vely, velz);
}
else
{
GetVehicleVelocity(vehicleid, velx, vely, velz);
}
speed = floatround(floatpower(floatabs(velx), 2) + floatpower(floatabs(vely), 2) + floatpower(floatabs(velz), 2));
if(!speed)
{
SetPVarInt(i, "AFKTime", GetPVarInt(i, "AFKTime") + 1);
}
#elseif MOVEMENT_TYPE == 2
new
Float:x,Float:y,Float:z;
GetPlayerPos(playerid, x, y, z);
if(x == GetPVarFloat(i, "OldPosX") && y == GetPVarFloat(i, "OldPosY") && z == GetPVarFloat(i, "OldPosZ"))
{
SetPVarInt(i, "AFKTime", GetPVarInt(i, "AFKTime") + 1);
}
SetPVarFloat(i, "OldPosX", x);
SetPVarFloat(i, "OldPosY", y);
SetPVarFloat(i, "OldPosZ", z);
#endif
if(GetPVarInt(i, "AFKTime") >= AFK_TIMES)
{
TogglePlayerControllable(i, 0);
SetPVarInt(i, "IsAFK", 1);
new tempkey[MSG_LENGTH+1];
RandomGenerator(10, tempkey);
SetPVarString(i, "ReturnKey", tempkey);
SendClientMessage(i, COLOR_LIGHTRED, "| Anti-Afk | Vocк estб sem se mover ou falar durante algum tempo, por favor,");
format(string, sizeof(string), "digite isso: \"%s\" , para que possamos saber que ainda estб OnLine.", tempkey);
SendClientMessage(i, COLOR_LIGHTRED, string);
#if AFK_TIMER_TYPE == 1
SetPVarInt(i, "AFKKickTimer", SetTimer("DelayedKick", AFK_DELAYKICK_AMOUNT, true));
#elseif AFK_TIMER_TYPE == 2
SetPVarInt(i, "AFKKickTimer", SetTimer("DelayedKick", (AFK_DELAYKICK_AMOUNT*1000), true));
#elseif AFK_TIMER_TYPE == 3
SetPVarInt(i, "AFKKickTimer", SetTimer("DelayedKick", (AFK_DELAYKICK_AMOUNT*60000), true));
#elseif AFK_TIMER_TYPE == 4
SetPVarInt(i, "AFKKickTimer", SetTimer("DelayedKick", (AFK_DELAYKICK_AMOUNT*3600000), true));
#endif
}
}
return 1;
}
FUNCTION:DelayedKick(playerid)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "| Anti-Afk | Infelizmente vocк nгo digitou o texto a tempo, e foi Kickado.");
Kick(playerid);
return 1;
}
stock RandomGenerator(amount, randomstring[])
{
#if MIXED_CASE == 1
new charset[63] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for(new i = 0; i < amount; i++)
{
randomstring[i] = charset[random(62)];
}
#elseif MIXED_CASE == 0
new charset[37] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for(new i = 0; i < amount; i++)
{
randomstring[i] = charset[random(36)];
}
#endif
return 1;
}
// --- CODE END ---