How to reget the origin player name
#1

I have a code when the player do /afk he can't move and change is name to xxxx[afk]
but i hava a another code /stopafk but i can't remove the [afk]

there is the code

Код:
COMMAND:afk(playerid, params[])
{
	SendAdminText(playerid, "/afk", params);
	if (APlayerData[playerid][LoggedIn] == false) return 0;
	new Name[24], string[128], AFKName[25];
	TogglePlayerControllable(playerid,0);
	GetPlayerName(playerid, Name, sizeof(Name));
    GetPlayerName(playerid, AFKName, sizeof(AFKName));
 	format(string, sizeof(string),"%s[afk]", AFKName);
    SetPlayerName(playerid, string);
	format(string, sizeof(string),"Le joueur %s c'est mis afk !", Name);
	SendClientMessageToAll(0xFFFFFF, string);
	// message afk
	SendClientMessage(playerid,0xFFFFFFFF, "Vous etes maintenant afk !");
	return 1;
}
COMMAND:stopafk(playerid, params[])
{
	SendAdminText(playerid, "/stopafk", params);
	if (APlayerData[playerid][LoggedIn] == false) return 0;
	new Name[24], string[128], AFKName[25];
	TogglePlayerControllable(playerid,1);
	GetPlayerName(playerid, Name, sizeof(Name));
    GetPlayerName(playerid, AFKName, sizeof(AFKName));
 	format(string, sizeof(string),"%s", AFKName);
    SetPlayerName(playerid, string);
	format(string, sizeof(string),"Le joueur %s est de retour !", Name);
	SendClientMessageToAll(0xFFFFFF, string);
	// message afk
	SendClientMessage(playerid,0xFFFFFFFF, "Vous etes maintenant de retour !");
	return 1;
}
Reply
#2

you have to declare backup string as global like this new Name[MAX_PLAYERS][MAX_PLAYER_NAME]; and then use it the code you provided wont work because it will only work on that certain structure
Edit: or you could use enum that would be better
Reply
#3

Use SetPVarString to temporarily store the player's name before setting the tag when they go AFK.

Something like:

Under your AFK code
PHP код:
SetPVarString(playerid"AFKName"Name); 
And under /stopafk command
PHP код:
new name[24];
GetPVarString(playerid"AFKName"namesizeof(name));
SetPlayerName(playeridname);
DeletePVar(playerid"AFKName"); 
It's better if you use global arrays but PVar is easier to use so.
Reply
#4

