Change the terrain_tag at runtime

nihilath

Villager
Member
Joined
Jul 6, 2014
Messages
21
Reaction score
2
Primarily Uses
Is it possible to change the terrain_tag of certain tiles at runtime? I know that "terrain_tag(x, y)" GETs the tag, but I acutally dont want to "read" it, I would like to re-write it.
 
Reason for that is, I am using Khas Awesome Light Effects. I am changing certain tiles at runtime (secreat passage opens, walls become floor to walk on, with lighting torches etc.) and it seems that the original terrain tags for these tiles are kept and not changed automatically to the new tiles. This results in having wall and roof shadows on plain floors and the like.
 
My method of changing tiles looks like that:

$game_map.data[$game_variables[35],$game_variables[36],2] = $game_variables[38]Again, the only thing that doesn't seem to work propperly is Khas Awesome Light Effects.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
1) If that is called on the same map, maybe KHAS doesn't re-check


2) If that is called on a different map, maybe the old data gets reloaded


3) Maybe the game just really reloads the old data


4) Add a link to the thread of the script
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
ah you're switching images... I thought you where switching the actual tag data... The data is tied with the tile position in the tileset, not with the actual image used...
 

nihilath

Villager
Member
Joined
Jul 6, 2014
Messages
21
Reaction score
2
Primarily Uses
ok... so is there a possibility to change the tag data at runtime? ;)

Somethinge like this?:

Code:
$game_map.data[x,y].terrain_tag = 6
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
IDK, never tried it... so I suggest you actually try it, it might work.
 

nihilath

Villager
Member
Joined
Jul 6, 2014
Messages
21
Reaction score
2
Primarily Uses
unfortunatley not. And I cant find a method or a hint to something like that in Game_Map script :(

Only "Get Terrain Tag"
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
This requires you to manipulate flag settings in the tileset using bit-wise operations.


If the method for getting a terrain tag is provided, then that should automatically give you a big hint on how the tag is stored
 
Last edited by a moderator:

nihilath

Villager
Member
Joined
Jul 6, 2014
Messages
21
Reaction score
2
Primarily Uses
I get your point, but my internal knowledge of the core scripts and ruby in general are quite low. So I am not really sure what I am actually doing, but this is what I come up with:

#-------------------------------------------------------------------------- # * change Terrain Tag #-------------------------------------------------------------------------- def change_terrain_tag(x, y, newTag) return 0 unless valid?(x, y) all_tiles(x, y).each do |tile_id| tileset.flags[tile_id] = newTag end end Its evoked ingame like this

$game_map.change_terrain_tag($game_variables[35],$game_variables[36] - 1,6) where the variables represent x and y positions of a specific tile and 6 the actual terrain tag.

It doesn' throw any errors but when its evoked the player is either freezed to its position, or he can only move streight horizontally.

This is the original method from RPG makers core Game_Map script

Code:
  #--------------------------------------------------------------------------  # * Get Terrain Tag  #--------------------------------------------------------------------------  def terrain_tag(x, y)    return 0 unless valid?(x, y)     layered_tiles(x, y).each do |tile_id|      tag = tileset.flags[tile_id] >> 12      return tag if tag > 0    end    return 0  end
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
What exactly do you want to change? If it's just the shadow, that's not in tileset.flags - it's in $game_map.data itself. If you change tileset.flags info, you are changing it for EVERYWHERE that tile is used, not just the few locations on the map you may identify. And it won't be saved - as soon as you leave the map and come back, it'll be reset. In fact, terrain tags have nothing to do with shadows - unless there's something in Khas' script that mucks around with them.
 

nihilath

Villager
Member
Joined
Jul 6, 2014
Messages
21
Reaction score
2
Primarily Uses
Ok... so I guess than it won't work :(

Khas script uses terrain tags to cut shadows to a realistic angle. The script though doesn't change the terrain tags it is just reading them to calculate the shadows:

#-------------------------------------------------------------------------------# * Instructions - 6. Setup your Tileset Tags!#-------------------------------------------------------------------------------# In order to cut the effect's picture correctly, there's 3 types of behavior# for a tile: wall, block and roof. Walls will make shadows as real walls,# blocks as blocks and roofs as roofs. So, the tileset tags MUST be configured.# Check the demo to understand how this system works. If the tilesets aren't# configured correctly, the script won't cut the effects correctly.So to make the script work correctly, walls need to have the terrain tag 6 and roofs 7 for example. The strange thing is, though I am changing the tile images through $game_map.data the terrain tags which should belong to the changed tile are not changed. However, the passability (x and o) are working. So I am not even 100% sure if the terrain tags are the problem. I just thought I could test this, if it was easy enough to change the terrain tags of specific tiles via x and y coordinates :(
 
Last edited by a moderator:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
How about changing the tileset on the fly?

I mean, same tileset... but different terrain tag

Does it work with khas's ligth effect?
 

nihilath

Villager
Member
Joined
Jul 6, 2014
Messages
21
Reaction score
2
Primarily Uses
Although it would be a quirky workaround, at least this should work correctly.

In that case I would need to have wall/roof/floor tile duplicates. One with a original terrain tag and one with the new tag but the same graphic. Otherwise it won't be possible to have roof tiles becoming floor and wall tiles with the correct terrain tag. So I would have to change a lot for maps and graphics.

Thanks for the tip :)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Terrain tags are not in $game_map.data - they are in $game_map.tileset.flags


