/afk thingy
#1

I got /afk system.
pawn Код:
#include <a_samp>
#if defined FILTERSCRIPT
#endif
new afk[MAX_PLAYERS];
new Float:x;
new Float:y;
new Float:z;
new cage;
new cage1;
new cage2;
new cage3;
new cage4;
new muted[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/afk", cmdtext, true, 10) == 0)
    {
        if (afk[playerid] == 0)
        {
        GetPlayerPos(playerid, x, y, z);
        muted[playerid] = 1;
        SetPlayerHealth(playerid, 100000000000);
        new name[MAX_PLAYER_NAME], string[44];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s is AFK.",name);
        SendClientMessageToAll(0xFFFF00AA, string);
        afk[playerid] = 1;
        SetPlayerPos(playerid, 2261.4995, 1398.8009, 30.1234);
        new Float:xi = 2261.4995;
        new Float:yi = 1398.8009;
        new Float:zi = 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
        {
        SendClientMessage(playerid, 0xFFFF00AA,"You are already AFK!");
        }
        return 1;
    }
   
    if (strcmp("/back", cmdtext, true, 10) == 0)
    {
        if (afk[playerid] == 1)
        {
        SetPlayerHealth(playerid, 100);
        new name[MAX_PLAYER_NAME], string[44];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s is BACK.",name);
        SendClientMessageToAll(0xFFFF00AA, string);
        afk[playerid] = 0;
        SetPlayerPos(playerid, x, y, z);
        DestroyObject(cage);
        DestroyObject(cage1);
        DestroyObject(cage2);
        DestroyObject(cage3);
        DestroyObject(cage4);
        muted[playerid] = 0;
        }
        else
        {
        SendClientMessage(playerid, 0xFFFF00AA, "You arent AFK!");
        }
        return 1;
    }
    return 0;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    afk[playerid] = 0;
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if (muted[playerid] == 1)
    {
        SendClientMessage(playerid, 0xFFFF00AA, "YOU CANNOT TALK WHILE AFK!");
        return 0;
    }
    return 1;
}
How to add [AFK] in front of players name? Like when they do /afk they will appear in player list/and above them, for example [AFK]ColdIce, and when they do /back the AFK thingy goes away
Reply
#2

I haven't tested it out, but it should work.

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;
}
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.
Reply
#3

