How to use `Strins`
#1

Hello, I want to make a drug effect based on the function "strins". Can you tell me how I can add some crazy characters in the text written by the player?

Example:
I write "hello, it`s me!", but, on chat appear "Heeqewleo, dsait`s m2qwme!". This is just one example. How can I do this?
Reply
#2

A very hard thing to do, either have predefined list sets of what you will be inserting either at the start of every word, the end, or any random position. You can insert random characters at random positions but make sure you always know the (final) string length.
Reply
#3

You think you can do that? Can you show me an example?
Reply
#4

https://sampwiki.blast.hk/wiki/Strins

That should get you started.
Reply
#5

I do this, but, not working..

Код:
new RandomWords[][] = {
	{"ajm", "utjb", "cjg", "dsae"},
	{"bg", "fb", "ew", "dsf"},
	{",hj", "wr3", "gfr", "mt"},
	{"mgu", "wtm", "vtm", "ef"}
};

OnPlayerText:
new rand = random(sizeof(RandomWords));
strins(text, RandomWords[rand][rand], strlen(text), 4);
format(gString, sizeof(gString), "%s says: %s", GetName(playerid), text);
Reply
#6

Код:
new RandomWords[][] =
{
    "ajm", "utjb", "cjg", "dsae",
    "bg", "fb", "ew", "dsf",
    ",hj", "wr3", "gfr", "mt",
    "mgu", "wtm", "vtm", "ef"
};

//in OnPlayerText:
new rand_w = random(sizeof(RandomWords));
new rand_pos = random(strlen(text)-strlen(RandomWords[rand_w]));
strdel(text, rand_pos, rand_pos+strlen(RandomWords[rand_w]));
strins(text, RandomWords[rand_w], rand_pos, strlen(text));
format(gString, sizeof(gString), "%s says: %s", GetName(playerid), text);
Reply
#7

This example causes a bug in this callback
(Appears "Lunoxx: text", not "Lunoxx says: text", and name is colored with TAB color)
Reply
#8

Код:
new gString[128];
new rand_w = random(sizeof(RandomWords));
new rand_pos = random(strlen(text)-strlen(RandomWords[rand_w]));
if(rand_pos+strlen(RandomWords[rand_w]) > strlen(text))
{
    format(gString, sizeof(gString), "%s says: %s", GetName(playerid), text);
}
else
{
    strdel(text, rand_pos, rand_pos+strlen(RandomWords[rand_w]));
    strins(text, RandomWords[rand_w], rand_pos, strlen(text));
    format(gString, sizeof(gString), "%s says: %s", GetName(playerid), text);
}
//send message...
Reply
#9

You're brilliant! Tell me please how can I make those letters appear several times in the text?



(I gave +rep)
Reply
#10

The reason why I said this is very hard to do is because PAWN has static memory allocation. And for what you are doing you would need some kind of word tokeniser, specifically getting every word save to substrings and using the function posted by Adeon on each word.

Alternatively you could loop N times and run the function to insert at random places, you could add a check to test if the random position is not a space, or some other punctuation mark.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)