SA-MP Forums Archive
Fast question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Fast question (/showthread.php?tid=230940)



Fast question - sim_sima - 24.02.2011

Hi guys.
I made a cool function. (/goafk and /back commands).
It works almost perfect, but there is one issue.
Here is what i have made so far:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

    new currentvw; // Gets the current virtual world of the player
    new currentcolor; // Gets the current color of the player
 
    if (strcmp("/goafk", cmdtext, true, 10) == 0)
    {
        currentvw = GetPlayerVirtualWorld(playerid);
        currentcolor = GetPlayerColor(playerid);
        SetPlayerColor(playerid, COLOR_GREY);
        SetPlayerVirtualWorld(playerid, 5);
        TogglePlayerControllable(playerid, 0);
        GameTextForPlayer(playerid, "~r~Afk mode", 10000, 5);
        SendClientMessage(playerid, COLOR_YELLOW, "( ! ) You are now in AFK mode. Type /back to return");
        new name[MAX_PLAYER_NAME], string[44];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "( ! ) %s is now in AFK mode",name);
        SendClientMessageToAll(COLOR_GREY, string);
        return 1;
    }

    if (strcmp("/back", cmdtext, true, 10) == 0)
    {
        SetPlayerColor(playerid, currentcolor);
        SetPlayerVirtualWorld(playerid, currentvw);
        TogglePlayerControllable(playerid, 1);
        GameTextForPlayer(playerid, "Welcome back", 3000, 5);
        new name[MAX_PLAYER_NAME], string[44];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "( ! ) %s is back from AFK mode",name);
        SendClientMessageToAll(COLOR_GREY, string);
        return 1;
    }
    return 0;
}
It works almost perfect. When you type /goafk, you come to virtual world 5. Your keys get disabled, so u cant move around, and your name-color turns grey.
Then when you type /back, you come to the past virtual world again and your keys gets enabled again. I want the name to turn into the color it had before typing /goafk again. I dont understand why this doesnt work, cus it works with the virtual world.
Hope you can help me. Thank you.


Re: Fast question - maramizo - 24.02.2011

Note :
Important Note: GetPlayerColor will return nothing unless SetPlayerColor has been used.
https://sampwiki.blast.hk/wiki/ColorFix


Re: Fast question - sim_sima - 24.02.2011

Quote:
Originally Posted by maramizo
Посмотреть сообщение
Note :
Important Note: GetPlayerColor will return nothing unless SetPlayerColor has been used.
https://sampwiki.blast.hk/wiki/ColorFix
Thank you man! I love you!


Re: Fast question - maramizo - 24.02.2011

Haha np


Re: Fast question - Mean - 24.02.2011

Also, you'll need to save it to a variable.
pawn Код:
new gpColor[ MAX_PLAYERS ];
To save the color
pawn Код:
gpColor[ playerid ] = GetPlayerColor( playerid );
To restore the player's color
pawn Код:
SetPlayerColor( playerid, gpColor[ playerid ] );



Re: Fast question - sim_sima - 24.02.2011

Quote:
Originally Posted by Mean
Посмотреть сообщение
Also, you'll need to save it to a variable.
pawn Код:
new gpColor[ MAX_PLAYERS ];
To save the color
pawn Код:
gpColor[ playerid ] = GetPlayerColor( playerid );
To restore the player's color
pawn Код:
SetPlayerColor( playerid, gpColor[ playerid ] );
Okay. But i did it in another way, and that works. But thank you very much for the help.