If you are changing the map to use different tiles, you should not need to make any changes to the terrain tags - the old tile and new tile will have whatever tags you have given them in the tileset.


It sounds like Khas' script may not be reading the updated $game_map.data and seeing that the tile has changed?
 

nihilath

Villager
Member
Joined
Jul 6, 2014
Messages
21
Reaction score
2
Primarily Uses
It sounds like Khas' script may not be reading the updated $game_map.data and seeing that the tile has changed?
I guess that is the problem. So if there is no "one-line-easy-way" to change (and save) the terrain_tags of specific tiles, I guess I'll have to change the tilesets. Thanks! 
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
What Shaz means is that even if you had a one-line-easy-way to change terrain tags, khas' script might not pick it up.
 
Last edited by a moderator:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
It doesn't work that way.

I've checked his script here. It only reads the tag data when you enter the map. 

I'm not sure, but maybe doing this will make it load the tags again:

$game_map.setup_surfaces$game_map.merge_surfacesOr, you can always teleport to an empty map and teleport back, to make the player "re-enter" the map. That way his script will surely reload the information.
 
Last edited by a moderator:

nihilath

Villager
Member
Joined
Jul 6, 2014
Messages
21
Reaction score
2
Primarily Uses
great idea, but doesn't seem to work. Transfering the player and "refreshing" the map via $game_map.setup(map id) also doesn't work, because the changed tiles are than gone again and the map is back to its initial state. There might be a better way to "refresh" a map without changing its events and tiles that I don't know of though.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
great idea, but doesn't seem to work. Transfering the player and "refreshing" the map via $game_map.setup(map id) also doesn't work, because the changed tiles are than gone again and the map is back to its initial state. There might be a better way to "refresh" a map without changing its events and tiles that I don't know of though.
the setup method will reload the information from the map file. Try creating a copy of the setup method but without the line that loads the information from the file:

Code:
class Game_Map  def setup_copy(map_id)    @map_id = map_id#    @map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))    @tileset_id = @map.tileset_id    @display_x = 0    @display_y = 0    referesh_vehicles    setup_events    setup_scroll    setup_parallax    setup_battleback    @need_refresh = false  endend
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Bad, bad, bad idea! Did you TRY running that before posting it? If you're not going to set up the map data, where does it get set up?


Did you try just running the two commands in the post above? There's nothing in there about transferring to the map again or "refreshing" via $game_map.setup - that's not what was suggested.


You are giving up too quickly. Just because the script doesn't check constantly, doesn't mean it can't be made to. You just need to find the right method.


And yes, you will either also have to find a way to save the new settings (will require more scripts), or set up a parallel process event on the map that's conditioned by a switch that's turned on when you are ready to make the change, does the changes and calls the update for Khas' script to re-read the tags, then erases itself.
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,569
Latest member
Shtelsky
Top