RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Catapiller Script

0 Members and 1 Guest are viewing this topic.

****
Rep:
Level 87
In my own little world...
Can you say, "Follow the leader"?
Well, now we're going to discuss the basic element for a catapiller script - A code that makes other events follow the player.. There are more advanced ways to do it, but that's for you to explore.
Q.So why do an event version when I can just use an RGSS script?
A. An eventing version is much more managable for special cutscenes or parts in your game, well, for non-scriptors anyway..

Here's the crackdown, I'll display the script, then explain what each command does, after all, eventing is like a whole 'nother language.

Basic Catapiller Script:
Code: [Select]
<>Variable: [0001: Player X] = Player X Coords
<>Variable: [0002: Player Y] = Player Y Coords
<>Variable: [0003: Follower 1 X] = This Event X Coords
<>Variable: [0004: Follower 1 Y] = This Event Y Coords
Code: [Select]
<>Conditional Branch: Variable [0001: Player X] > Variable [0003: Follower 1 X]
  <>Move Event:: This Event
  :                     : <>Move Right
<>
End
<>Conditional Branch: Variable [0001: Player X] < Variable [0003: Follower 1 X]
  <>Move Event:: This Event
  :                     : <>Move Left
<>
End
<>Conditional Branch: Variable [0001: Player Y] > Variable [0003: Follower 1 Y]
  <>Move Event:: This Event
  :                     : <>Move Down
<>
End
<>Conditional Branch: Variable [0001: Player Y] < Variable [0003: Follower 1 Y]
  <>Move Event:: This Event
  :                     : <>Move Up
<>
End

I know what your thinking,
"OMG great, sexy, intellectual, cunning, amazing and compassionate teacher Arkbennett, I just don't understand what all those bigs words like 'variable' even mean!"
I know, it's a dreaded fate not to understand, so, let's delve deeper into it, shall we?

First off, typically your going to put this in a reguler event on the map, but you could use it through a common event, but let's not get into that now. Your going to start a new event on the map, name it whatever you want. Your going to set it as a parallel event, I typically set the speed to fast and the frequency to higher. And yes, this coding will go inside the event that you want to follow the player.

Now, you see that I split the code, the first portion is going to be part 1, the second; part 2.
The first part is the variable set up. This is where your going to save both the X and Y  of the player and the followers coordinates. You should have some knowledge of variables, so we won't delve to deep in it.
Part 2 is the Conditional Branch, this determines which way the follower should go.
It's pretty simple, RMXP's coordinate setup is similer to Quandrant IVs in math (0 starts in the top left) and the X increases as you move right, and the Y increases as you move down. So, for the first conditional branch,

Code: [Select]
<>Conditional Branch: Variable [0001: Player X] > Variable [0003: Follower 1 X]
  <>Move Event:: This Event
  :                     : <>Move Right
<>
End

It's saying, if Player's X coordinate is greater than Follower 1's X, Move Right. Easy peasy, right? Now, if you wanted to add more followers, Make follower 2 follow follower 1, follower 3 follows follower 2, and so on and so forth.

I'd suggest putting follower 2 variables and Conditional Branchs in the event that will be follower 2. The same with 3 and 4 and so on.
So as an example, follower 2 would look like this..

Code: [Select]
<>Variable: [0005: Follower 2 X] = This Event X Coords
<>Variable: [0006: Follower 2 Y] = This Event Y Coords
Code: [Select]
<>Conditional Branch: Variable [0003: Follower 1 X] > Variable [0005: Follower 2 X]
  <>Move Event:: This Event
  :                     : <>Move Right
<>
End
<>Conditional Branch: Variable [0003: Follower 1 X] < Variable [0005: Follower 2 X]
  <>Move Event:: This Event
  :                     : <>Move Left
<>
End
<>Conditional Branch: Variable [0004: Follower 1 Y] > Variable [0006: Follower 2 Y]
  <>Move Event:: This Event
  :                     : <>Move Down
<>
End
<>Conditional Branch: Variable [0004: Follower 1 Y] < Variable [0006: Follower 2 Y]
  <>Move Event:: This Event
  :                     : <>Move Up
