AFK system
#1

Код:
public AntiAFK(playerid)
{
	new Float:Pos[3];
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		GetPlayerPos(i, Pos[0], Pos[1], Pos[2]);
		if(IsPlayerInRangeOfPoint(i, 2, Pos[0], Pos[1], Pos[2]))
		{
			AFKSeconds[i]++;
		}
		if(AFKSeconds[i] == 600)
		{
			new string[255];
			format(string, sizeof(string), "%s has been kicked by AdmBot for being AFK without sleep for more than 10 minutes", pInfo[playerid][pName]);
			SCMTOALL(COLOR_INDIANRED, string);
		}
	}
	return 1;
}
is any method to make that work only with one timer, beacause this methot will check the pos at 1 second ant it will not check if i am afk because when it's saving my pos is checking if is same position and i don't want that because it will add afkseconds if i'm moving
Reply
#2

I have an afk kick system. Using if player is in same point every time also running it in only one loop will result in returning same position. Its both useless and server tiring to do when you already have the callbacks to do this.

Try to make a timer that does this loop.
Код:
afktime[i]++;
if(afktime[i]==600)
{
    ///do your kicks messages etc.
}
and onplayerupdate and onplayertext and onplayercommandtext* do
Код:
afktime[playerid]=0;
OnPlayerUpdate is called everytime you walk run press a key do what ever literally so he will have his afktime resetted.

OnPlayerText is called everytime you talk so if someone is playing while standing still like maybe inside a car with another player, not calling OnPlayerUpdate in anyway. Then he is probably speaking this will reset his afk time.

OnPlayerCommandText(or that other callback) is called everytime you write a command like "/me". So every time a command is processed you can reset the players afk time.

*(There is another callback if you are using zcmd)
Reply
#3

if i put in onplayerupdate that code it will stay at 0 because i will not move it's still updating, it will not update only if i minimize the game
Reply
#4

It's not working, it's resseting everytime, and i don't move
Reply
#5

Reply
#6

Oh yeah my bad i didn't realise that. My code isn't working properly. Then you have to make it with like

Pos1[3]
Pos2[3]

Then in one timer GetPlayerPosition to pos1 then in another timer do GetPlayerPosition to pos2 then compare the results in second timer and reset the afktime. Checking it through if he moved 2 meters still doesnt seem the best way to do it. I dont think you can take a break for a time to stop loops and do the second one after.

NOTE: You could put two different loops in a timer. I dont know if it would be efficient.
Reply
#7

i fixed. you know what is the max interior id?
Reply
#8

http://weedarr.wikidot.com/interior
Reply
#9

Max interior is 255. SA-MP limits is a good search term.
Reply
#10

I know its too late already, but i removed afktime=0 from OnPlayerUpdate and updated my code to this:
Код:
new Float:xx,Float:xy,Float:xz;
	for(new i=0; i<MAX_PLAYERS; i++)
	{
		GetPlayerPos(i,xx,xy,xz);
		if(USER[i][POS_X]!=xx && USER[i][POS_Y]!=xy && USER[i][POS_Z]!=xz)
		{
			afktime[i]=0;
		}
		else
		{
			afktime[i]++;
		}
		USER[i][POS_X]=xx;
		USER[i][POS_Y]=xy;
		USER[i][POS_Z]=xz;
		if(afktime[i]==150)
		{
			new text[128];
			format(text,sizeof(text),"%s has been kicked for being afk.",GetName(i));
		    SendClientMessageToAll(COLOR_RED,text);
		    SetTimerEx("regkick",500,0,"i",i);
		}
	}
	return 1;
Note that POS_X POS_Y and POS_Z wasnt used before, I used them just for this. And this works with only one timer.

Result:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)