SA-MP Forums Archive
Randomised string not displaying - 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: Randomised string not displaying (/showthread.php?tid=396980)



Randomised string not displaying - Intoxicated - 02.12.2012

I'm assigning random flightnumbers to aircraft, however, when I try to format the string into a message nothing gets displayed..

Код:
	if(IsAircraft(vehicleid))
	{
		new
			sHold[MAX_FLIGHT_NR+1];
		sHold[0]= RandomLetter();
		sHold[1]= RandomLetter();
	
		for(new i=2; i<MAX_FLIGHT_NR; i++)
		{
			sHold[i]= RandomNumber();
		}
		strpack(vInfo[vehicleid][FlightNR], sHold);
	}
Код:
stock RandomLetter()
{
	new
		Letters[27]= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return Letters[random(26)];
}

stock RandomNumber()
{
	new
		Numbers[11]= "0123456789";
	return Numbers[random(10)];
}
Blank:
Код:
format(sHold, sizeof sHold, "[Radio] #%s: %s", vInfo[iID][FlightNR], params);



Re: Randomised string not displaying - maramizo - 02.12.2012

Shouldn't you set
pawn Код:
vInfo[iID][FlightNR] to RandomNumber()



Re: Randomised string not displaying - Intoxicated - 02.12.2012

No since RandomNumber(); Only returns one number at a time.


Re: Randomised string not displaying - maramizo - 02.12.2012

So you're setting it to:
pawn Код:
for(new i=0;i<sizeof(vInfo[iID][FlightNR]);i++)
{
    new RandomFlight = random(2);
    switch(RandomFlight)
    {
        case 0:
        {
            format(vInfo[iID][FlightNR], sizeof(vInfo[iID][FlightNR]), "%s%s",vInfo[iID][FlightNR],RandomLetter());
        }
        case 1:
        {
            format(vInfo[iID][FlightNR], sizeof(vInfo[iID][FlightNR]), "%s%i",vInfo[iID][FlightNR],RandomNumber());
        }
    }
}
Also note that random(x) returns a MAXIMUM of x-1.


Re: Randomised string not displaying - Intoxicated - 02.12.2012

I think you' re missing the point of what I'm trying to do, the flightID assigned is 8 characters (MAX_FLIGHT_NR)

The first 2/8 characters are randomised letters, the other 6 are random numbers.

EDIT:
Your post did give me a solution though. I was overcomplicating things and I' ve simplified it a bit now. Thanks!


Re: Randomised string not displaying - Intoxicated - 02.12.2012

Update:

format(vInfo[iID][FlightNR], sizeof(vInfo[iID][FlightNR]), "%s%s",vInfo[iID][FlightNR],RandomLetter());

Results in invalid expression


Re: Randomised string not displaying - ReneG - 02.12.2012

Quote:
Originally Posted by Intoxicated
Посмотреть сообщение
Update:

format(vInfo[iID][FlightNR], sizeof(vInfo[iID][FlightNR]), "%s%s",vInfo[iID][FlightNR],RandomLetter());

Results in invalid expression
sizeof is iffy on array elements, try setting it to MAX_FLIGHT_NR.


Re: Randomised string not displaying - Intoxicated - 03.12.2012

Still doesn't work, can someone please find me a way to return a randomised letter and a randomised number?