Randomising Arrays

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
MrChef2233
Posts: 30
Joined: Sun Apr 10, 2011 11:35 pm
Location: Sydney, AUS

Randomising Arrays

Post 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
User avatar
solarsnowfall
Posts: 1581
Joined: Thu Jun 30, 2005 1:44 am

Re: Randomising Arrays

Post 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.
Locked

Return to “Editing (Archive)”