Moving all Events on the Map

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Hmm, the script seems like it only accounts for turning the map once, and then back again. I can turn it clockwise, or counterclockwise, 90 degrees at a time, as much as I like. If I'm wrong correct me on this please, but I think a variable would be better in this case, such as a value of the variable corresponding to the amount turned? I use that system for the graphical side of things, set to the following:

"[Event to change Variable number 26 to a value of 4]
The variable keeps track of which way the map has been rotated.
Think of quadrants in Geometry.
1: 270 clockwise from standard
2: 180 clockwise from standard
3: 90 clockwise from standard
4: Standard Direction"
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
Yes, it only keeps track of one rotation. If you want to rotate your map more than once then a variable is better than a switch. However in that case a recursive method that applies N transformations to your x and y coordinates is better. (N in this case isbthe number of rotations applied)

If you are not in a hurry and can wait until tuesday I can provide a new script that keeps track of more than one rotation.
 

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Alright. I trust you know what you're doing, so I'd be glad to wait.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
I managed to find a bit of time today so I edited the code in my previous post to handle different directions. I didn't test it so I have to rely on you for that.

I fixed few things that might cause unpleasant issues and I made it able to handle multiple rotations. Just remember to change the id in $game_variables[id] to be the same as the one you want to use for your variable and do not forget to increase that variable every time a rotation occurs. Its value should be as follows:
  • 0° rotation: variable = 0
  • 90° rotation: variable = 1
  • 180° rotation: variable = 2
  • 270° rotation: variable = 3
You can use something like this whenever you rotate something:
Code:
($game_variables[id] >= 4) ? ($game_variables[id] = 0) : ($game_variables[id] += 1)


# if that doesn't fit in a line then use this one

a = $game_variables[id]
$game_variables[id] = ((a >= 4) ? 0 : (a+1))
In this case, as in the previous one, you should change id to be the one you need.
 
Last edited:

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Hmm, I can't seem to get it functioning. The collision simply isn't changing. Here's my event, so far.

Code_2.png

I also tried out your script for moving events, and it simply crashes my game. It says "events" is not a method.

Error_001.png
 
Last edited:

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
I cant help with scripting but i got an Idea, atleast in Theory :).
1.
Put an invisible Event in the middle of your Maps. The Maps will rotate around that middle point, this point is also our fix point to calculate the
Event positions.
2.
If you press the Button to change Map Angle, you calculate the X and Y maptile distance of the Test Event. (mpointx -eventx =x distance)
Thatway you know where exactly it is. In our case (y = +1 (one tile down) ) and (x= -4 (4tiles to the left))
3.
Now we need to somehow create a fancy algorithm that changes the x and y values acordingly.
A Loop with the teleport commands should make all events teleport at once.
------------------------

Lets think about the rotation:
If standard is the look from south to north and
if y = 0 (to make the exmaple easier)
if x = -4
If we would rotate this,
to the right: x= -4 becomes y= -4
to the left: x= -4 becomes y= +4

But we need a Math Person to put the changes into a formula.
Than maybe a self variables script , or a script equivalent variable pointer and you are able to teleport hundret of events
with 10 lines event scriptcall. But my brain is a little rusty and would overheat :).

Edit:
Not directly, no. You can only use Set Event Location to a specific spot, to coordinates based on variables, and by switching with another event.

I'm certain I can get around the 90 degree issue with a formula and a Script Call, but I'm not sure about performing to all events on the map. Perhaps this should be moved to script support? I'm not sure.
You should take a look at the Script equivalent thread in this Forums,you can use event command script and insert single command lines, like in this Case Teleport Event. MAybe there is something helpfull in there.

Edit2: I oversaw the seccond thread page ^^ damn i should go back sleeping.
 
Last edited:

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
Ehm, are you sure you used the script in the right way? In the script I provided there is no such a word as "events". That's something I used only in the script call, but you don't have to add it to your materials ad from what I can see you have a script called "Rotate Events".
Code:
class Game_CharacterBase
  def passable?(x, y, d)
   x2 = $game_map.round_x_with_direction(x, d)
   y2 = $game_map.round_y_with_direction(y, d)
   if map_rotated?
     # xN and yN are x and y coordinates of the center of your cartesian translated system
     xnew = rotated_x(x2, y2, xN, yN, rotations)
     ynew = rotated_y(x2, y2, xN, yN, rotations)
     x2 = xnew
     y2 = ynew
     x1 = $game_map.round_x_with_direction(x2, reverse_dir(d))
     y1 = $game_map.round_y_with_direction(y2, reverse_dir(d))
   end
   return false unless ($game_map.valid?(x, y) && $game_map.valid?(x2, y2))
   return true if @through || debug_through?
   return false unless map_passable?(x1, y1, d)
   return false unless map_passable?(x2, y2, reverse_dir(d))
   return false if collide_with_characters?(x, y)
   return true
  end

  def rotations
   $game_variables[id] #the id of the variable used to tell the engine how many times your map is rotated
  end

  def map_rotated?
   rotations > 0
  end

  def rotated_x(x, y, xN, yN, times)
   return x if (times == 0)
   x1 = rotated_y(x, y, xN, yN, times - 1) - yN
   x1 += xN
   return x1
  end

  def rotated_y(x, y, xN, yN, times)
   return y if (times == 0)
   y1 = rotated_x(x, y, xN, yN, times - 1) - xN
   y1 = yN - y1
   return y1
  end
