name in sendclientmessage
#1

hey so basicaly i want this line to say (playername) Has just stole a couch ! to all players so how would i get this code line to say there name at the start ?
Код:
SendClientMessageToAll(0x33AA33AA, "playersnamehere has just stole a hobo's couch!");
Reply
#2

you would format a string

add this at the top of your couch stealing code

Код:
new pname[24], string[128];
GetPlayerName(playerid, pname, sizeof(pname);
format(string, sizeof(string), "%s has just stole a couch!", pname);
and change your "SendClientMessageToAll", "(player name) has just stole a couch!", change that to string (no quotes

should look like this

Код:
SendClientMessageToAll(<color>, string);
put your color in where <color> is
Reply
#3

hey i get this error with that line
Код:
C:\Documents and Settings\Chris\Desktop\Stunt City\gamemodes\NewServer.pwn(543) : error 001: expected token: ",", but found ";"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Код:
    if (pickupid == skate)
    {
        new pname[24], string[128];
        format(string, sizeof(string), "%s has just stole a hobo's couch!", pname);
        GetPlayerName(playerid, pname, sizeof(pname);
        SendClientMessageToAll(0x33AA33AA, string);
        SendClientMessage(playerid, 0xFFA500AA, "Look on the bright side, you sold the couch on eBay for $400");
        GivePlayerMoney(playerid, 400);
        SetPlayerWantedLevel(playerid, 3);
        GameTextForPlayer(playerid,"Couch Theif",5000,3);

        
    }
line 543 is GetPlayerName(playerid, pname, sizeof(pname);
Reply
#4

Add a ) just before the ;
Reply
#5

hmm it dont say there name it just dose this
Reply
#6

The GetPlayerName should be before the format line i think. If that don't work try this:

pawn Код:
new string[128], adminname[MAX_PLAYER_NAME];
        GetPlayerName(playerid,adminname,sizeof(adminname));
        format(string, sizeof(string), "%s has just stole a hobo's couch!",adminname);
        SendClientMessageToAll(0x33AA33AA, string);

Reply
#7

Look carefully these lines:
pawn Код:
new pname[24], string[128];
format(string, sizeof(string), "%s has just stole a hobo's couch!", pname);
GetPlayerName(playerid, pname, sizeof(pname);
You use GetPlayerName AFTER formatting.. so at the moment format() is called, pname is empty.
Reply
#8

hmm still dosent show the name
Reply
#9

Quote:
Originally Posted by [mad
MLK ]
hmm still dosent show the name
Did you read what he said?

Quote:
Originally Posted by 0rb
Look carefully these lines:
pawn Код:
new pname[24], string[128];
format(string, sizeof(string), "%s has just stole a hobo's couch!", pname);
GetPlayerName(playerid, pname, sizeof(pname);
You use GetPlayerName AFTER formatting.. so at the moment format() is called, pname is empty.
Change the order of the format and the GetPlayername so it looks like this:
pawn Код:
new pname[24], string[128];
GetPlayerName(playerid, pname, sizeof(pname);
format(string, sizeof(string), "%s has just stole a hobo's couch!", pname);

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)