Using the same variable twice in a string - 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: Using the same variable twice in a string (
/showthread.php?tid=458449)
Using the same variable twice in a string -
FireShooter10 - 16.08.2013
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;
}
Re: Using the same variable twice in a string -
Edix - 16.08.2013
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
Re: Using the same variable twice in a string -
gtakillerIV - 16.08.2013
You have to add the size. You can't just type in "s". It has to be "s[String size]". Ex: s[24].
Re: Using the same variable twice in a string -
Edix - 16.08.2013
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.
Re: Using the same variable twice in a string -
andruz99 - 17.08.2013
128 Will probably be a little small also. Text will be cut
Respuesta: Using the same variable twice in a string -
Strier - 17.08.2013
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