[SCRIPT]Change to specific random map - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: [SCRIPT]Change to specific random map (/thread-19279.html) |
[SCRIPT]Change to specific random map - FlawlessHappiness - 11-19-2012 Hey guys! So in my custom story i want to change to different maps with one script, posted in the end of all the maps. It will work like this: You start in the default map (Which is NOT random). You get to a point where the script calls and you change map: There are 3 different maps to change to, and the first change should be completely random. After getting to the "end-point" in map 1, the script calls again, but now it can only choose between the 2 maps which haven't been played yet. At last when finishing that map, you will change to the last map, not played. I cannot figure out how to script this. Yes it's something with SetGlobalVarInt("Map_1", 1) and GetGlobalVarInt and that... but when it also has to choose randomly between them. It cannot seem to form correctly in my head. Could anybody help me? Lets just call the maps: Path_1 Path_2 Path_3 RE: [SCRIPT]Change to specific random map - The chaser - 11-19-2012 Ok. So: AddEntityCollideCallback("Player", "Script_change_da'_map", "CHANGE", true, 1); void CHANGE (///sintaxis) { ChangeMap ///Sorry, I'm in a friends house and I don't remain how it was. But, you will add a RandInt(1, 3); } So, make several callbacks: If went to map three: { AddGlobalVarInt("I_WENT_TO_MAP_THREE", 1); Change(); } void Change() { if (GetGlobalVarInt("I_WENT_TO_MAP_THREE") == 1) { ChangeMap////+RandInt (1, 2) } } And you should do something like this for the other maps. Sorry for not putting all the script, but I'm in a friend's house (Gooby) and I don't have time. Hope you the best of luck! RE: [SCRIPT]Change to specific random map - FlawlessHappiness - 11-19-2012 I'm not sure how this will work... What if the player went to map 2? I cannot say RandInt(1, 3) because that will include 2 RE: [SCRIPT]Change to specific random map - Adrianis - 11-19-2012 You'll want to use the RandInt(int, int) function, there you can set the range to pick from (say, RandInt(1, 3), then you can append that to the name of the map you want to change to. For example (this will need to be inside a function) int MapNum = RandInt(1, 3); ChangeMap("Path_" + MapNum, .... etc); That is, very basically, a way to get a random map to jump to - you'll need to be careful with the names of maps (so that they are all Path_1, Path_2 etc) and also the names of the start positions will have to be the same since you need to provide the ChangeMap function with the name of the start pos. You'll probably run into problems in keeping a record of which maps you have already been to, you should be able to do this with global variables but it would be best to use an array, but I'm not sure how arrays behave in the global script yet so I won't give you advice on that EDIT: Ninja'd, but the problem with only using a variable for which map you've been to is as you say, if 2 gets picked then you are buggered. Also, global variables as far as I understand get wiped if the player saves/exits/restarts, so its kinda dangerous RE: [SCRIPT]Change to specific random map - Kreekakon - 11-19-2012 If you want to avoid to choosing 2, I'd suggest you to use a "While" function to help with this. Like say: SetGlobalVarInt("maper", RandInt(1,3)); While (GetGlobalVarInt("maper")==2) { SetGlobalVarInt("maper", RandInt(1,3)); } The above will keep picking random numbers until you get one you're "happy with". Afterwards, just do your map changing stuff. RE: [SCRIPT]Change to specific random map - Your Computer - 11-19-2012 (11-19-2012, 05:53 PM)Adrianis Wrote: Also, global variables as far as I understand get wiped if the player saves/exits/restarts, so its kinda dangerous They don't get wiped if the player saves, only if the player exits without saving, which isn't an issue. RE: [SCRIPT]Change to specific random map - The chaser - 11-19-2012 (11-19-2012, 06:04 PM)Kreekakon Wrote: SetGlobalVarInt("maper", RandInt(1,3));That would still have a chance to choose two. RE: [SCRIPT]Change to specific random map - FlawlessHappiness - 11-19-2012 Ok! Thank you for all who came up with ideas! I think i've got it now. Please tell me if there is an error. Here is the script: Spoiler below!
EDIT: Is it ok to use a lot of timers calling in 0 seconds? RE: [SCRIPT]Change to specific random map - Kreekakon - 11-19-2012 (11-19-2012, 07:00 PM)The chaser Wrote:No, it wouldn't. This is how the script would go:(11-19-2012, 06:04 PM)Kreekakon Wrote: SetGlobalVarInt("maper", RandInt(1,3));That would still have a chance to choose two. 1. Randomly pick from 1 to 3 2(a). If you get something besides a 2, everything keeps going normally. or 2(b). If you get a 2 you will enter the "while" script, because "maper" being equal to 2 fulfills the conditions under which the while will run. 3. The script inside the while will pick a new number for maper at random, also from 1 to 3. It will keep repeating this process until "maper" is no longer 2, because as long as it is, the while script will never end, and keep repeating itself. RE: [SCRIPT]Change to specific random map - The chaser - 11-19-2012 (11-19-2012, 07:09 PM)Kreekakon Wrote:You are a Genius.(11-19-2012, 07:00 PM)The chaser Wrote:No, it wouldn't. This is how the script would go:(11-19-2012, 06:04 PM)Kreekakon Wrote: SetGlobalVarInt("maper", RandInt(1,3));That would still have a chance to choose two. |