Counting Steps inside Regions

So I actually want a script that counts the steps a player makes a total within a certain region during a game. 
Also I want a second counter that alos counts the steps a player makes inside a region but that resets when the player leaves that region (also some switches are toggled when a certain number of steps is made).

Basicly: Counts steps made inside a region. -> May reset or not when exiting the region. 
class Game_Party


attr_reader :region_steps


alias :region_steps_initialize :initialize


alias :region_steps_increase_steps :increase_steps


def initialize


region_steps_initialize


@region_steps = {}


@last_region = 0


end


def increase_steps


region_steps_increase_steps


region = $game_map.region_id($game_player.x, $game_player.y)


(@region_steps[region] ||= [0, 0]).tap{|s| s[0] += 1; s[1] += 1}


(@region_steps[@last_region] ||= [0, 0])[1] = 0 if region != @last_region


@last_region = region


end


def total_steps(region_id)


(@region_steps[region_id] ||= [0, 0])[0]


end


def current_steps(region_id)


(@region_steps[region_id] ||= [0, 0])[1]


end


end

# Total number of steps
$game_party.total_steps(region_id)


# Current number of steps


$game_party.current_steps(region_id)

How exactly would the switch be handled? Would he constantly switch ON for every step after a certain amount or only the first time?
I want each switch to Turn on once, to commence events. when a certain number of steps is made inside the region.

Thanks for helping I really appreciate it.
class Game_Party attr_reader :region_steps alias :region_steps_initialize :initialize alias :region_steps_increase_steps :increase_steps def initialize region_steps_initialize @region_steps = {} @last_region = 0 end def increase_steps region_steps_increase_steps region = $game_map.region_id($game_player.x, $game_player.y) (@region_steps[region] ||= [0, 0]).tap{|s| s[0] += 1; s[1] += 1} (@region_steps[@last_region] ||= [0, 0])[1] = 0 if region != @last_region @last_region = region end end
Code:
# Total number of steps$game_party.region_steps[region_id][0]# Current number of steps$game_party.region_steps[region_id][1]
How exactly would the switch be handled? Would he constantly switch ON for every step after a certain amount or only the first time?
Brilliant script, would you mind if I use this? 😀
So current number of steps automatically starts counting when I enter a region , and when I call the method you typed I will get the number of steps that the player had walked inside the region since entering?
module REGION_STEPS


# region id => [number of steps, switch to turn ON]


TRIGGERS = {


1 => [100, 2]


}


end


class Game_Party


include REGION_STEPS


attr_reader :region_steps


alias :region_steps_initialize :initialize


alias :region_steps_increase_steps :increase_steps


def initialize


region_steps_initialize


@region_steps = {}


@last_region = 0


end


def increase_steps


region_steps_increase_steps


region = $game_map.region_id($game_player.x, $game_player.y)


current = (@region_steps[region] ||= [0, 0]).tap{|s| s[0] += 1; s[1] += 1}[1]


$game_switches[TRIGGERS[region][1]] = true if (TRIGGERS[region] && current == TRIGGERS[region][0])


(@region_steps[@last_region] ||= [0, 0])[1] = 0 if region != @last_region


@last_region = region


end


def total_steps(region_id)


(@region_steps[region_id] ||= [0, 0])[0]


end


def current_steps(region_id)


(@region_steps[region_id] ||= [0, 0])[1]


end


end

This will turn switch 2 ON once the player made 100 current (without moving on a different region) steps in region 1.
I am checking if it works and I will tell you.
Seems to be working. 
So if I want to add more switches to turn on I just do this:

# region id => [number of steps, switch to turn ON]

Inside the { } under it. 

Thanks . I really Appreciate it.

 

Original thread: https://forums.rpgmakerweb.com/threads/counting-steps-inside-regions.41042/