Stuck at sscanf (again)
#1

Ok now i'm stuck again. It's about the params that the player write after the command.
pawn Код:
CMD:message(playerid,params[])
{
    //here i want to add the if(sscanf(and something that i dont really have figured out how to make.
    //I want the text the player write after the command to be the string and use that in a format.
    //I know it's easy to create but when i tried to make a code it wont work so i need a little help.
    // this is just a example for the format.
    format(string1,sizeof(string1),the string or the params,string1);
    return 1;
}
My question is if someone can give me a example how to make the params[] into a string and place that in a format. Example as i want the text the player write after the command to show in for example SendClientMessage.
Reply
#2

pawn Код:
CMD:message(playerid,params[])
{
    new messagetext[128], string1[128];
    if(sscanf(params, "s[128]", messagetext)) return SendClientMessage(playerid, -1, "Usage: /message [text]");
    format(string1,sizeof(string1),"%s",messagetext);
    return 1;
}
I'll explain it a bit. The sscanf checks if the params of the command is a string, of which is the messagetext, and if not, it sends a message saying how to use it. If it is, it continues, obviously, and formats it into a string. Thats all I wrote on there, considering you didn't explain what else you wanted in there, such as a playerid or something.

Hope I helped (this should work, didn't test, but no warnings/errors in compile).
Reply
#3

pawn Код:
CMD:message(playerid, params[])
{
    new
        iMessage[70],
        iStr[128];

    if(sscanf(params, "s[70]", iMessage)) return SendClientMessage(playerid, -1, "Usage: /Message Message");

    new iName[24];
    GetPlayerName(playerid, iName, sizeof(iName));

    format(iStr, sizeof(iStr), "Admin: %s - %s", iName, iMessage);
    return SendClientMessageToAll(-1, iStr);
}
Reply
#4

Well this helped alot but for me i dont just need the code, beacouse i want to learn it so what is actually the numbers you write here
pawn Код:
new messagetext[128],string1[128];
I've never understood what the number 128 and all the other numbers people place there is.
Reply
#5

128 is the number of cells available. PAWN uses the NULL terminator, so TECHNICALLY only 127 of those are usable, along with \0 (I think?) ((ASCII code)).

Basically, the higher the number, the more it can hold, but the more memory it takes and the slower it will run.
Reply
#6

Yeh 2KY is right, it represents the cells in that string. So make sure you have the right amount and it is all properly scripted.
Reply
#7

Quote:
Originally Posted by HDFord
Посмотреть сообщение
Well this helped alot but for me i dont just need the code, beacouse i want to learn it so what is actually the numbers you write here
pawn Код:
new messagetext[128],string1[128];
I've never understood what the number 128 and all the other numbers people place there is.
And again, for more than 100 times, I will have to copy and paste this URL: https://sampwiki.blast.hk/wiki/Scripting_Basics

Please, PLEASE, read that before you are going to script, otherwise you have NO idea what you are doing and you will be just making yourself look retarded because of those questions. (Not that you are retarded, just pointing something out)
Reply
#8

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
And again, for more than 100 times, I will have to copy and paste this URL: https://sampwiki.blast.hk/wiki/Scripting_Basics

Please, PLEASE, read that before you are going to script, otherwise you have NO idea what you are doing and you will be just making yourself look retarded because of those questions. (Not that you are retarded, just pointing something out)
Nice one. I've just never figured out what the number was nothing else. And i dont see why i need the scripting basics i've learned most of what i can in scripting from looking at other scripts and is just coming with a few questions about things i dont understand proberbly. The human brain ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)