Counting Steps inside Regions

Josephkhland

Extremely Hardfork
Veteran
Joined
May 20, 2015
Messages
140
Reaction score
17
First Language
Greek
Primarily Uses
RMVXA
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. 
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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?
 
Last edited by a moderator:

Josephkhland

Extremely Hardfork
Veteran
Joined
May 20, 2015
Messages
140
Reaction score
17
First Language
Greek
Primarily Uses
RMVXA
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.
 
Last edited by a moderator:

Seriel

Veteran
Veteran
Joined
Aug 16, 2014
Messages
3,013
Reaction score
504
First Language
English
Primarily Uses
Other
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? :D
 

Josephkhland

Extremely Hardfork
Veteran
Joined
May 20, 2015
Messages
140
Reaction score
17
First Language
Greek
Primarily Uses
RMVXA
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?
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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.
 

Josephkhland

Extremely Hardfork
Veteran
Joined
May 20, 2015
Messages
140
Reaction score
17
First Language
Greek
Primarily Uses
RMVXA
I am checking if it works and I will tell you.
 

Josephkhland

Extremely Hardfork
Veteran
Joined
May 20, 2015
Messages
140
Reaction score
17
First Language
Greek
Primarily Uses
RMVXA
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.

 
 

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,864
Messages
1,017,056
Members
137,573
Latest member
nikisknight
Top