Get Player Name? Or?
#1

Well i'm scripting in a simple teleport, but i've got a problem.

When the player teleports to the position given in the script, i want it to send a message to all the people in the server.

So this is what i've done:
Код:
if(strcmp(cmd, "/lsairport", true) == 0) {
		SetPlayerPos(playerid,1984.3177,-2473.2759,13.5469);
		SendClientMessage(playerid, COLOR_BRIGHTRED,"Welcome to Los Santos Airport!");
		SendClientMessageToAll(COLOR_PINK,"%d Has Teleport To LS Airport!");
    return 1;
	}
As you can see i used '%d' just hoping it would give the players name, but no... didn't work like that, so now when ever i type it this comes up:


Anyone know what i need to do/add to that script so the players name will show up instead of all those numbers?

Thanks
Reply
#2

pawn Код:
new string[64];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid,pName,sizeof(pName));
format(string,sizeof(string),"%s has teleported to LS Airport!",pName);
SendClientMessageToAll(COLOR_PINK,string);
Reply
#3

pawn Код:
if(strcmp(cmd, "/lsairport", true) == 0)
{
                new name[MAX_PLAYER_NAME];
                new string[128];
                GetPlayerName(playerid,name,sizeof(name));
                format(string,sizeof(string), "%s Has Teleport To LS Airport!",name);
        SetPlayerPos(playerid,1984.3177,-2473.2759,13.5469);
        SendClientMessage(playerid, COLOR_BRIGHTRED,"Welcome to Los Santos Airport!");
        SendClientMessageToAll(COLOR_PINK,string);
    return 1;
    }
Reply
#4

Edited. Top posters will already help the thread starter.
Reply
#5

Thanks guys, but when ever i try to complie, i get this warning:

Код:
C:\Users\azd\Desktop\samp03bsvr_R2_win32\gamemodes\Fruity10.pwn(251) : warning 219: local variable "string" shadows a variable at a preceding level
Reply
#6

Quote:
Originally Posted by Quest123
Посмотреть сообщение
Thanks guys, but when ever i try to complie, i get this warning:

Код:
C:\Users\azd\Desktop\samp03bsvr_R2_win32\gamemodes\Fruity10.pwn(251) : warning 219: local variable "string" shadows a variable at a preceding level
remove "
Код:
new string
" and just use it as you already did that.
Reply
#7

if(strcmp(cmd, "/lsairport", true) == 0)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string), "%s Has Teleport To LS Airport!",name);
SetPlayerPos(playerid,1984.3177,-2473.2759,13.5469);
SendClientMessage(playerid, COLOR_BRIGHTRED,"Welcome to Los Santos Airport!");
SendClientMessageToAll(COLOR_PINK,string);
return 1;
}

Just delete new string[128];
Reply
#8

Thanks guys for all your help, all working now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)