SA-MP Forums Archive
String length cut-off? - 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: String length cut-off? (/showthread.php?tid=306814)



String length cut-off? - Tee - 28.12.2011

Well since recently I've noticed that on my commands, the string has been cut off. For example, commands that give a reason, like kick, ban, mute, warn, etc. Now the reason string has been cut off for a reason I don't know, I'm wondering if it has anything to do with sscanf 2.0 since I just updated to that.

Yes I've made the reason string bigger and it doesn't work (made it up to 200 cells, instead of the normal 100)
Here's what it looks like:



Chatlog:

Код:
[20:55:07] Tee has been warned by Admin Tee for: Warning test. This is testing t (1 / 3 warnings).
[20:55:07] You have been warned by Admin Tee for: Warning test. This is testing t
Here's what I typed:

Код:
/warn tee Warning test. This is testing the lenght of the string which should be 128 characters and maybe it's not. Test warn...



Re: String length cut-off? - JamesC - 28.12.2011

We can't help you unless you post the command...


Re: String length cut-off? - MP2 - 28.12.2011

You can't show more than 128 (or 127?) characters in a client message. There is no way to get around this. If it's longer, it will not show. You HAVE to cut stuff off when you have user-input strings in the messages. This can be done like so:

pawn Код:
new scm[128];
format(scm, sizeof(scm), "%s warned %s for %s.", blah, blah, blah);
You could set a limit for the reason by using strlen() on both players' names, plus the characters in the string, take that away from 128 and you have the reason limit. Example:

MP2 has warned Tee for 'hacking'.

MP2 = 3
Tee = 3
Rest of string = 20 (+1 null char = 21)

Total = 21+3+3 (27)
Reason limit = 128-(strlen(name1)+strlen(name2)+21) [101]

pawn Код:
if(strlen(reason) > reason_limit) return SendClientMessage(playerid, red, "ERROR: Reason too long.");
Note that color embedding also counts, it will add 8 characters to a string. I recommend not using embedding when user-input strings are used. unless they are going to be short.


Re: String length cut-off? - Scenario - 28.12.2011

Do you use sscanf at all?


Re: String length cut-off? - Tee - 28.12.2011

The problem started when I upgraded to sscanf 2.0. I've never changed my command.
Here's the sscanf line anyway:

pawn Код:
if(sscanf(params,"us", id,rson))return SendClientMessage(playerid, Grey, "Usage: /warn [id] [reason]");
It only sent 33 characters from the reason string of 187 characters.

Again, this is how it was on previous version of sscanf, although I'm not yet sure if that's the problem.


Re: String length cut-off? - Seven_of_Nine - 28.12.2011

There is a limit for characters in 1 line.
When chatting, it automatically splits it into 2 lines. ; )


Re: String length cut-off? - Tee - 28.12.2011

Look at the picture again and you'll see that's not the problem.


Re: String length cut-off? - rinori - 28.12.2011

pawn Код:
#DEFINE MAX_STRING 1024
or
pawn Код:
new string[256]
Check if your MAX strings are set to 1024 or your string created at that command has a small number "256" would be good I think.


Re: String length cut-off? - Seven_of_Nine - 28.12.2011

Well then it's the formatting.


Re: String length cut-off? - Calgon - 28.12.2011

You need to specify a string size when you use 's' in sscanf.

An example of this is:
pawn Код:
new szParams[128], iSomething;
if(sscanf(params, "us[128]",  iSomething, szParams))