<>
End

Alrighty, I think I got the basic element down of the catapiller script, so, if you have any questions or are confused in any way, please heistate to ask. Just joking go ahead and ask!

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Seems pretty nice.

I'll move it to the TD, but just as a suggestion, to reduce stress on the system, it might be a good idea to do two things:

First, combine all the events for each member of the party into one parallel process event. The downside to this is, of course, that you cannot directly copy & paste the event, you will need to make sure it controls the right events for that map.

Second, put the conditional branches into Else Conditions. I.e., instead of running all four conditional branches every frame, write it like this:

<>Conditional Branch: Variable [0001: Player X] != Variable [0003: Follower 1 X]
  <>Conditional Branch: Variable [0001: Player X] > Variable [0003: Follower 1 X]
  <>Move Event:: This Event
      :                     : <>Move Right
  <>
    Else
      <>Move Event:: This Event
       :                     : <>Move Left
      <>
    End
Else
  <>Conditional Branch: Variable [0001: Player Y] > Variable [0003: Follower 1 Y]
  <>Move Event:: This Event
      :                     : <>Move Down
  <>
    Else
      <>Move Event:: This Event
       :                     : <>Move Up
      <>
    End
END


Also, it would be a good idea to mention that the events you are using as the followers chould be checked as Through, so you can't get trapped in corners.


All in all, an effective and useful tutorial. Nice job.


****
Rep:
Level 87
In my own little world...
Your absolutely right, but the time I wrote this I didn't know that.
The whole time I've been eventing RPG Maker, I didn't use else case very much until recently with my percentage formula when my seperate conditonal branchs are lagging up the game.

So I used else case and voila, worked like a charm!
Thank you for the correction.

Edit:
Quote
Also, it would be a good idea to mention that the events you are using as the followers chould be checked as Through, so you can't get trapped in corners.


All in all, an effective and useful tutorial. Nice job.

Thank you for your kind words, the reason I didn't mention checking "Through" or "Phasing" in Xp is because the following characters will just walk inside of you and sit there.
They think it's okay to do that.
« Last Edit: August 19, 2007, 06:29:12 AM by Arkbennett »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Sorry, I did make a mistake, unfortunately. This part:

  <>Conditional Branch: Variable [0001: Player Y] > Variable [0003: Follower 1 Y]
  <>Move Event:: This Event
      :                     : <>Move Down
  <>
    Else
      <>Move Event:: This Event
       :                     : <>Move Up
      <>
    End

Should be inside another conditional branch:

<>Conditional Branch: Variable [0001: Player Y] != Variable [0003: Follower 1 Y]

END


As well, this structure is a little strange given this:

<>Variable: [0001: Player X] = Player X Coords
<>Variable: [0002: Player Y] = Player Y Coords
<>Variable: [0003: Follower 1 X] = This Event X Coords
<>Variable: [0004: Follower 1 Y] = This Event Y Coords

Player X will be greater or lesser than Follower X or Player Y will be greater or lesser than Follower Y as long as the Follower is not on the exact same square as the player. It would be better to base the system on player position and last player position, especially if you set the follower events on through.

These are mostly suggestions, and you don't have to revise your system if you don't want to.

Oh, and 2000th post :)
« Last Edit: August 19, 2007, 10:16:28 PM by modern algebra »

**
Rep:
Level 87
can u make a demo?


****
Rep:
Level 87
In my own little world...
Sure if you'd like.
I'll make one later today.

**
Rep:
Level 87
thanx... i could really use this in my game


****
Rep:
Level 87
In my own little world...
Quote
These are mostly suggestions, and you don't have to revise your system if you don't want to.

Yeah, after going over your method I realized the same thing. Originally I just skimmed through your version looking for differences, it looked fine, then when I actually tried it I got the same problem.

Anywho, I did revise it with the "else" case, but I didn't make it all in one event, simply so you can C&P it from map to map without making any changes. Convienence.

Alrighty, well, on request by a Mr. Brandon Jenkins, here is the catapiller script. You can learn from it, or just copy and paste it into your project and it'll work like a charm. But I suggest you learn it.
Catapiller Script Demo