ID:269225
 
How would I limit the amount of characters a player can "say"?
Use length() or lentext().
In response to DeathAwaitsU
Aight, thanks
Another effective way to do this is with the copytext() procedure. Here's an example:

mob/verb/say(t as text)
var
saytext
addendum
if(length(t)>80)
saytext = copytext(t,1,81)
addendum = copytext(t,81,0)
else
saytext = t
addendum = null
if(addendum)
for(var/mob/M In world)
if(M==src)
M << "[src.name]: [saytext] ([addendum])"
M << "Text was cut off because of its length."
else
M << "[src.name]: [saytext]"
else
world << "[src]: [saytext]"


That way, flooders will mostly flood themselves and people who accidentally type too long of a message will be able to copy-paste the rest of their message into subsequent say() verbs.

If your game has a spam count that triggers based on the number of calls to say() per period of time, one effective way to limit flooders but not legitimate chatters is to break messages up into multiple segments, like so:

mob/verb/say(t as text)
if(length(t)<=80) world << "[src]: [t]"
else
world << "[src]: [copytext(t,1,81)]"
say(copytext(t,81,0))


That recursive procedure will call a different say() for each 80 characters the user inputs, allowing your spam catcher to notice floods of text. However, normal chatters will only end up breaking their text on an occasion.
In response to PirateHead
PirateHead wrote:
Another effective way to do this is with the copytext() procedure. Here's an example:

> mob/verb/say(t as text)
> var
> saytext
> addendum
> if(length(t)>80)
> saytext = copytext(t,1,81)
> addendum = copytext(t,81,0)
> else
> saytext = t
> addendum = null
> if(addendum)
> for(var/mob/M In world)
> if(M==src)
> M << "[src.name]: [saytext] ([addendum])"
> M << "Text was cut off because of its length."
> else
> M << "[src.name]: [saytext]"
> else
> world << "[src]: [saytext]"

That way, flooders will mostly flood themselves and people who accidentally type too long of a message will be able to copy-paste the rest of their message into subsequent say() verbs.

If your game has a spam count that triggers based on the number of calls to say() per period of time, one effective way to limit flooders but not legitimate chatters is to break messages up into multiple segments, like so:

> mob/verb/say(t as text)
> if(length(t)<=80) world << "[src]: [t]"
> else
> world << "[src]: [copytext(t,1,81)]"
> say(copytext(t,81,0))

That recursive procedure will call a different say() for each 80 characters the user inputs, allowing your spam catcher to notice floods of text. However, normal chatters will only end up breaking their text on an occasion.

Or, a slightly shorter method:
world<<"[src.name]: [length(T)>81 ? copytext(T,1,81) : T]"
In response to Teh Governator
Teh Governator wrote:
Or, a slightly shorter method:
> world<<"[src.name]: [length(T)>81 ? copytext(T,1,81) : T]"
>


That snippet doesn't work the same way the PirateHead's does, Governator. It may be shorter, but it doesn't work as it's supposed to.
In response to PirateHead
80 characters is kind of an arbitrary choice given that BYOND doesn't use DOS's text mode. It's also a really poor choice because anything worth saying is usually going to be longer than that. A better limit would be 400 or even higher. Most developers have discovered that 256, a more common arbitrary choice, is too low.

Lummox JR
In response to Lummox JR
This is the first time I've written a MUD for anything but DOS. However, just to play devil's advocate, I find that once you are typing a few hundred characters the "say" command is less applicable than the "narrate" command.

In any case, to the codesmith in distress, don't let this discussion confuse you. The idea is that you can limit text to any arbitrary amount. Alternately, you can limit it to a number of words or even a number of sentences, depending on the average length of messages to chat.
In response to DeathAwaitsU
DeathAwaitsU wrote:
Use length() or lentext().

Don't use lentext(). It's been deprecated in favor of the length() proc, which not only returns the same value that lentext() would on a text string, but can also be used to get the length of other types of data, like savefiles. There is no garuntee that lentext() will even be supported in the future, so it's best to not use it at all.

~X