Request: A script randomly picking a place to adventure

coolbartek

New member
I'm starting to learn scripting in mafia, but I do not know how to make mafia pick advenure place randomly. Could Anybody tell me or do a short script?
 
I'm not sure what the practical use of such a thing is, but it wouldn't be too hard to write a function that returns a random location.

Here's one:
Code:
location random_location(){
        location[int] locs;
        foreach loc in $locations[]
            locs[count(locs)] = loc;
        return locs[random(count(locs))];
}
Here's some of the locations it returned:
Code:
Fun House
Post-War Sonofa Beach
The Middle Chamber
Astral Mushroom (Bad Trip)
Simple Tool-Making Cave
Mine Foremens' Office
Battlefield (Hippy Uniform)
Frat House (Stone Age)
Post-War Sonofa Beach
Battlefield (No Uniform)
Batrat and Ratbat Burrow
Haunted Conservatory
Crimbo Town Toy Factory
As you can see, if you were trying to script some sort of adventuring routine with this it would be utterly pointless. I suppose you could try to combine it with canadv.ash, but a lot of locations would still fall through the cracks.

If your looking to select a random location from a list of just a handful it becomes much more practical:

Code:
location random_location(){
    location[int] locs;
    locs[0] = $location[Giant's Castle];
    locs[1] = $location[Hole in the Sky];
    locs[2] = $location[Fantasy Airship];
    return locs[random(count(locs))];
}
When called the function above returns a random location of the three listed. If you are only planning on considering a handful of locations then hard coding the locations as a map like the function above is probably your best bet.
 

slyz

Developer
This will print a random location. I guess you can take it from here.
PHP:
location[int] locs;
foreach l in $locations[]
	locs[ count(locs) ] = l ;

print( locs[ random(count(locs)) ] );

EDIT:
lol, I was beautifully ninja'd by That Ninja. And with the exact same code!
 
Last edited:
Top