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.

Script snippets for the eventer

Zeriab

Sponsor

Hey all!

This topic is for scripts snippets made specifically for providing extra building blocks. Both scripts to you have copy-paste and scripts which are small to fit in the call script window are fine.
Here is for example a snippet I cooked up which can help in spicing up battles:

[rgss]class Interpreter
  ##
  # Battler id (-1 returned when not in battle)
  #
  def get_battler_id(variable=id)
    unless $game_temp.in_battle
      return $game_variables[variable] = -1
    end
    $game_variables[variable] = $scene.get_active_battler_id
    return
  end
 
  ##
  # Battler id (-1 returned when not in battle)
  #
  def get_battler_index(variable=id)
    unless $game_temp.in_battle
      return $game_variables[variable] = -1
    end
    $game_variables[variable] = $scene.get_active_battler_index
    return
  end
 
  ##
  # Battler enemy? (Return false when not in battle)
  #
  def is_battler_enemy?(switch=id)
    unless $game_temp.in_battle
      $game_switches[switch] = false
      return true
    end
    $game_switches[switch] = $scene.instance_eval("@active_battler.is_a?(Game_Enemy)")
    return true
  end
end
 
class Scene_Battle
  ##
  # Return the index of the current active battler. (-1 with no active battler)
  #
  def get_active_battler_id
    unless @active_battler.nil?
      return @active_battler.id
    end
    return -1
  end
 
  ##
  # Return the index of the current active battler. (-1 with no active battler)
  #
  def get_active_battler_index
    unless @active_battler.nil?
      return @active_battler.index
    end
    return -1
  end
end
[/rgss]

You can then use a script call where you call the methods. It could for example be:
[rgss]get_battler_id(2)
get_battler_index(3)
is_battler_enemy?(1)
[/rgss]

get_battler_id(2) will set variable 2 to be the id of the battler. (The one they have in the database) this is the one you'll want.
get_battler_index(3) will set variable 3 to the index of the battler. If Arshes is the left-most hero then the index will be 0, then 1, then 2, etc.
is_battler_enemy?(1) will set switch 1 to ON if the battler is an enemy and OFF otherwise.

When I talk about battler I talk about the one who triggered common event. I.e. the one doing the skill.

*hugs*
- Zeriab
 
First off thanks this is pretty neat

I was wondering if this could be modified(reversed actually) to change the current battler id, thereby shifting control to someone else?
 
Here are some pretty simple snippets that should be very useful to any eventer.

Code:
module REGI_EVENTS

  

  # self switch (value can be true, false)

  def selfswitch(id = 0, key = "A", value = true)

    if id <= 0 and (@event_id != nil or @id != nil)

      ev = (@event_id != nil ? @event_id : @id)

      k = [$game_map.map_id, ev, key]

    else

      k = [$game_map.map_id, id, key]

    end

    value = nil if value == false

    $game_self_switches[k] = value

    $game_map.need_refresh = true

  end

  

  # toggle switch

  def toggle(id = 1)

    $game_switches[id] = !$game_switches[id]

  end

  

  # add one to variable

  def addvar(id = 1)

    $game_variables[id] += 1

  end

  

  # batch switch (value can be true, false, or toggle)

  def batch(a = 1, b = 1, value = true)

    for i in a..b

      if value == "toggle"

        toggle(i)

      else

        $game_switches[i] = value

      end

    end

  end

end

 

class Interpreter

  include REGI_EVENTS

end

class Game_Character

  include REGI_EVENTS

end

Now you can use the following in script calls:
Selfswitch call
Description: Turns an event self-switch on or off.
Call:
selfswitch(id, key, value)

id: event id (leave 0 for current event)
key: self-switch letter "A", "B", "C", or "D" (by default, it is "A")
value: true or false (by default, it is true)


Toggle switch
Description: Toggles a switch (if true, turns false; if false, turns true).
Call:
toggle(id)

id: switch id


Add variable
Description: Adds one to a variable. Useful for counters (steps, enemies killed, etc).
Call:
addvar(id)

