SA-MP Forums Archive
>> Get Player Name Help << [+REP] - 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)
+--- Thread: >> Get Player Name Help << [+REP] (/showthread.php?tid=527163)



>> Get Player Name Help << [+REP] - DarknessKnight - 21.07.2014

Hey guys , im working on a Mechanic job.

pawn Код:
CMD:repair(playerid, params[])
{
    if(Job[playerid] != 7)
        return SendClientMessage(playerid, 0xAFAFAFAA, "You not are Mechanic");

    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "You are not in a car!");

    SendClientMessage(playerid, 0xFF66FFAA," *PLAYERNAME* repaired his vehicle.");
    return 1;
}
*PLAYERNAME* = How i can do that the server will print the player name?
I Saw some stuff with %s but i dont got it.


Re: >> Get Player Name Help << - osman2571 - 21.07.2014

you need use getplayername


Re: >> Get Player Name Help << [+REP] - SPA - 21.07.2014

Код:
CMD:repair(playerid, params[])
{
new pName[MAX_PLAYERS];
GetPlayerName(playerid, pname, sizeof(pName));
 new string[128];
format(string,sizeof(string),"%s repaired his vehicle.",pName(playerid));
SendClientMessageToAll(-1,string);
if(Job[playerid] != 7)
return SendClientMessage(playerid, 0xAFAFAFAA, "You not are Mechanic");
 if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "You are not in a vehicle!");
return 1;
}



Re: >> Get Player Name Help << [+REP] - DarknessKnight - 21.07.2014

Код:
undefined symbol "pName"



Re: >> Get Player Name Help << [+REP] - SPA - 21.07.2014

Код:
CMD:repair(playerid, params[])
{
new string[128];
new pName[MAX_PLAYERS];
GetPlayerName(playerid, pName, sizeof(pName));
format(string,sizeof(string),"%s repaired his vehicle.",pName(playerid));
SendClientMessageToAll(-1,string);
if(Job[playerid] != 7)
return SendClientMessage(playerid, 0xAFAFAFAA, "You not are Mechanic");
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "You are not in a vehicle!");
return 1;
}



Re: >> Get Player Name Help << [+REP] - LivingLikeYouDo - 21.07.2014

Quote:
Originally Posted by SPA
Посмотреть сообщение
Код:
CMD:repair(playerid, params[])
{
new pName[MAX_PLAYERS];
GetPlayerName(playerid, pname, sizeof(pName));
 new string[128];
format(string,sizeof(string),"%s repaired his vehicle.",pName(playerid));
SendClientMessageToAll(-1,string);
if(Job[playerid] != 7)
return SendClientMessage(playerid, 0xAFAFAFAA, "You not are Mechanic");
 if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "You are not in a vehicle!");
return 1;
}
Dat string is useless. Why are you declaring 128 cells for a 50 cells string?
Also, why are you defining the result before the outcomes? Also, for getting name, you use MAX_PLAYER_NAME, which returns a value of 24.

This is better:

Код:
CMD:repair(playerid, params[])
{
    if(Job[playerid] != 7)
        return SendClientMessage(playerid, 0xAFAFAFAA, "You not are Mechanic");

    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "You are not in a vehicle!");

    new name[MAX_PLAYER_NAME + 2], string[50];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "%s repaired his vehicle.", name);
    SendClientMessageToAll(-1, string);
    return 1;
}
@osman2571 : That is the worst example, we are using a temporary new value, and getting name from playername requires opening of file, getting the name, formatting it, and closing the file, which results in slow time.


Re: >> Get Player Name Help << [+REP] - osman2571 - 21.07.2014

find enum pInfo and define pName,


Re: >> Get Player Name Help << [+REP] - SPA - 21.07.2014

This should work:
Код:
CMD:repair(playerid, params[])
{
new string[128];
new pName[MAX_PLAYERS];
GetPlayerName(playerid, pName, sizeof(pName));
format(string,sizeof(string),"%s repaired his vehicle.",pName);
SendClientMessageToAll(-1,string);
if(Job[playerid] != 7)
return SendClientMessage(playerid, 0xAFAFAFAA, "You not are Mechanic");
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "You are not in a vehicle!");
return 1;
}



Re: >> Get Player Name Help << [+REP] - DarknessKnight - 21.07.2014

Quote:
Originally Posted by LivingLikeYouDo
Посмотреть сообщение
Dat string is useless. Why are you declaring 128 cells for a 50 cells string?
Also, why are you defining the result before the outcomes? Also, for getting name, you use MAX_PLAYER_NAME, which returns a value of 24.

This is better:

Код:
CMD:repair(playerid, params[])
{
    if(Job[playerid] != 7)
        return SendClientMessage(playerid, 0xAFAFAFAA, "You not are Mechanic");

    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "You are not in a vehicle!");

    new name[MAX_PLAYER_NAME + 2], string[50];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "%s repaired his vehicle.", name);
    SendClientMessageToAll(-1, string);
    return 1;
}
@osman2571 : That is the worst example, we are using a temporary new value, and getting name from playername requires opening of file, getting the name, formatting it, and closing the file, which results in slow time.
Thanks alot man
+REP


Re: >> Get Player Name Help << [+REP] - LivingLikeYouDo - 21.07.2014

Quote:
Originally Posted by DarknessKnight
Посмотреть сообщение
Thanks alot man
+REP
No problem!