Using the same variable twice in a string
#1

I'm trying to make an admin chat for a test gamemode I'm making, I just started learning how to code pawno about 10 hours ago and I've had help from a few advanced friends. I'm trying to store the player's name and what they typed both as the variable of %s, using it twice. The player's name is correctly displayed but their message is show as y. Included below is the code.

Код:
CMD:achat(playerid,params[])
{
	
	new admins[MAX_PLAYERS];
	#define admin 0
	new name[MAX_PLAYER_NAME+1], string[70];
	new text[128];
	if(IsPlayerAdmin(playerid))
	{
	    if(sscanf(params, "uu", text)) return SendClientMessage(playerid,COL_WHITE,"[USAGE]: /achat [message]");
	    admins[playerid] = admin;
	    GetPlayerName(playerid,name,sizeof(name));
	    format(string, sizeof(string), "(( %s: %s ))", name, text);
	    SendClientMessage(admin,COL_YELLOW,string);
	}
	else
	{
	    if(sscanf(params, "uu", text)) return SendClientMessage(playerid,COL_WHITE,"[ERROR]: You do not have access to this command!");
	}
	
	return 1;
}
Reply
#2

Why did you do "uu" on the sscanf line? u is for the player name/id and it should be "s" for string.

Read a bit more about sscanf its going to help you trust me
https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#3

You have to add the size. You can't just type in "s". It has to be "s[String size]". Ex: s[24].
Reply
#4

Quote:
Originally Posted by gtakillerIV
Посмотреть сообщение
You have to add the size. You can't just type in "s". It has to be "s[String size]". Ex: s[24].
You dont have to.
Reply
#5

128 Will probably be a little small also. Text will be cut
Reply
#6

pawn Код:
CMD:achat(playerid,params[])
{

    new text[250], pname[24], str[150];
    GetPlayerName(playerid, pname, 24);
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be an rcon admin to use this command.!");
    if(sscanf(params("s[250]", text)) return SendClientMessage(playerid, -1, "USAGE: /achat [ text ]");
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerAdmin(i))
        {
            format(str, 150, "A.Chat: %s[%i]: %s", pname, playerid, text);
            SendClientMessage(i, -1, str);
        }
    }
    return 1;
}
I think this would work, didn't test xd
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)