Raised This Month: $ Target: $400
 0% 

Solved choosing only "x" number of origin to spawn


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-11-2020 , 08:11   Re: choosing only "x" number of origin to spawn
Reply With Quote #2

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][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[count], 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];         copy(szDesc[count], charsmax(szDesc[]), szDesc[rand2]);         vOrigin[rand2][0] = vOrigin[rand1][0];         vOrigin[rand2][1] = vOrigin[rand1][1];         vOrigin[rand2][2] = vOrigin[rand1][2];         copy(szDesc[rand2], charsmax(szDesc[]), szDesc[rand1]);         vOrigin[rand1][0] = vOrigin[count][0];         vOrigin[rand1][1] = vOrigin[count][1];         vOrigin[rand1][2] = vOrigin[count][2];         copy(szDesc[rand1], charsmax(szDesc[]), szDesc[count]);     }         for ( new i ; i < 6 /* or pcvar */ ; i++ )         spawn_testing(vOrigin[i], szDesc)
or
Code:
    new x[16], y[16], z[16], szDesc[32][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[count], 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 & (1<<temp) )         spawn_testing(vOrigin[temp], szDesc[temp])         vOriginUsed |= (1<<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; //...
__________________

Last edited by Black Rose; 06-15-2020 at 12:41.
Black Rose is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode