じ☆ve冰风 发表于 前天 09:32

Door popup windows

Hello community, I am writing this tutorial fundamentally because I did something very similar while answering a post and I thought that my answer could be transformed into a tutorial with ease. In this tutorial I am going to explain how to create popup windows. I will focus on how to create them for doors but you can apply them to any event that works more or less in the same way (such as quests characters for example).

    What we are going to do is an event that looks like this:




    To achieve this we need absolutely no script at all. Everything will be done using events. Now you are probably bored about my premise so...let's step into it.

First step: door creation

SpoilerSince we are going to create popup windows for doors we need a door first. Let's create one. To do this as quick as possible you can press Ctrl+2 and let the engine create a door event in a very simple way. If you want to create a door that works differently you are free to do it but you might have to modify few things later on.


            Once you created your door copy your event page and duplicate it. This way you end up having two identical pages. Since we don't need two identical pages we are going to delete everything in the first page contents (only in the contents! do not use clear page or it will delete everything!). What's this page for will be explaned in the next step, don't worry about it, for now just leave it blank.


Note: if you decided to create your own door event be sure to set your first page priority to "Same as Characters" and trigger to "Player Touch".


            Now that we have our door event we can proceed to the next step.





Second step: popup window

SpoilerTime to fill our door contents with something and that something is going to be our popup window.


            There are few things we need to achieve that:


[*]Two variables to store player map X and Y coordinates (of course if the player moves we want our popup window to disappear...we don't want it to stay there forever, right?)
[*]A switch to tell the game that our popup window is being shown and to pass that information to other events
[*]A variable to create our popup window and access it from other events.

            The first point is easy to achieve. Add new event command and select "Control Variables" then select a variable and set it to be equal to Game Data > Player Map X.
            If you have never stored player coordinates into a variable before nor used Game Data in your Control Variables command your game data window should look like this:



Spoiler





            The final look of your Control Variable command should be this one:

Spoiler





            Now you have to do the same with another variable where we are going to store player's map Y.


            After setting up our variables let's add another Event Command to turn on a switch. Up to you which switch you want to use, just remember it's ID. The same goes for your variables as well.


Note: In this tutorial I am going to use Variable 1 for player X and Variable 2 for player Y while my switch will be switch number 1.


            To complete this part add a Script Call event command (you can find it in the 3rd page). Script calls are really versatile and allow you to write pieces of code to be executed in your event. In our script call we need another variable to store our window. In my example it will be variable 3. To create a window we need something like this:



@shop_name = "Your Shop Name"
$game_variables = Window_Base.new(0, 0, Graphics.width, 48)
$game_variables.draw_text_ex(0, 0, @shop_name)


            Where "Your Shop Name" can be anything you want but don't forget the quotation marks!


            Example: "The Happy Unicorn"


IMPORTANT: if you want to use a different variable just change the "3" in the code with your variable ID. Don't forget to do it or it will use your variable 3.


            If you did everything right your event first page should look like this:

Spoiler









Third step: handling our window

SpoilerIf you test your game now you will see that your window does pop up but there is no way it disappears. That's why we are going to modify our second event page and to add a common event to handle it.


Note: if you don't want to use a common event you can use another event in the map but then you have to put one in each map with at least a popup window.


            First of all move to your second page and before every other command add a Control Switch command to turn off the switch you used (in my case it's switch 1). Immediatly after that add a Script Call command to dispose our window and reset our variable 3. To do that you have to write this in your script call:



$game_variables.dispose
$game_variables = 0


IMPORTANT: change the number 3 to be the ID of the variable you used for your window!


            At this point your second page should look like this:


Spoiler






            Since your second page is now fine let's move to our common event. Press F9 and select the Common Events tab, then create a new one and set its Trigger to "Parallel Process" and its Condition Switch to be the switch you turned on in your door event first page (in my case it's switch 1).


            Once your common event is ready add a Script Call command and write this (with opportune changes):



@same_x = ($game_player.x == $game_variables)
@same_y = ($game_player.y == $game_variables)
unless (@same_x && @same_y)
$game_variables.dispose
$game_variables = 0
$game_switches = false
end




IMPORTANT: The variable in the first line should be the one you used to store player's map X, the one in the second line should be the one you used to store player's map Y while the other one should be the one you used for your window. The switch is the switch you turned on in your door event first page.


What's this event for?


            This event checks the player position every frame and compares the new coordinates with the one we stored in our variables. If they are the same it does nothing, if they somwhow changed (the player moved) it disposes the popup window and resets both the variable we used for our window and the switch we used to tell that the window was being shown.


            If you followed my steps then your event looks like this:

Spoiler












Good job!


    Now you have your popup window, test your game and see how it looks.


    One thing you might find uncomfortable is the fact that the delay between when the window is shown and when the player activates the door is too short. If you want to increase it just put a wait command at the bottom of your door first page (5 or 10 frames should be ehough).


    Thank you for reading and have fun with your popup windows!


    P.S. These are very basic windows. you can achieve something different using the same method. Here are few samples.


    Resized door name:

Spoiler





    Quest Dialogue Popup:

Spoiler






本贴来自国际rpgmaker官方论坛作者:Heirukichi处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/door-popup-windows.71543/
页: [1]
查看完整版本: Door popup windows