Anti afk abuse
#1

Ok i want to add a code to my /afk command that when the player /afk it checks if they were recently taking damage and if they were recently taking damage and they tried to do /afk it would send them a message saying you would have to wait like 60seconds before using this command. How would i execute this?

pawn Код:
//My afk coding
CMD:afk(playerid,params[])
{
    if( pInfo[playerid][Spawned]    != 1)
    {
        ShowMessage(playerid, red, 9);
        return 1;
    }
    if(InEvent[playerid] == 1)
    {
        ShowMessage(playerid, red, 11);
    }
    if(Afk[playerid] == 1)
    {
        SendClientMessage(playerid,red,"You are already /afk. Use the /back command to return to playing the game." );
    }
    else
    {
        Afk[playerid] = 1;
        GetPlayerHealth(playerid, afkH[playerid]);
        TogglePlayerControllable(playerid,0);
        GetPlayerArmour(playerid, afkA[playerid]);
        SetPlayerHealth(playerid,300000);
        SetPlayerArmour(playerid,100000);
        GetPlayerName(playerid, afkname, sizeof(afkname));
        format(afkstring,sizeof(afkstring),"[AFK]%s",afkname);
        SetPlayerName(playerid, afkstring);
        SendClientMessage(playerid,red,"Your Status is now set to AFK. (You have 5mins or get kick)");
    }
    return 1;
}
Reply
#2

hello, below i have added you 60 seconds for a player needs to wait to go afk again.
Код:
CMD:afk(playerid,params[])
{
   new afkcount;
  if(GetTickCount() - afkcount < (60000)) return SendClientMessage(playerid, -1, "You need to wait 60 seconds before using this command again");
	if( pInfo[playerid][Spawned]    != 1)
	{
        ShowMessage(playerid, red, 9);
		return 1;
	}
	if(InEvent[playerid] == 1)
	{
	    ShowMessage(playerid, red, 11);
	}
	if(Afk[playerid] == 1)
	{
	    SendClientMessage(playerid,red,"You are already /afk. Use the /back command to return to playing the game." );
	}
	else
 	{
		Afk[playerid] = 1;
      afkcount = GetTickCount();
    	GetPlayerHealth(playerid, afkH[playerid]);
		TogglePlayerControllable(playerid,0);
    	GetPlayerArmour(playerid, afkA[playerid]);
		SetPlayerHealth(playerid,300000);
    	SetPlayerArmour(playerid,100000);
   	GetPlayerName(playerid, afkname, sizeof(afkname));
      format(afkstring,sizeof(afkstring),"[AFK]%s",afkname);
      SetPlayerName(playerid, afkstring);
      SendClientMessage(playerid,red,"Your Status is now set to AFK. (You have 5mins or get kick)");
	}
    return 1;
}
Reply
#3

Quote:
Originally Posted by ThatFag
Посмотреть сообщение
hello, below i have added you 60 seconds for a player needs to wait to go afk again.
Код:
CMD:afk(playerid,params[])
{
   new afkcount;
  if(GetTickCount() - afkcount < (60000)) return SendClientMessage(playerid, -1, "You need to wait 60 seconds before using this command again");
	if( pInfo[playerid][Spawned]    != 1)
	{
        ShowMessage(playerid, red, 9);
		return 1;
	}
	if(InEvent[playerid] == 1)
	{
	    ShowMessage(playerid, red, 11);
	}
	if(Afk[playerid] == 1)
	{
	    SendClientMessage(playerid,red,"You are already /afk. Use the /back command to return to playing the game." );
	}
	else
 	{
		Afk[playerid] = 1;
      afkcount = GetTickCount();
    	GetPlayerHealth(playerid, afkH[playerid]);
		TogglePlayerControllable(playerid,0);
    	GetPlayerArmour(playerid, afkA[playerid]);
		SetPlayerHealth(playerid,300000);
    	SetPlayerArmour(playerid,100000);
   	GetPlayerName(playerid, afkname, sizeof(afkname));
      format(afkstring,sizeof(afkstring),"[AFK]%s",afkname);
      SetPlayerName(playerid, afkstring);
      SendClientMessage(playerid,red,"Your Status is now set to AFK. (You have 5mins or get kick)");
	}
    return 1;
}
Thats not what i want, i want it to be if the player was shot or damage they have to wait 60seconds before they can heal or go on afk
Reply
#4

Put
Код:
 afkcount = GetTickCount();
under
Код:
 
public OnPlayerTakeDamage(playerid, damagedid, Float:amount, weaponid)
* this will start counting 60 seconds before the player heal or go afk again

also put this next to where you define the "AFK[MAX_PLAYERS]" or idk how u call it
remove it from this cmd
Код:
new afkcount;
Reply
#5

Player takes damage in OnPlayerTakeDamage. You could also technically use OnPlayerGiveDamage.

If the player was damaged by another player, update their 'last damaged' variable to the current timestamp.

PHP код:
if((gettime() - variable[playerid]) < duration// Player has not waited long enough 
Example:
PHP код:
OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart)
{
    if(
issuerid != INVALID_PLAYER_ID && issuerid != playerid// The player was damaged by another player
    
{
        
SetPVarInt(playerid"LastDamaged"gettime());
    }
    return 
1;
}
CMD:afk(playeridparams[])
{
    if((
gettime() - GetPVarInt(playerid"LastDamaged")) < 60) return SendClientMessage(playerid, -1"You have been damaged recently, you can't use this command.");
    
// Rest of command...

https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
https://sampwiki.blast.hk/wiki/OnPlayerGiveDamage
https://sampwiki.blast.hk/wiki/Gettime
https://sampwiki.blast.hk/wiki/GetTickCount
Reply
#6

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Player takes damage in OnPlayerTakeDamage. You could also technically use OnPlayerGiveDamage.

If the player was damaged by another player, update their 'last damaged' variable to the current timestamp.

PHP код:
if((gettime() - variable[playerid]) < duration// Player has not waited long enough 
Example:
PHP код:
OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart)
{
    if(
issuerid != INVALID_PLAYER_ID && issuerid != playerid// The player was damaged by another player
    
{
        
SetPVarInt(playerid"LastDamaged"gettime());
    }
    return 
1;
}
CMD:afk(playeridparams[])
{
    if((
gettime() - GetPVarInt(playerid"LastDamaged")) < 60) return SendClientMessage(playerid, -1"You have been damaged recently, you can't use this command.");
    
// Rest of command...

https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
https://sampwiki.blast.hk/wiki/OnPlayerGiveDamage
https://sampwiki.blast.hk/wiki/Gettime
https://sampwiki.blast.hk/wiki/GetTickCount
I end up using your code, now i want when the player respawn he will be able to use this command.

how would i do that

pawn Код:
// would it be
 SetPVarInt(playerid, "LastDamaged", 0);
Reply
#7

SOLVED
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)