Page 1 of 1

Randomising Arrays

Posted: Sat Apr 30, 2011 5:04 pm
by MrChef2233
Hi again. Just a question, how would you randomise an array that spawns weapons. Eg here is the array
int randomweapons[22] = { "DoubleBladedChainsaw", "Enforcer", "SMG", "Shotgun", "SuperShotgun", "Drummle", "HunterShotgun", "Chaingun", "AK47", "Autogun", "MP40", "RocketLauncher", "UberMinigun", "PlasmaRifle", "40MMGrenadeLauncher", "Channeler", "NuclearMissileLauncher", "BFG9000", "SniperRifle", "UTNTFlamethrower", "STBFG10K" };
Now how would I spawn them randomly? I'm trying to create a mystery box effect just like in WAW Zombies so please give me some info. Thanks

Re: Randomising Arrays

Posted: Sun May 01, 2011 2:04 am
by solarsnowfall

Code: Select all

#define NUM_WEAPS 22
#define SPAWN_FOG TRUE

str weapons[NUM_WEAPS] = { 
    "DoubleBladedChainsaw", 
    "Enforcer", 
    "SMG", 
    "Shotgun", 
    "SuperShotgun", 
    "Drummle", 
    "HunterShotgun", 
    "Chaingun", 
    "AK47", 
    "Autogun", 
    "MP40", 
    "RocketLauncher", 
    "UberMinigun", 
    "PlasmaRifle", 
    "40MMGrenadeLauncher", 
    "Channeler", 
    "NuclearMissileLauncher", 
    "BFG9000", 
    "SniperRifle", 
    "UTNTFlamethrower", 
    "STBFG10K"
};

script 1 (int spot_tid, int new_tid, int angle)
{
    int n = random(0, NUM_WEAPS - 1);
    
    if (SpawnSpot(weapons[n], spot_tid, new_tid, angle) && SPAWN_FOG)
    {
        SpawnSpot("TeleportFog", spot_tid, 0, 0);
    }
}
Then call script 1 with your arguments.