Random location problem
#2

If you need to spawn a gift each time on random unused place, the easiest way is
1. Store all position IDs in one array
2. Shuffle it
3. On each gift spawn iteration use the next item in this array
4. When you reach the end of array just shuffle it again and start over

For example

PHP код:
#define MAX_GIFT_POINTS (10) // Number of points your gifts will be spawned on
new Float:giftPointsMAX_GIFT_POINTS ][3] = { // Gift spawn points (exactly the same number of points as you defined in MAX_GIFT_POINTS )
    
{100.0200.010.0},
    
//...
};
new 
giftPointsKeysMAX_GIFT_POINTS  ]; // We'll store all point array keys here (we'll shuffle this array)
new currentGiftPoint 0// Current gift spawn iteration

// Spawns one gift in a random unused point
// Call this function in timer
public GiftSpawnHandler() {
    if ( 
currentGiftPoint  == ) {
        
// We are now looking on a beginning of the keys array, let's shuffle it
        
new tmp;
        for ( new 
i=0i<MAX_GIFT_POINTS i++ ) {
            for ( new 
i=0i<MAX_GIFT_POINTS i++ ) {
                
tmp giftPointsKeys];
                
giftPointsKeys] = giftPointsKeys];
                
giftPointsKeys] = tmp;
            }
        }
    }
 
    
// Get next array key from suffled array
    
new pointArrayKey giftPointsKeyscurrentGiftPoint ];

    
// Now spawn a gift
    
SpawnNewGiftgiftPointspointArrayKey  ][ ], giftPointspointArrayKey  ][ ], giftPointspointArrayKey  ][ ] );

    
// And increase iteration pointer
    
currentGiftPoint ++;
    if ( 
currentGiftPoint == MAX_GIFT_POINTS  ) {
        
// Reached the end of the array, start over
        
currentGiftPoint 0;
    }

Reply


Messages In This Thread
Random location problem - by IceBilizard - 25.12.2015, 07:58
Re: Random location problem - by prineside - 25.12.2015, 14:54
Re: Random location problem - by xTURBOx - 26.12.2015, 05:23
Re: Random location problem - by IceBilizard - 26.12.2015, 05:49

Forum Jump:


Users browsing this thread: 1 Guest(s)