id: variable id


Batch Switch
Description: Turns multiple switches on, off, or toggles them.
Call:
batch(a, b, value)

a: first switch
b: last switch
value: true or false or toggle (by default, it is true)

selfswitch(2, "B", false)
Turns Event #2, self-switch "B" off.

selfswitch(3)
Turns Event #3, self-switch "A" on.

selfswitch
Turns this event, self-switch "A" on.

toggle(5)
Toggles switch #5.

addvar(27)
Adds one to variable 27.

batch(2, 9)
Turns switches 2-9 on.

batch(1, 2, toggle)
Toggles switches 1 and 2.

If you notice, I used a module and included it in both class Interpreter and Game_Character. This allows the methods to be called in both normal "Call Script" and in "Set Move Route: Script". Hope this helps!
 
Updated above post with a few fixes and some examples. I hope this is useful to someone out there; and feel free to drop off requests or suggestions for other calls to ease eventing!
 
I was planning to write a manual that shows how can a eventer explore and use a lot of things from rgss, but i think it will never be completed...so:

This is a list that show how to call event command with scripts calls. This can be used to recover some missed functions , like the hability to equip a weapon setting its id by a event variable.

Equip weapon:

@parameters[0] = actor id to equip
@parameters[1] = 0
@parameters[2] = weapon id to equip
command_319

Elections

@parameters[0] = []
@parameters[0].push 'Opcion 1'
@parameters[0].push 'Opcion 2'
@parameters[0].push 'Opcion 3'
@parameters[0].push 'Opcion 4'
@parameters[1] = v

command_102


v =Option when cancel

v:

0: invalidate
1: option 1
2: 2
3: 3
4: 4
election number+1:create tree

Wait
@parameters[0] = frames
command_106

Call common event
@parameters[0] = event id
command_117

Switchs
@parameters[0] = Start of switch list to operate
@parameters[1] = end of list
@parameters[2] = v
command_121

v = 0: Active
v= 1: Desactive

Note: If you only select a switch you have to put the same id in parameter 0 and 1:

Variables
@parameters[0] = start of list to operate
@parameters[1] = end list
@parameters[2] = v3
@parameters[3] = v
@parameters[4] = v2
command_121

Variable type

v = 0: Constant
v = 1: Variable
v = 2: Random
v = 3: Item
v = 4: Actor
v = 5: Enemy
v = 6: Actor
v = 7: Other

Variable subtype

v2: You have to check by yourself the value needed. If you select actor and then HP, the subtipe value will be the position in the list -1. In this example Hp will be v2=2

For constant type, here you write the value to operate.

Operation type:

v3:
v3 = 0: Substiuite
v3 = 1: +
v3 = 2: -
v3 = 3: *
v3 = 4: /
v3 = 5: Resto, %

Note2: Random:
@parameters[5] = Start random range
@parameters[4] = End random range

Note3: If you only select a variable you have toput the same id in the first and last of the list
@parameters[0] = 3
@parameters[1] = 3



Time:
@parameters[0] = v
@parameters[1] = time
command_124
v = 0 : start
v = 1: stop

The TRICK here is use $game_variable[id]. With this you can acces a event variable with scripts. So if you call...


@parameters[0] = $game_variables[3]
@parameters[1] = 0
@parameters[2] = $game_variables[2]
command_319

You are equiping a weapon to the actor that have the id contained on the variable 3 and the weapon with the id that have the variable 2.

This might be useful to create some engines . It will let you evade the use of a lot of conditions to check doing one thing or other, now working withs ids is more simple
 
Something I thought I should mention is that when you use the call script function, you can actually use instance variables. That means that you should never, ever use @index in your event unless you want very weird, and usually bad things to happen. However, if you made, say, @counter, and had a call script that was @counter += 1, (after it was already set), you could make another call script later on (while the same was still open, and hadn't been closed and reopened) that would print out an accurate value. (I.E., if it was initially set to zero, and you used that bit I just mentioned, if you put p @counter, a little window with 1 would appear on the screen)
 

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