Hi again everyone!
Need a little help with my script that I believe you guys have a nice solution to :)
So I've created a region in a room; when the player walks onto this region, he will change rooms and say a few words when he enters said room.
This is how my script looks like for room number 2:
function region1_WalksOnto(){
player.Say("Blablabla.");
player.ChangeRoom(1, 100, 200);
}
Now, as I said, when the player changes room I want him to say a few things, so this is my script in room no. 1:
function room_AfterFadeIn()
{
if(player.PreviousRoom == 2)
{
player.Say("Please help me find a solution to this problem!");
}
However, my problem is, the player will say this line every time he enters the room, even if I don't walk onto the region. How do I make him say it only once and not every single time I enter the room?
Thank you for your help!
You can use Game.DoOnceOnly():
function room_AfterFadeIn()
{
if(player.PreviousRoom == 2)
{
if (Game.DoOnceOnly("enter room 2")) player.Say("Please help me find a solution to this problem!");
}
}
Or you can use the "first time player enters room event", but only if the previous room doesn't matter.
If you only want to trigger this once after stepping on room 2's region1 (and not if the player enters the room coming from room #2 some other way), you can use a global int variable (set to 0 initially).
In the region's code add 1 to the variable. In AfterFadeIn, check for it being equal to 1 and only then make the player say something. The next time it'll be 2, so it won't trigger again.
Thank you Khris, that did the trick!
Although, now I have another problem. If I wanted the player to stop walking on the region, and instead (when you click the region or walk onto it) say something like "No way, I'm not going near that thing again". How would I do that with the Global variables in place?
Right now, my script looks almost like this:
function region1_WalksOnto()
{
if (GateRegionWalk == 0){
Blablabla
GateRegionWalk = 1;
}
else if (GateRegionWalk == 1){
cPlayer.ChangeRoom(1, 100, 200);
GateRegionWalk = 2;
}
That's where it cuts off to room number 1, but if the player were to click on the region/hotspot in front of it, how would I make the character refuse to go there? Can I still use the Global Variable or do I have to create a whole new variable for that to work?
Just add another else if block and check for GateRegionWalk being equal to 2.
Inside, call player.StopMoving().
You only need two variables if you're dealing with two independent game states.
Quote from: Khris on Thu 23/07/2015 01:05:49
Just add another else if block and check for GateRegionWalk being equal to 2.
Inside, call player.StopMoving().
You only need two variables if you're dealing with two independent game states.
Thank you, it's working now!
I solved it by editing the hotspot script like this:
function hGate_AnyClick()
{
// WALK TO
if (GateRegionWalk == 3){
player.StopMoving();
player.Say("Blablabla.");
}
else if(UsedAction(eMA_WalkTo)){
player.Walk(350, 190, eNoBlock, eWalkableAreas);
}
else Unhandled();
}
And then adding a second region beneath the first one, and making this script:
function region2_WalksOnto()
{
if (GateRegionWalk == 3){
player.Say("Blablabla.");
player.Walk(130, 265, eBlock, eWalkableAreas);
}
}
Thank you for the help Khris! :)