end
Code:
xN = 30 #your central square x goes here
yN = 30 #your central square y goes here
$game_map.events.each do |event|
  evX = event.x - xN
  evY = event.y - yN
  newX = evY + xN
  newY = -evX + yN
  event.moveto(newX, newY)
end
Put an invisible Event in the middle of your Maps. The Maps will rotate around that middle point, this point is also our fix point to calculate the
Event positions
This is also a very good idea to get the central square of your map. This way you can access it using $game_map.events[central_event_id].x and $game_map.events[central_event_id].y
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
I kinda like the Idea of rotating maps, i hope you provide us with a link as soon your game is finished or a demo is released :).
Sounds like a real good Gameplay Mechanic, iam excited to see how it looks and feels in the end.
 

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Ah, I had thought you provided two different scripts, one for events, and one for collision. I guess that's incorrect. Even after fixing that though, it still crashes.

Error_002.png Code_3.png Error_002.png
 
Last edited:

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
Ups, my bad. I fixed it:
Code:
xN = 30 #your central square x goes here
yN = 30 #your central square y goes here
$game_map.events.each do |event|
  evX = event[1].x - xN
  evY = event[1].y - yN
  newX = evY + xN
  newY = -evX + yN
  event[1].moveto(newX, newY)
end
 

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
It works! However, the script makes entities rotate counter-clockwise, rather than clockwise. (This is easily fixable though, I just need to rotate multiple times at once, I think? Also, collision still does not rotate.

Edit: I edited the script so now events rotate in the correct direction. I also found out the central number was 29, not 30 or 31. I'm still working on getting collision to rotate; no luck so far, though.

Also, would you modify the script to move the player's location as well?
 
Last edited:

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
Are you using 1 Map for this? Or are you using 4Maps for this?

What do you mean by Collisions?
Map Passability?
 

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
I'm using one map. Having four kind of defeats the purpose, doesn't it?

Yes, based on a collision map, though, and not tile data.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
It works! However, the script makes entities rotate counter-clockwise, rather than clockwise.
Yes, it was made this way since in math positive angles are obtained that way. Changing it is super easy anyway.

About passability...it seems that compatibility with Hime's script is harder than I thought. That's because it uses a dll to handle collisions and that overwrites the normal method. Since you rotated your map but you moved your events what you have to rotate is map layers' passability and NOT events' passability.
That makes it impossible for me to pass a different x and y to Hime's method because that way it wold detect no event (allowing your character to pass on events). At the same time I cannot tell it to only calculate map layers because everything it does is handled by the dll.
That said I can actually pass Hime's script new coordinates if you set all your events to be passable and draw your passability map in a way that keeps track of where your events are (so basically you have to manually set the event tile unpassable by drawing it on the collision map). This is a way of going it. Another way of doing it is to use a different script that allows you to draw a collision map using regions (and I can write that for you). The choice is up to you.

IMPORTANT NOTE:
Keep in mind that once you made your choice you have to change everything: if you draw your events directly on the collision map you have to manually change every collision map you used so far and every event as well. At the same time, if you use regions you have to manually draw your collision map using regions in every map but you can keep your events as they are.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
But are his events than still able to move around the map?
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
That's exactly why I stated pro and cons of both options. Unfortunately Hime says that the script is provided as is and is not going to recive any change.

Since rotating maps is something that the script itself doesn't do (and is not intended in that way) editing the script makes it impossibile for movable event to be unpassable. The only unpassable events will be those who have their square marked on the collision map.

On the other hand this requires less modifications to the rest of the game while the other way, while allowing a better way to handle events, requires a region collision map for every other map in the game. And even if it is kinda fast and easy to do it is still a pain if the OP has a large amount of maps in his game.
 
  • Like
Reactions: Bex

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Well, do you think you can create a way to change the collision map in-game? If you can do that, I can always just use four collision maps per map, one for each orientation.
 
  • Like
Reactions: Bex

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
That can be done but we have to decide a formula for it. For example: every 90° rotated collision map could have an id that is 1 and the real id.
This way the 1st rotation for map 1 will have a collision map named with id 101.

That depends on how many maps you have in your game. After we decided a formula that can be easily done.
 

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
So far, I'm naming my layer graphics with the following convention.

1: 270 clockwise from standard (Viewing from West)
2: 180 clockwise from standard (Viewing from North)
3: 90 clockwise from standard (Viewing from East)
4: Standard Direction (Viewing from South)

Naming_Convention.png

As for the number of maps, there's easily over 80 rooms in the castle proper, but each floor of the castle is a single, subdivided, map. There'll be plenty of maps, though.

I named the collision map after the ID of the map in question. The test map for this little project is Map 008, so I named it "Map008". This could easily be "Map008_1", "Map008_2", etc.
 
Last edited:

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
How many maps do you have in your game? Because I thought of something easier but it depends on how many maps you are using.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D

Forum statistics

Threads
106,051
Messages
1,018,551
Members
137,837
Latest member
Dabi
Top