11.06.2011, 17:52
I haven't tested it out, but it should work.
Basically, what it does is, that it get's player name, saves it as "prevname" (short from previous name) and sets player name to "[AFK](and string for GetPlayerName here)" after the player re-enter's the command it sets player's name back to what it was before (prevname).
I also made it to a single command, but you can always make it back to 2 commands. I also modified it a bit from here and there, to make it look better.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/afk", cmdtext, true, 10) == 0) {
new
prevname[MAX_PLAYER_NAME],
name[MAX_PLAYER_NAME],
string[44],
;
if (afk[playerid] == 0) {
new Float:xi = 2261.4995;
new Float:yi = 1398.8009;
new Float:zi = 30.1234;
GetPlayerPos(playerid, x, y, z);
muted[playerid] = 1;
SetPlayerHealth(playerid, 100000000000);
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s is AFK.",name);
SendClientMessageToAll(0xFFFF00AA, string);
prevname = name;
format(string, sizeof(string), "[AFK]%s", name);
SetPlayerName(playerid, string);
afk[playerid] = 1;
SetPlayerPos(playerid, 2261.4995, 1398.8009, 30.1234);
cage = CreateObject(985, xi, yi+4, zi, 0.0, 0.0, 0.0);
cage2 = CreateObject(985, xi+4, yi, zi, 0.0, 0.0, 90.0);
cage3 = CreateObject(985, xi-4, yi, zi, 0.0, 0.0, 270.0);
cage4 = CreateObject(985, xi, yi-4, zi, 0.0, 0.0, 180.0);
}
else if (afk[playerid] == 1) {
SetPlayerHealth(playerid, 100);
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s is BACK.",name);
SendClientMessageToAll(0xFFFF00AA, string);
SetPlayerName(playerid, prevname);
afk[playerid] = 0;
SetPlayerPos(playerid, x, y, z);
DestroyObject(cage);
DestroyObject(cage1);
DestroyObject(cage2);
DestroyObject(cage3);
DestroyObject(cage4);
muted[playerid] = 0;
}
return 1;
}
return 0;
}
I also made it to a single command, but you can always make it back to 2 commands. I also modified it a bit from here and there, to make it look better.