Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
|
06-11-2020
, 08:21
Re: choosing only "x" number of origin to spawn
|
#3
|
Quote:
Originally Posted by Black Rose
You buffer and randomize.
Code:
new x[16], y[16], z[16], szDesc[32], szData[charsmax(x) + charsmax(y) + charsmax(z) + charsmax(szDesc)]
new Float:vOrigin[3]
while(!feof(iFile))
{
fgets(iFile, szData, charsmax(szData))
trim(szData)
if(!szData[0]) continue;
parse(szData, x, 15, y, 15, z, 15, szDesc, 31)
vOrigin[0] = str_to_float(x)
vOrigin[1] = str_to_float(y)
vOrigin[2] = str_to_float(z)
spawn_testing(vOrigin, szDesc)
}
->
Code:
new x[16], y[16], z[16], szDesc[32], szData[charsmax(x) + charsmax(y) + charsmax(z) + charsmax(szDesc)];
new Float:vOrigin[32][3], count;
while(!feof(iFile))
{
fgets(iFile, szData, charsmax(szData));
trim(szData);
if(!szData[0]) continue;
parse(szData, x, 15, y, 15, z, 15, szDesc, 31);
vOrigin[count][0] = str_to_float(x);
vOrigin[count][1] = str_to_float(y);
vOrigin[count][2] = str_to_float(z);
count++;
}
for ( new i, rand1, rand2 ; i < 100 ; i++ ) {
rand1 = random(count);
rand2 = random(count);
vOrigin[count][0] = vOrigin[rand2][0];
vOrigin[count][1] = vOrigin[rand2][1];
vOrigin[count][2] = vOrigin[rand2][2];
vOrigin[rand2][0] = vOrigin[rand1][0];
vOrigin[rand2][1] = vOrigin[rand1][1];
vOrigin[rand2][2] = vOrigin[rand1][2];
vOrigin[rand1][0] = vOrigin[count][0];
vOrigin[rand1][1] = vOrigin[count][1];
vOrigin[rand1][2] = vOrigin[count][2];
}
for ( new i ; i < 6 /* or pcvar */ ; i++ )
spawn_testing(vOrigin[i], szDesc)
or
Code:
new x[16], y[16], z[16], szDesc[32], szData[charsmax(x) + charsmax(y) + charsmax(z) + charsmax(szDesc)];
new Float:vOrigin[32][3], count;
while(!feof(iFile))
{
fgets(iFile, szData, charsmax(szData));
trim(szData);
if(!szData[0]) continue;
parse(szData, x, 15, y, 15, z, 15, szDesc, 31);
vOrigin[count][0] = str_to_float(x);
vOrigin[count][1] = str_to_float(y);
vOrigin[count][2] = str_to_float(z);
count++;
}
new vOriginUsed;
for ( new i, temp ; i < 6 /* or pcvar */ ; i++ ) {
do {
temp = random(count);
}
while ( vOriginUsed & temp )
spawn_testing(vOrigin[temp][i], szDesc)
vOriginUsed |= temp;
}
If you want it dynamic and editable by the end user don't forget to check that there are more locations than requested spawns.
Code:
new pcvar = get_pcvar_num(...);
if ( pcvar > count )
pcvar = count;
//...
|
thank you @BLACK ROSE , i will test it
__________________
SED LYF !!!
|
|