How to use `Strins` -
Lunoxx - 13.02.2016
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?
Re: How to use `Strins` -
Virtual1ty - 13.02.2016
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.
Re: How to use `Strins` -
Lunoxx - 13.02.2016
You think you can do that? Can you show me an example?
Re: How to use `Strins` -
FreAkeD - 13.02.2016
https://sampwiki.blast.hk/wiki/Strins
That should get you started.
Re: How to use `Strins` -
Lunoxx - 13.02.2016
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);
Re: How to use `Strins` -
Adeon - 14.02.2016
Код:
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);
Re: How to use `Strins` -
Lunoxx - 14.02.2016
This example causes a bug in this callback
(Appears "Lunoxx: text", not "Lunoxx
says: text", and name is colored with TAB color)
Re: How to use `Strins` -
Adeon - 14.02.2016
Код:
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...
Re: How to use `Strins` -
Lunoxx - 14.02.2016
You're brilliant! Tell me please how can I make those letters appear several times in the text?
(I gave +rep)
Re: How to use `Strins` -
Virtual1ty - 14.02.2016
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.