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,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
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,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
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.

 
 

Latest Threads

Latest Posts

Latest Profile Posts

Ugh... 4:53AM over here and I can't sleep so why not just game make.
I just love the MV feature that allows you to create your own animations!
I typically ask this on my normal social media channels, but figured there may be good replies here. Anyone got any good horror movie recommendations? I've seen a lot, but I always love getting suggestions! Bonus points if you know which service it is streaming on (in the US) - bring on the spOoooOky!
 After a few distractions (and my annual rough second week of October), I’m getting back on track with my OMGC project.
 Am I overcomplicating it? Yes. Am I going to tone it down? Almost certainly not.
 At least the dialogue stuff is almost done. I need to do the map itself, and then all that’s left is combat.
 Getting there!

Forum statistics

Threads
115,910
Messages
1,093,894
Members
151,159
Latest member
rlawlsrjs3387
Top