Randomize a word from a list - 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: Randomize a word from a list (
/showthread.php?tid=603095)
Randomize a word from a list -
AidanRO - 18.03.2016
Hello everybody, today I want to make something releated to my car system (again) and the mode you steal one.
Shortly, I want to take a word from a list and randomize it. Example: The word "kitchen" gets selected and the script may transform it in "nehcikt" or something.
The code I use for my list:
pawn Код:
new RandomNames[][4] =
{
"couch",
"ignition",
"kitchen"
};
Re: Randomize a word from a list -
DRIFT_HUNTER - 18.03.2016
https://sampforum.blast.hk/showthread.php?tid=535186
Re: Randomize a word from a list -
AidanRO - 18.03.2016
Quote:
Originally Posted by DRIFT_HUNTER
|
I already tried that method but I have some errors when I try to use it with a command or anything.
Re: Randomize a word from a list -
AidanRO - 19.03.2016
Can be closed. Solved other way.
Re: Randomize a word from a list -
SickAttack - 20.03.2016
Quote:
Originally Posted by AidanRO
Can be closed. Solved other way.
|
You should have posted the function. Anyway, here:
pawn Код:
// ** INCLUDES
#include <a_samp>
// ** DEFINES
// *** FUNCTIONS
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
// ** MAIN
main()
{
print("Loaded \"mix_up_characters_in_string.amx\".");
printf("%s", MixUpCharactersInString("testing"));
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** FUNCTIONS
stock MixUpCharactersInString(string[])
{
new new_string[128], temp[2];
strcpy(new_string, string, 128);
for(new i = 0, j = strlen(string); i < j; i ++)
{
temp[0] = string[i];
temp[1] = random(j);
new_string[i] = string[temp[1]];
new_string[temp[1]] = temp[0];
}
return new_string;
}
Outputs:
Код:
nginste
eggnsts
tninngn
niggens,
etc.
P.S. The 4th output, though! If the 6th character was an "r", it would say "niggers". Hahahaha! PAWN is such a racist!