SA-MP Forums Archive
Word Scrambling - 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: Word Scrambling (/showthread.php?tid=428701)



Word Scrambling - venomlivno8 - 06.04.2013

Now, is it possible to scramble a word if it is, it should be like this:

i enter the word : "duty"
it gives me back : "uydt"

? Help please.


Re: Word Scrambling - MP2 - 06.04.2013

I'll write this in the next hour if nobody beats me to it


Re: Word Scrambling - Pottus - 06.04.2013

Well since strings are just arrays you can randomize your array pretty easy...

Код:
CMD:randword(playerid, arg[])
{

	RandomizeWord(arg);
	SendClientMessage(playerid, 0xFFFF0000, arg);
	return 1;
}

stock RandomizeWord(word[])
{
    new tmp;
    new r;

    for(new i = strlen(word) - 1; i >= 0; i--)
    {
        r=random(strlen(word));
        tmp = word[i];
	word[i] = word[r];
	word[r] = tmp;
    }
}



Re: Word Scrambling - [ABK]Antonio - 06.04.2013

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Well since strings are just arrays you can randomize your array pretty easy...

Код:
CMD:randword(playerid, arg[])
{

	RandomizeWord(arg);
	SendClientMessage(playerid, 0xFFFF0000, arg);
	return 1;
}

stock RandomizeWord(word[])
{
    new tmp;
    new r;

    for(new i = strlen(word) - 1; i >= 0; i--)
    {
        r=random(strlen(word));
        tmp = word[i];
	word[i] = word[r];
	word[r] = tmp;
    }
}
lol beat me to it, just wrote one out


Re: Word Scrambling - Pottus - 06.04.2013

Lets see your code anyways.


Re: Word Scrambling - MattyG - 06.04.2013

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Well since strings are just arrays you can randomize your array pretty easy...

Код:
CMD:randword(playerid, arg[])
{

	RandomizeWord(arg);
	SendClientMessage(playerid, 0xFFFF0000, arg);
	return 1;
}

stock RandomizeWord(word[])
{
    new tmp;
    new r;

    for(new i = strlen(word) - 1; i >= 0; i--)
    {
        r=random(strlen(word));
        tmp = word[i];
	word[i] = word[r];
	word[r] = tmp;
    }
}
The only problem with that code is that if I randomized a word, say "computer", it could get scrambled as "mputccoo", as it has the possibility of re-using letters


Re: Word Scrambling - [ABK]Antonio - 06.04.2013

pawn Код:
stock Scramble(string[], size=sizeof(string))
{
    new rand, tmp;
    for(new i=0; i < size; ++i) if(string[i] == ' ' || string[i] == '\0') size=i-1;
   
    for(new i=0; i < size; ++i)
    {
        rand=random(size);
        tmp=string[i];
        string[i]=string[rand];
        string[rand]=tmp;
    }
    return 1;
}
Mine's probably not as optimized as yours though, but was making sure was only 1 word gettin scrambled lol


Re: Word Scrambling - Pottus - 06.04.2013

Quote:
Originally Posted by MattyG
Посмотреть сообщение
The only problem with that code is that if I randomized a word, say "computer", it could get scrambled as "mputccoo", as it has the possibility of re-using letters
I don't know what glue stick your sniffing but that can't happen.

Antonio: It is true if there is spaces the spaces will get mixed into the array so each word wouldn't be scrambled in sequence requires an additional stock function


Re: Word Scrambling - venomlivno8 - 06.04.2013

Lock, [uL]Pottus, thanks, I took your code.