Quote:
Originally Posted by ColdIce
Посмотреть сообщение
I got /afk system.
pawn Код:
#include <a_samp>
#if defined FILTERSCRIPT
#endif
new afk[MAX_PLAYERS];
new Float:x;
new Float:y;
new Float:z;
new cage;
new cage1;
new cage2;
new cage3;
new cage4;
new muted[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/afk", cmdtext, true, 10) == 0)
    {
        if (afk[playerid] == 0)
        {
        GetPlayerPos(playerid, x, y, z);
        muted[playerid] = 1;
        SetPlayerHealth(playerid, 100000000000);
        new name[MAX_PLAYER_NAME], string[44];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s is AFK.",name);
        SendClientMessageToAll(0xFFFF00AA, string);
        afk[playerid] = 1;
        SetPlayerPos(playerid, 2261.4995, 1398.8009, 30.1234);
        new Float:xi = 2261.4995;
        new Float:yi = 1398.8009;
        new Float:zi = 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
        {
        SendClientMessage(playerid, 0xFFFF00AA,"You are already AFK!");
        }
        return 1;
    }
   
    if (strcmp("/back", cmdtext, true, 10) == 0)
    {
        if (afk[playerid] == 1)
        {
        SetPlayerHealth(playerid, 100);
        new name[MAX_PLAYER_NAME], string[44];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s is BACK.",name);
        SendClientMessageToAll(0xFFFF00AA, string);
        afk[playerid] = 0;
        SetPlayerPos(playerid, x, y, z);
        DestroyObject(cage);
        DestroyObject(cage1);
        DestroyObject(cage2);
        DestroyObject(cage3);
        DestroyObject(cage4);
        muted[playerid] = 0;
        }
        else
        {
        SendClientMessage(playerid, 0xFFFF00AA, "You arent AFK!");
        }
        return 1;
    }
    return 0;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    afk[playerid] = 0;
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if (muted[playerid] == 1)
    {
        SendClientMessage(playerid, 0xFFFF00AA, "YOU CANNOT TALK WHILE AFK!");
        return 0;
    }
    return 1;
}
How to add [AFK] in front of players name? Like when they do /afk they will appear in player list/and above them, for example [AFK]ColdIce, and when they do /back the AFK thingy goes away
just Create a Simple /afk and /back command Which will Announce To All People That %s @PLAYER@ Is Afk. Also Use a Create3dTextlabel, That Will Show that The Player Is Afk.
Also Use a Textdraw instead of Making a Cage, Good Example : /afk "Player Gets Blind" "His Virtual World is 1"
If you use
pawn Код:
Toggleplayercontrollable(playerid,0);
in /afk. and
pawn Код:
Toggleplayercontrollable(playerid,1);
in /back. Than Theres No Use For Admins /Freeze command.

ADVICED :LD
Reply
#4

Quote:
Originally Posted by HP
Посмотреть сообщение
I haven't tested it out, but it should work.

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;
}
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.
string[44],
;
if (afk[playerid] == 0) {


That ; is giving error: error 001: expected token: "-identifier-", but found ";"
Reply
#5

Ahh, sorry. Remove the coma "," after the "string[44]" and it should be fine.
Reply
#6

Ahh works perfectly! Where do I add the /back?
Reply
#7

You can just use /afk for once to set your status as "afk" and use it once again to set your status back to normal. Or if it is necessary to have separate commands like /afk and /back then here's what it should look like:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new
        prevname[MAX_PLAYER_NAME],
        name[MAX_PLAYER_NAME],
        string[44]
    ;
    if (strcmp("/afk", cmdtext, true, 10) == 0) {
        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);
        }
        return 1;
    }
    if (strcmp("/back", cmdtext, true, 10) == 0)
    {
        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 suggest you to use some kind of command processor like y_commands or zcmd, as they are much faster, simply because they are called directly as a function and they are a lot more user friendly compared to regular commands.
Reply
#8

There is something wrong here. /back does not work and the server restarts and asks me to register again because my nick is AFKNICK
Reply
#9

I should have usen strdel in the first place, as I believe it's more efficient.
"strdel(name, 0, 5);" just deletes the characters started from 0 and ending with 5 in the string, which in this case are "[AFK]" and then we can simply set the player's name.

This works perfectly anyway:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new
        name[MAX_PLAYER_NAME],
        string[44]
        ;
    if (strcmp("/afk", cmdtext, true, 10) == 0) {
        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);
            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 {
            SendClientMessage(playerid, 0xFFFF00AA,"You are already AFK!");
        }
        return 1;
    }

    if (strcmp("/back", cmdtext, true, 10) == 0) {
        if (afk[playerid] == 1) {
            SetPlayerHealth(playerid, 100);
            GetPlayerName(playerid, name, sizeof(name));
            strdel(name, 0, 5);
            format(string, sizeof(string), "%s is BACK.",name);
            SendClientMessageToAll(0xFFFF00AA, string);
            SetPlayerName(playerid, name);
            afk[playerid] = 0;
            SetPlayerPos(playerid, x, y, z);
            DestroyObject(cage);
            DestroyObject(cage1);
            DestroyObject(cage2);
            DestroyObject(cage3);
            DestroyObject(cage4);
            muted[playerid] = 0;
        }
        else {
            SendClientMessage(playerid, 0xFFFF00AA, "You arent AFK!");
        }
        return 1;
    }
    return 0;
}
Edit: Keep in mind that you have to set player's name back to normal, when they disconnect (in case your username saves or if it checks for the username while saving).

To do that, simply add this to OnPlayerDisconnect:
pawn Код:
if (afk[playerid] == 1) {
        new
            name[MAX_PLAYER_NAME]
        ;
    GetPlayerName(playerid, name, sizeof(name));
    strdel(name, 0, 5);
    SetPlayerName(playerid, name);
    return 1;
}
Reply
#10

Because prevname is a variable and won't save, you should use PVars for that...
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)