Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SCRIPT]Change to specific random map
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#1
[SCRIPT]Change to specific random map

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

Trying is the first step to success.
(This post was last modified: 11-19-2012, 05:02 PM by FlawlessHappiness.)
11-19-2012, 05:01 PM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#2
RE: [SCRIPT]Change to specific random map

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!

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
11-19-2012, 05:47 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#3
RE: [SCRIPT]Change to specific random map

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

Trying is the first step to success.
11-19-2012, 05:51 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#4
RE: [SCRIPT]Change to specific random map

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 Smile

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
(This post was last modified: 11-19-2012, 05:55 PM by Adrianis.)
11-19-2012, 05:53 PM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#5
RE: [SCRIPT]Change to specific random map

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.

[Image: Tv0YgQb.gif]
Image by BandyGrass
(This post was last modified: 11-19-2012, 07:26 PM by Kreekakon.)
11-19-2012, 06:04 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: [SCRIPT]Change to specific random map

(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.

Tutorials: From Noob to Pro
11-19-2012, 06:40 PM
Website Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#7
RE: [SCRIPT]Change to specific random map

(11-19-2012, 06:04 PM)Kreekakon Wrote: SetGlobalVarInt("maper", RandInt(1,3));
While (GetLocalVarInt("maper")==2)
{
SetGlobalVarInt("maper", RandInt(1,3));
}
That would still have a chance to choose two.

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
11-19-2012, 07:00 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#8
RE: [SCRIPT]Change to specific random map

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!


void Collide(string &in asParent, string &in asChild, int alState)
{

//BEGIN FOR THE 3RD MAP//

if(GetGlobalVarInt("PlayedPath_1") == 1 && GetGlobalVarInt("PlayedPath_2") == 1)
{
ChangeMap("Path_3", "PlayerStartArea_1", "", "");
SetGlobalVarInt("FinalLevel", 1);
return;
}

if(GetGlobalVarInt("PlayedPath_2") == 1 && GetGlobalVarInt("PlayedPath_3") == 1)
{
ChangeMap("Path_1", "PlayerStartArea_1", "", "");
SetGlobalVarInt("FinalLevel", 1);
return;
}

if(GetGlobalVarInt("PlayedPath_1") == 1 && GetGlobalVarInt("PlayedPath_3") == 1)
{
ChangeMap("Path_2", "PlayerStartArea_1", "", "");
SetGlobalVarInt("FinalLevel", 1);
return;
}

//END FOR THE 3RD MAP//

//BEGIN FOR THE 2ND MAP//

if(GetGlobalVarInt("PlayedFirstPath_1") == 1)
{
AddTimer("ChangeMap_Second_"+RandInt(2, 3), 0, "ChangeMap_Second");
return;
}

if(GetGlobalVarInt("PlayedFirstPath_2") == 1)
{
AddTimer("ChangeMap_Second_"+RandInt(1, 2), 0, "ChangeMap_Second_1_3");
//IF THE PLAYER PLAYED 1 AND 3, CALL SEPARATE TIMER THAT CHOOSES BETWEEN 1 AND 3//
return;
}

if(GetGlobalVarInt("PlayedFirstPath_3") == 1)
{
AddTimer("ChangeMap_Second_"+RandInt(1, 2), 0, "ChangeMap_Second");
return;
}

//END FOR THE 2ND MAP//

//BEGIN FOR THE 1ST MAP. CHOOSE RANDOM LEVEL//

AddTimer("ChangeMap_First_"+RandInt(1, 3), 0, "ChangeMap_First");

//END FOR THE 1ST MAP//
}

//BGEIN FIRST MAP CHOOSE//

void ChangeMap_First(string &in asTimer)
{
if(asTimer == "ChangeMap_First_1")
{
SetGlobalVarInt("PlayedFirstPath_1", 1);
SetGlobalVarInt("PlayedPath_1", 1);
ChangeMap("Path_1", "PlayerStartArea_1", "", "");
return;
}

if(asTimer == "ChangeMap_First_2")
{
SetGlobalVarInt("PlayedFirstPath_2", 1);
SetGlobalVarInt("PlayedPath_2", 1);
ChangeMap("Path_2", "PlayerStartArea_1", "", "");
return;
}

if(asTimer == "ChangeMap_First_3")
{
SetGlobalVarInt("PlayedFirstPath_3", 1);
SetGlobalVarInt("PlayedPath_3", 1);
ChangeMap("Path_3", "PlayerStartArea_1", "", "");
return;
}
}

//END FIRST MAP CHOOSE//

//BEGIN SECOND MAP CHOOSE//

void ChangeMap_Second(string &in asTimer)
{
if(asTimer == "ChangeMap_Second_1")
{
SetGlobalVarInt("PlayedSecondPath_1", 1);
SetGlobalVarInt("PlayedPath_1", 1);
ChangeMap("Path_1", "PlayerStartArea_1", "", "");
return;
}

if(asTimer == "ChangeMap_Second_2")
{
SetGlobalVarInt("PlayedSecondPath_2", 1);
SetGlobalVarInt("PlayedPath_2", 1);
ChangeMap("Path_2", "PlayerStartArea_1", "", "");
return;
}

if(asTimer == "ChangeMap_Second_3")
{
SetGlobalVarInt("PlayedSecondPath_3", 1);
SetGlobalVarInt("PlayedPath_3", 1);
ChangeMap("Path_3", "PlayerStartArea_1", "", "");
return;
}
}

void ChangeMap_Second_1_3(string &in asTimer)
{
if(asTimer == "ChangeMap_Second_1")
{
AddTimer("ChangeMap_Second_1", 0, "ChangeMap_Second");
return;
}

if(asTimer == "ChangeMap_Second_2")
{
AddTimer("ChangeMap_Second_3", 0, "ChangeMap_Second");
return;
}
}

//END SECOND MAP CHOOSE//



EDIT: Is it ok to use a lot of timers calling in 0 seconds?

Trying is the first step to success.
(This post was last modified: 11-19-2012, 07:11 PM by FlawlessHappiness.)
11-19-2012, 07:04 PM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#9
RE: [SCRIPT]Change to specific random map

(11-19-2012, 07:00 PM)The chaser Wrote:
(11-19-2012, 06:04 PM)Kreekakon Wrote: SetGlobalVarInt("maper", RandInt(1,3));
While (GetGlobalVarInt("maper")==2)
{
SetGlobalVarInt("maper", RandInt(1,3));
}
That would still have a chance to choose two.
No, it wouldn't. This is how the script would go:

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.

[Image: Tv0YgQb.gif]
Image by BandyGrass
(This post was last modified: 11-19-2012, 07:26 PM by Kreekakon.)
11-19-2012, 07:09 PM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#10
RE: [SCRIPT]Change to specific random map

(11-19-2012, 07:09 PM)Kreekakon Wrote:
(11-19-2012, 07:00 PM)The chaser Wrote:
(11-19-2012, 06:04 PM)Kreekakon Wrote: SetGlobalVarInt("maper", RandInt(1,3));
While (GetLocalVarInt("maper")==2)
{
SetGlobalVarInt("maper", RandInt(1,3));
}
That would still have a chance to choose two.
No, it wouldn't. This is how the script would go:

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.
You are a Genius.

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
11-19-2012, 07:19 PM
Find




Users browsing this thread: 1 Guest(s)