Randomly Selecting From a List

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.
User avatar
Slasher
Posts: 1160
Joined: Sun Mar 16, 2008 11:17 pm
Location: California

Re: Randomly Selecting From a List

Post by Slasher »

Hmm, I wasn't aware of that Changelevel() command. I was trying with Teleport_NewMap(), which worked in the script I had created, but when using an UNLOADING script, it would process the random map selection and go to that map, then be immediately sent to the next map as if being executed by Exit_Normal().

It didn't work so I figured it couldn't be done. Isle's solution looks like it would work. Legend, I'd recommend you try that.
User avatar
Legend
Posts: 158
Joined: Fri Jun 11, 2010 12:32 am
Location: Antioch, CA

Re: Randomly Selecting From a List

Post by Legend »

just a small problem of seeing the next map for a frame though.
Not sure what you mean by that exactly.

By the looks of the code, it says changelevel_nointermission. Does that mean that the intermission screen will not be shown? Is there a way to keep it?
User avatar
Legend
Posts: 158
Joined: Fri Jun 11, 2010 12:32 am
Location: Antioch, CA

Re: Randomly Selecting From a List

Post by Legend »

Isle wrote:if you want a random map you could change it when the next one loads. just use a global to make sure you don't keep changing levels. IE:

Code: Select all

global int 1:loaded;

int levels[5] = {"map01", "map02", "map03", "map04", "map05"};

script 1 OPEN
{
	if(!loaded)
	{
		loaded	= 1;
		changelevel(levels[random(0, 4)], 0, CHANGELEVEL_NOINTERMISSION);
	}
	else loaded = 0;
}
just a small problem of seeing the next map for a frame though.
So, would I put this in a library and use the load acs script? And put all the maps in an array?

I'm not sure how to combine the above with:

Code: Select all

Code: Select all • Expand view
    global int 0:list[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    #define last 19; // this will be used later on

    global int 1:max = 19; // (size of array - 1)

    Script 1 ENTER
    {
    int choice;
    int rand;
    rand = Random(0,max); // The array element chosen
    choice = list[rand];  // The value in that element

    int temp;
    temp = list[rand];
    list[rand] = list[last]; // this is where we need the "last" variable.
    list[last] = temp;       // it represents the last element of the full sized array
    max--;

    Teleport_NewMap (choice, 0, 0); // Sends the player to the chosen map.
    }


    Script 2 RETURN
    {

    TakeInventory();
    GiveInventory("Pistol",1);
    GiveInventory("Clip",50);
    GiveInventory("Fist",1);

    int choice;
    int rand;
    rand = Random(0,max); // The array element chosen
    choice = list[rand];  // The value in that element

    int temp;
    temp = list[rand];
    list[rand] = list[last]; // this is where we need the "last" variable.
    list[last] = temp;       // it represents the last element of the full sized array
    max--;

    Teleport_NewMap (choice, 0, 0); // Sends the player to the chosen map.
    }
Which part would I replace?
User avatar
Zippy
Posts: 3302
Joined: Wed Mar 23, 2005 5:31 pm
Location: New Jersey

Re: Randomly Selecting From a List

Post by Zippy »

Legend wrote:Not sure what you mean by that exactly.
The way Isle's method works is not changing the map right before you EXIT a level but changing the map just after you ENTER a new one. In other words, for a brief frame you'll see the first map load before it redirects and loads the actual map you want. That's why the no intermission. Otherwise the player would see the intermission of all 0%'s for the level they didn't play.
User avatar
Legend
Posts: 158
Joined: Fri Jun 11, 2010 12:32 am
Location: Antioch, CA

Re: Randomly Selecting From a List

Post by Legend »

still not sure how to combine the code samples in my last post or where to put them. I've been looking in the wiki for help on how to implement it but still not sure how yet. If Slasher, or isle (or anyone else) could provide a few more pointers, I'd appreciate it. Thanks.
Locked

Return to “Editing (Archive)”