PHP код:
// for origin name
new NameOriginAfk[MAX_PLAYERS][MAX_PLAYER_NAME];
// for origin name
COMMAND:afk(playeridparams[])
{
    
SendAdminText(playerid"/afk"params);
    if (
APlayerData[playerid][LoggedIn] == false) return 0;
    new 
Name[24], string[128], AFKName[25];
    
TogglePlayerControllable(playerid,0);
    
GetPlayerName(playeridNamesizeof(Name));
    
GetPlayerName(playeridAFKNamesizeof(AFKName));
     
format(stringsizeof(string),"%s[afk]"AFKName);
    
SetPlayerName(playeridstring);
    
format(stringsizeof(string),"Le joueur %s c'est mis afk !"Name);
    
SendClientMessageToAll(0xFFFFFFstring);
    
// message afk
    
SendClientMessage(playerid,0xFFFFFFFF"Vous etes maintenant afk !");
    return 
1;
}
COMMAND:stopafk(playeridparams[])
{
    
SendAdminText(playerid"/stopafk"params);
    if (
APlayerData[playerid][LoggedIn] == false) return 0;
    new 
Name[24], string[128], AFKName[25];
    
TogglePlayerControllable(playerid,1);
    
GetPlayerName(playeridNamesizeof(Name));
    
GetPlayerName(playeridAFKNamesizeof(AFKName));
     
format(stringsizeof(string),"%s"AFKName);
    
SetPlayerName(playeridNameOriginAfk);
    
format(stringsizeof(string),"Le joueur %s est de retour !"Name);
    
SendClientMessageToAll(0xFFFFFFstring);
    
// message afk
    
SendClientMessage(playerid,0xFFFFFFFF"Vous etes maintenant de retour !");
    return 
1;

like that ? but i getting error

Код:
C:\Users\XXXX\Desktop\Serveur SAMP\gamemodes\XXX.pwn(17982) : error 048: array dimensions do not match
Edit : and when i use your idea Sjn i get somes errors.
Reply
#5

So you want to remove the [afk] tag? strmid to extract characters or set the NULL for the string:
pawn Код:
new AFKName[25];
GetPlayerName(playerid, AFKName, sizeof AFKName);

AFKName[strlen(a) - 5] = EOS;
// or
strmid(AFKName, AFKName, 0, strlen(AFKName) - 5, sizeof AFKName);
Reply
#6

Quote:
Originally Posted by Eymeric69
Посмотреть сообщение
PHP код:
// for origin name
new NameOriginAfk[MAX_PLAYERS][MAX_PLAYER_NAME];
// for origin name
COMMAND:afk(playeridparams[])
{
    
SendAdminText(playerid"/afk"params);
    if (
APlayerData[playerid][LoggedIn] == false) return 0;
    new 
Name[24], string[128], AFKName[25];
    
TogglePlayerControllable(playerid,0);
    
GetPlayerName(playeridNamesizeof(Name));
    
GetPlayerName(playeridAFKNamesizeof(AFKName));
     
format(stringsizeof(string),"%s[afk]"AFKName);
    
SetPlayerName(playeridstring);
    
format(stringsizeof(string),"Le joueur %s c'est mis afk !"Name);
    
SendClientMessageToAll(0xFFFFFFstring);
    
// message afk
    
SendClientMessage(playerid,0xFFFFFFFF"Vous etes maintenant afk !");
    return 
1;
}
COMMAND:stopafk(playeridparams[])
{
    
SendAdminText(playerid"/stopafk"params);
    if (
APlayerData[playerid][LoggedIn] == false) return 0;
    new 
Name[24], string[128], AFKName[25];
    
TogglePlayerControllable(playerid,1);
    
GetPlayerName(playeridNamesizeof(Name));
    
GetPlayerName(playeridAFKNamesizeof(AFKName));
     
format(stringsizeof(string),"%s"AFKName);
    
SetPlayerName(playeridNameOriginAfk);
    
format(stringsizeof(string),"Le joueur %s est de retour !"Name);
    
SendClientMessageToAll(0xFFFFFFstring);
    
// message afk
    
SendClientMessage(playerid,0xFFFFFFFF"Vous etes maintenant de retour !");
    return 
1;

like that ? but i getting error

Код:
C:\Users\XXXX\Desktop\Serveur SAMP\gamemodes\XXX.pwn(17982) : error 048: array dimensions do not match
Edit : and when i use your idea Sjn i get somes errors.
you will get error because you declared it as matrix and then u used it like dimensionless variable
Reply
#7

forget what i said it will ruin your code if u dont do it correctly follow what konstantinos said (it could be made work if u used it as same matrix form in the command structure too )
Reply
#8

To cause you less confusion, I just edited your code.

PHP код:
COMMAND:afk(playeridparams[])
{
       
SendAdminText(playerid"/afk"params);
    if (
APlayerData[playerid][LoggedIn] == false) return 0;
    if (
GetPVarInt(playerid"AFK") == 1)
        return 
SendClientMessage(playerid, -1"You are already AFK!");
    new 
Name[24], string[128];
    
TogglePlayerControllable(playerid,0);
    
GetPlayerName(playeridNamesizeof(Name));
    
SetPVarString(playerid"PreviousName"Name);
    
SetPVarInt(playerid"AFK"1); // To indicate that the player is AFK
    
format(stringsizeof(string), "%s[AFK]"Name);
    
SetPlayerName(playeridstring);
    
format(stringsizeof(string), "Le joueur %s c'est mis afk !"Name);
    
SendClientMessageToAll(-1string);
    
// message afk
    
SendClientMessage(playerid, -1"Vous etes maintenant afk !");
    return 
1;
}
COMMAND:stopafk(playeridparams[])
{
    
SendAdminText(playerid"/stopafk"params);
    if (
APlayerData[playerid][LoggedIn] == false) return 0;
    if (
GetPVarInt(playerid"AFK") == 0)
        return 
SendClientMessage(playerid, -1"You are not AFK!");
    new 
Name[24], string[128];
    
TogglePlayerControllable(playerid1);
    
GetPVarString(playerid"PreviousName"Namesizeof(Name));
    
SetPlayerName(playeridName);
    
format(stringsizeof(string),"Le joueur %s est de retour !"Name);
    
SendClientMessageToAll(-1string);
    
// message afk
    
SendClientMessage(playerid,-1"Vous etes maintenant de retour !");
    
DeletePVar(playerid"PreviousName");
    
SetPVarInt(playerid"AFK"0);
    return 
1;

Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
So you want to remove the [afk] tag? strmid to extract characters or set the NULL for the string:
pawn Код:
new AFKName[25];
GetPlayerName(playerid, AFKName, sizeof AFKName);

AFKName[strlen(a) - 5] = EOS;
// or
strmid(AFKName, AFKName, 0, strlen(AFKName) - 5, sizeof AFKName);
fixed thank you +rep

and you too Sjn
Reply
#10

Another idea for you - attach a 3D text to player's head that says "[AFK]" when player is afk and then the player returns - detach the 3D text? Isn't it easier?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)