Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Changing an event's graphic via script (direct assign via graphic file name)

Hugo_S

Member

Hi guys,

I would like to change the graphic of events by direct assigning via a script.

More detailled explanation:
I would like to give the player the opportunity to lay down items on the ground on each map. So I have a bunch of events (arround 30) on each map, which are only waiting for being "layed down". Accordingly they have to change their graphics. I don't want to script for several hundred items fork conditions and manual graphic changings.
So the player can't lay down more than 30 items for each map because there are only 30 events for this purpose on each map.

Then I will include this script in my inventory script. So the player can choose an item which he would like to lay down to the ground. Then an event is chosen and its graphic is changed to the specific item.

Each charset has 16 frames, so I can get 16 items out of one charset.


Thanks for your help!

Cheers
Hugo

EDIT: I have found a similiar thread: http://www.rmxp.org/forums/index.php?topic=29513.0

But unfortunately I don't understand the code which is in the FAQ:

$game_map.events[event_id].character_name = 'filename'
$game_map.events[event_id].character_hue = 0..360

I have written this in my script which I am calling:

$game_map.events[003].character_name = '002-Fighter01'
$game_map.events[003].character_hue = 0..360

It doesn't work :(

Do I have to change the "character_name" to what?

Thanks for your help!
 

khmp

Sponsor

I'm not sure what's the problem with this line unless the leading zeros in front the 3 aren't dropped. If that's the case than you can correct this mistake with:
Code:
$game_map.events[3].character_name = '002-Fighter01' # should be fine as long as event exists.

Code:
class Game_Character
  attr_accessor :character_name
end

module Map
  class << self
    def down_graphic(ext = '_down')
      return if $game_map.nil?
      $game_map.events.each_key do |id|
        next if $game_map.events[id].nil? || !$game_map.events[id].is_a?(Game_Event)
        if $game_map.events[id].character_name[ext].nil?
          $game_map.events[id].character_name = 
            $game_map.events[id].character_name + ext
        end
      end
    end
  end
end

And have an event use the following script call. Just make sure every event on the map has down graphic equivalent or you will have an error. Like 002-Fighter01 better have a file in the graphics directory called '002-Fighter01_down'. But you can change that suffix to anything as long as you change the way you call the following line of code:
Code:
Map.down_graphic

Good luck with it Hugo_S! :thumb:
 

Hugo_S

Member

Ah great now it works! :)
Thank you khmp!

So the last thing to get worked is the following: I would like to assign a single frame of the character-set, for example the third row and the second column (when the character is putting its leg one step forward) and freeze this position.

How is that possible?



P.S. This all scripting is very motivating - I now started some tutorials and its really great learning it! In this forum there are several cool tutorials I saw - I'm really happy
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top