Getting two random numbers and putting them together into a variable. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting two random numbers and putting them together into a variable. (
/showthread.php?tid=85827)
Getting two random numbers and putting them together into a variable. -
Kenny990 - 09.07.2009
Код:
if(strcmp(cmd, "/vrn", true) == 0)
{
new VR1 = random(sizeof(vehreglet));
new VR2 = random(sizeof(vehregnum));
new VRF[256];
format(VRF, sizeof(VRF), "%s%s%s%s%s%s%s%s%s",vehreglet[VR1][0],vehregnum[VR2][0],vehreglet[VR1][1],vehregnum[VR2][1],vehreglet[VR1][2],vehregnum[VR2][2],vehreglet[VR1][3],vehregnum[VR2][3],vehreglet[VR1][4]);
MYVARIABLE = VRF;
new string[256];
format(string, sizeof(string), "%s", MYVARIABLE);
SendClientMessage(playerid, COLOR_YELLOW, string);
return 1;
}
VR1 is getting a random array from vehreglet.
VR2 is getting a random array from vehregnum.
Let's say VR1 gets the letter h and VR2 lets the number 9. I want to put those together so they form "h9". And store that in MYVARIABLE. I wanna do this so later I could store it in SQL. Any ideas?
Re: Getting two random numbers and putting them together into a variable. -
Think - 09.07.2009
format(something, sizeof(something), "%s%d", VR1, VR2);
replace something with the desired variable
Re: Getting two random numbers and putting them together into a variable. -
Kenny990 - 09.07.2009
That's a problem because my variable doesn't work like that. If I set MYVARIABLE = SOMETHING, it says, "Array must be indexed." No idea how to work this.
Re: Getting two random numbers and putting them together into a variable. -
Weirdosport - 09.07.2009
You can't store a string (Alphanumeric text) in a variable, it must be stored in a string.
Example:
new Variable; - bad
new String[2] - good
You may need to change the 2 to suit your needs..
Errr, looking at the code, why do you even need MYVARIABLE? What's wrong with VHF?
Re: Getting two random numbers and putting them together into a variable. -
Kenny990 - 09.07.2009
I want to set MYVARIABLE = to VRF, but if I format MYVARIABLE, it doesn't let me. If I set MYVARIABLE = to VRF, still no good
And again, I need MYVARIABLE for SQL storage.