>> Get Player Name Help << [+REP]
#1

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.
Reply
#2

you need use getplayername
Reply
#3

Код:
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;
}
Reply
#4

Код:
undefined symbol "pName"
Reply
#5

Код:
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;
}
Reply
#6

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.
Reply
#7

find enum pInfo and define pName,
Reply
#8

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

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
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)