Hi everyone,
So I've been searching everywhere for a tutorial on how to make falling boulders on the map screen (or any falling object for that matter) that interact and damage the player, but found nothing. So I decided to tinker about for a bit, and I'm happy to say, it works perfectly!
Now, it works perfectly.. But I feel it's not the most optimised method, so I'm open to any suggestions or ideas to improve the formula!
In short, I have created an event that randomly generates on the map as a shadow, waits a second, then a boulder crashes into it. If the player is standing on that shadow as the boulder strikes, they jump back and lose HP.
Requirements:
- I managed to use the RTP shadow from img/system and convert it into a charactersheet using GIMP. I also copied over the boulder to a new character sheet, but removed the shadow underneath it. (You don't need to do this, but it looks better when falling).
- A little bit of scripting for switches, but I can provide the details.
- 2 events (Boulder and shadow).
- No plugins are necessary, but you might want to find one that hides event shadows. (I use Visustella's EventsMoveCore which is free from their sample project on their site).
Let's get stuck in!
Create your 'boulder' event
Create your 'shadow' event
Set shadow to random location
Set boulder location
Drop boulder
Get boulder info
Get hero info
Collision info
Reset trap
Create Your Boulder Event
Create an event with two pages and place it anywhere on the map.
Your first page should be left blank, with no image.
The second page, should be activated when self-switch A is on. Have maximum speed and highest frequency. Set it to through. It should look something like this.
Trigger is irrelevant, as all the work is done in the shadow event.
<Hide Shadow> is a plugin function from Visustella's EventsMoveCore, it's not necessary but does add to the overall look.
Create Your Shadow Event
Create your shadow event with two pages, and place it anywhere on the floor tiles. The first page image should be empty. Both pages should be parallel processes, below the character with the second page being activated once self-switch A is switched on.
Set Shadow to Random Location
For this scenario, I wanted the boulder to fall randomly on the map. I managed to assigning the shadow's X and Y coordinates a random number that correlates with the floor space on the map.
I wanted to make sure that the boulder would fall between the 6th and 10th cells horizontally, and 5th and 7th cells vertically.
Now with these variables, we can set the event location as so..
Now each time this event iterates, it will move to a random location specified by the variables. I added a wait, so the player will see the shadow, and have a second to move out of the way accordingly before the boulder drops!
The first few lines should look something like this.
Set Boulder Location
Now, we need to set the boulder's location relative to where the shadow is.
This was simple enough, at this stage, I changed ShadowY's value and deducted 5 from it.
You can deduct however many you'd like from ShadowY, but remember that your boulder will be that many spaces ABOVE the shadow.
We can now set the event location of the boulder, using the same parameters as the shadow, with the new
ShadowY value.
Now the boulder is in place!
Drop Boulder
This is where I've used some scripting to remotely activate self-switches. Allow me to share the line of code I've used.
$gameSelfSwitches.setValue([14, 4, "A"], true);
For those of you who are unaware, the values in the brackets equate to:
$gameSelfSwitches.setValue([MapID, EventID, "Self-Switch letter"], On/Off(True or False);
So on Map 14, with Event 4 (Boulder), Self-switch A, is set to true (on).
It was a personal preference to use self-switches, otherwise you'll find yourself using a lot of switches if creating multiples of this event.
Now let's drop that boulder!
Firstly
I changed the image of the shadow event, to the image of the shadow. So now there's a visual representation of the shadow onscreen. Followed by a wait of 60 frames.
Secondly
I activated the self-switch of the boulder using the script call mentioned above. So now the boulder is visible.
Thirdly
Now I move the boulder down, ensuring that
Through is On as to not just bump into the player or other objects/walls etc. I also added a few sound FX for immersion.
Now, depending on how much you deducted from the
ShadowY variable value, should dictate how many times down the boulder should move. I deducted five (see image above in
Set boulder Location) so my boulder must move five down to meet the shadow.
Now our boulder is set, time to get some location info!
Get Boulder Info
Now, we're going to need to store the boulder's location info into a few variables, and cross-reference this with the hero's location on the map.
Create BoulderX and BoulderY variables, and assign them the values of Map X, and Map Y of boulder.
Next, get the location info of
BoulderX and
BoulderY, and store them in another variable called
BoulderLocation. With the info type set to Event ID.
Your page should look something like this.
Now we do the same with the player!
Get Hero Info
Again, we need two variables,
HeroX and
HeroY, which we store the hero's X and Y coordinates in.
Followed by a
Get Location Info function that stores these two coordinates in a new variable called
HeroLocation. Info type as EventID again.
Which should look like this..
Collision Info
Finally for this page, we need to determine what happens when the boulder collides with the hero.
Begin with a conditional branch, if
BoulderLocation = HeroLocation. There's no need for an else branch.
Now within this branch, set your parameters on what you want to happen to the player.
I would advise that it ends with you moving the player away from the coordinates, otherwise the branched action will repeat until the event is over!
For my event, I had the player take 100 damage and jump away from the boulder, but the possibilites are up to you!
At the end of this, activate self-switch A of this event.
And finally....
Reset Trap
Take a breath.. The hard part is over! Now, for the easy bit of resetting this trap!
On the second event page. Wait a certain number of frames, and switch of Self-Switch A of this event, and of the boulder (using the script from before, but setting the end value to 'false' instead of true.
And that's it!
Your trap should now reset itself and move to a new random location!
If this doesn't work for you I'm happy to answer any questions and troubleshoot! I'm not the most knowledgable and still consider myself a beginner, but I'll help out anyway I can!
If you have any suggestions on how to improve this, please let me know!
Have fun!
Bleurgh
本贴来自国际rpgmaker官方论坛作者:Bleurgh处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/randomly-falling-boulders-damaging-player-on-impact.146124/