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.

Controlling events via script

Seto

Member

Hello,

I would like to ask if anyone could help me, I want to be able to use commands you would normally do through the events pages but instead through scripting. E.g. be able to switch self switches on and off from a script.

The two commands I am interested in at the moment are,
1) changing the graphic of the event and,
2) controlling its self switches

and I do want both of them, I know you can change the graphic on the next page of the event but I want to be able to do it via scripting.

Any explanations are welcome and other event controlling commands would still be interesting and may help me to figure it out myself.

From what I could gather what I need to do would involve something along the lines of:
$game_self_switches[event and switch] = true #to turn that switch on for the event? But it would also have to tell the maps that the event is on?
or maybe something to do with $game_map.events

Thanks in advance and I apologize if this isn't clear or doesn't follow forum policies
 

Zeriab

Sponsor

1)
Insert this script anywhere above main:
[rgss]class Game_Character
  attr_writer :character_name
end
[/rgss]

If you want to change the graphic of event 2 you can now do this:
[rgss]$game_map.events[2].character_name = "030-Cleric06"
[/rgss]

2)
The syntax for doing that is:
Code:
$game_self_switches[[MAP-ID, EVENT-ID, "LOCAL-SWITCH"]] = flag value

$game_map.need_refresh = true

If you for example want to turn on self-switch A for event 2 you can do it with this code:
[rgss]$game_self_switches[[$game_map.map_id,2,'A']] = true
$game_map.need_refresh = true
[/rgss]

$game_map.map_id
will return the current map id. You can also write it explicitly.

*hugs*
- Zeriab
 

Seto

Member

Wow thanks Zeriab! That was such a quick reply and very concise. If I could trouble you with one more thing, it's not quite as important but would be helpful to me. How could I change which graphic for the character is selected? E.g. if I selected "030-Cleric06" would I also be able to select the sub graphic of him turned left on its second step? (Just trying to explain exactly what I mean) Or for that matter, is it possible to give it a move route in the same way as before to set its image? Thanks :D

Anyway thanks a bundle, your always so helpful (To everyone) :D
and if I can *Hugs Back* lol.

*Edit*
Umm sorry to bother you again Zeriab. Whenever I call any of those methods you gave me I get, syntax error at line "what ever line it was used on"
This is how I did it,
Code:
$game_map.events[2].character_name = "Grid Seeds"
and
Code:
$game_self_switches[[$game_map.map_id, eventID, "B"]] = true
or
Code:
$game_self_switches[[1, 2, "B"]] = true

I added this in its own script slot
Code:
class Game_Character

   attr_writer :character_name

 end
I also tried moving it around, first script, last above main that kind of thing.

Do you know what I am doing wrong? Also if I add a # before them the interpreter still picks them up :s. I have tried closing rmxp down and starting again, as it sometimes helps with buggy stuff like this but it continues to find them as errors no matter what... or where I put them. Sorry, I must be the worse scripter even lol!
 

Zeriab

Sponsor

You get syntax errors?
It sounds like you either copied the numbers along or you put it in a script call where the line breaks causes the syntax error.

As for getting the right sub graphic here is a quick and dirty method:
[rgss]class Game_Character
  attr_writer :character_name
 
  def subgraphic!(pattern, direction)
    # Pattern
    @original_pattern = pattern
    @pattern = pattern
    # Direction
    @original_direction = direction
    @direction = direction
  end
end
[/rgss]

pattern = 0 is the leftmost column, pattern = 3 is the right-most column.
for direction 2 = down, 4 = left, 6 = right and 8 = up.

For example:
[rgss]$game_map.events[2].character_name = "Grid Seeds"
# Second column from the left facing up
$game_map.events[2].subgraphic!(1,8)
[/rgss]

*hugs*
 

Seto

Member

Sorry I need to re-open/unreslove this topic because I have another question to do with what has been discussed and it would be silly to open a new thread right? Please let me know if I shouldn't have done this.

Zeriab":1rg96grt said:
# $game_map.events[2].character_name = "Grid Seeds"
# # Second column from the left facing up
# $game_map.events[2].subgraphic!(1,8)

Is it possible to use this/these method/s to change events on another map rather then the one your currently on?
kinda like $game_maps[map_id].events[event_id].subgraphic!(1,8)
Is there a way to do such a thing? I understand that the syntax I just wrote wouldn't work but it was the best way to show what I was talking about.

Also whenever I use this method after changing a switch the characters don't actually change, do I need to cause an update?
I have set it up like
Code:
 

$game_self_switches[[$game_map.map_id, eventID, "A"]] = true

    $game_map.need_refresh = true

    $game_map.events[eventID].character_name = 'Character'

    $game_map.events[eventID].subgraphic!(0,8)

    $game_map.need_refresh = true

 
but the graphic for the event does not change, if I remove the switch part it works (And the switch works on its own or with both of them). Is there a different kind of update that needs to be called in between the two? Thanks again!

Thanks for any replies and help everyone! :D
 

Zeriab

Sponsor

There is no easy way to change the graphic of event on a different maps like there is with the current map. The reason that whenever you transfer to a new map it is loaded again.
It would be easier to simply just add those extra pages needed. Common events can be used for sharing the event code.

For the second part with the switches, the graphic is changed. After the script call, the page of the event is changed thus changed the graphic to whatever is on that page. For that to work you need to have them as two separate script calls and with a 1 frame wait in between.

*hugs*
 

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