[RESOLVED] [XP] Events/Enemies Chase Script

Started by MarkHest, February 24, 2012, 04:32:42 pm

Previous topic - Next topic

MarkHest

February 24, 2012, 04:32:42 pm Last Edit: August 09, 2012, 07:41:18 pm by MarkHest
Heya! I've been thinking a lot lately about my game The Missing Part and i thought: "I realy realy realy hate random encounters, they are so freaking ANNOYING!"
But then i thought: "If i make it so that enemies walks the map instead and when you touch them you get to battle them?"

This will be a big step in my game and the script that i need will make it like this:

When you move within a specified number of frames of an event(let's say, an events 6x and 6y) the event will, from the movement course i set up, change to speed to Faster(5) and the frequency to Fastest(6) and the course will be set to follow so that when it touches the player, the event commands i put will take place. If the player manages to move out of the 5 frame range of the event the movement options will be changed back to as it first was.
The only thing that strikes my mind is, how do i make an event into this perticular kind of event? Maybe put a command in the start of the event? Maybe i can even add my own preferences in the event itself by adding comments like:

Speed 5
Frequency 6
Frames 6 (The number of frames to move within for the enemy to start chasing you)

Maybe even put a parallel animation on it if it's possible(was thinking a "!" sign that signifies that it has noticed the player)? So the command would look something like this:

Speed 5
Frequency 6
Frames 6 (The number of frames to move within for the enemy to start chasing you)
Animation [ID]  or Animation [false] (for no animation)

I am not sure how this will be possible as i am no scripter and i don't know if this requires a big script. This is how i imagined it to work, it doesn't necessarily have to be exactly like this one.


I am not expecting this to be made in just a week, but if you could find it in your heart to tell me if this is even possible to begin with so i don't have to wait in vain :shy:
   

Aqua


MarkHest

Wouln't that require TONS of parallel events on every single map i have enemies in?  8-O
Not to mention the number of switches i will have to use and to keep track of it all together.
   

Aqua

February 24, 2012, 05:37:22 pm #3 Last Edit: February 24, 2012, 06:28:41 pm by Aqua
http://dl.dropbox.com/u/23928630/EnemyChasing.zip

Um... No?
Enemies check only themselves against the player.
I didn't make hoards follow the player if one person spotted him, but I can add that.


Edit:
Didn't have time to add some more notes when I first made the post.

You only need to have that one line of setup that is in the event on map001.
And then for the enemies, you can copy and paste them.
Just have to change the graphics, movement controls (if needed), and the battle settings and stuff.

MarkHest

February 24, 2012, 07:20:46 pm #4 Last Edit: February 24, 2012, 07:50:51 pm by Darth Hairspray
I hate no idea what those scripts in the Event Commands do :xD:
However, this seem to work perfect and it's EXACTLY what i wanted! :)


There's is just one thing. Is it possible to make the enemies stop when they reach the player and not run around him/her like they do?
Pretty sure i fixed this part by splitting the "player touch" part(aheam..) into a separate event page and made it "Autorun" instead of a Parallel process. Naturaly i altso had to turn off the self swich at the end of the event.


EDIT: Altso, the enemies should reapear when i exit/enter the map. I messed around a bit but i'm not sure how to find a solution.
Nevermind, i fixed that too :xD: I just made an "erase event" instead of swiching to a new self switch.


It now works EXACTLY like i want it to! Thank you so much Aqua for taking time to help me! :cclove:
   

Aqua

Oh right... forgot about erasing events... lol

Want me to add anything else or explain the code stuff?

MarkHest

nope, everything works as it should and it's still going to take some time before i understand coding at all :roll: (I'm working on it).

Thank you once again  :clap:
   

MarkHest

Uhm, after a long time I actually found a bug with this. The line: $monster_dist_thresh = 6 resets whenever I exit the engine and re-open it to load a saved game. So I actually have to create a new event which activates the call script command again everytime I load a saved game after closing the engine.
Know any way around this? :uhm:
   

ForeverZer0

Add this:

class Game_System
  attr_accessor :monster_dist_thresh
end


Now replace all instances of $monster_dist_thresh with $game_system.monster_dist_thresh
   
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

MarkHest

So i will make a new script with this?

class Game_System
  attr_accessor :monster_dist_thresh
end


Man, i've already placed so many enemies around the maps. Replacing this line on every single event will be so much work :xD:

oh well, i'll report the resoults when i have a chance to test it, thanks :)
   

ForeverZer0

August 06, 2012, 06:36:50 pm #10 Last Edit: August 06, 2012, 06:58:21 pm by ForeverZer0
I can make a script that iterates through all your maps and changes the event's script calls for you, it would only take a second

EDIT:
Here it be. Hopefully you didn't already go and change everything manually...

# Define the input and output strings.
INPUT = "$monster_dist_thresh"
OUTPUT = "$game_system.monster_dist_thresh"

#===============================================================================
count = 0
Dir.entries('Data').each {|filename|
  if filename =~ /Map[\d]+\.rxdata/
    changed = false
    map = load_data("Data/#{filename}")
    map.events.each_key {|key|
      event = map.events[key]
      event.pages.each_index {|i|
        page = event.pages[i]
        page.list.each_index {|j|
          cmd = page.list[j]
          next unless [355, 655].include?(cmd.code)
          if event.pages[i].list[j].parameters[0].include?(INPUT)
            count += 1
            event.pages[i].list[j].parameters[0].gsub!(INPUT) { OUTPUT }
            map.events[key] = event
            changed = true
          end
        }
      }
      if changed
        File.open("Data/#{filename}", 'wb') {|file| Marshal.dump(map, file) }
      end
    }
  end
}
if count == 0
  print "No event script calls found with matching string."
else
  print "Found and replaced #{count} occurences of input string.\n" +
    "Make sure to close and reload your project in order for the effects " +
    "take place. DO NOT SAVE THE GAME when closing or nothing will change."
end
exit
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

MarkHest

This does not work. $game_system.monster_dist_thresh does not make the script call in the events recognise the code. It gives me the error: Comparison of float with nil failed. This is the error i get if i walk to a map with a patrolling enemy without using the code $monster_dist_thresh.

$game_system.monster_dist_thresh Does not give that effect and i get that error I just told about.

Edit: Oh, and that new script you made worked.
   

ForeverZer0

Sorry, I made the assumption that there was actually a script that set the initial value of $monster_dist_thresh.

This will fix it:

class Game_System
  attr_accessor :monster_dist_thresh
  alias monster_dist_init initialize
  def initialize
    @monster_dist_thresh = 6
    monster_dist_init
  end
end
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

MarkHest

Nope, I still get the float error. $game_system.monster_dist_thresh still isn't taking effect.
   

ForeverZer0

Are you running this from a save game, or a new game?
If its a new game, then it makes no sense unless a script below it is overwriting all of the Game_System initialize method.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

MarkHest

August 08, 2012, 05:44:28 pm #15 Last Edit: August 08, 2012, 06:03:28 pm by MarkHest
I tried both New game and a Saved game and the script is furthest down in the list (above Main of course).
   

ForeverZer0

That doesn't make sense. Short of not using Game_System, the only possible way that could happen is if you are setting $game_system.monster_dist_thresh to nil somewhere after being initialized. There is no other possibility.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

MarkHest

Honestly, I don't know. Maybe a possible solution would be to add the Spotted-Range with a Variable? But I guess I'll have to change the call scripts used in the Patrolling Enemies then, if it's a possible solution i will do it.
   

diagostimo

i tested what foreverzer0 added with the original demo that aqua posted and it worked fine, theres definatly something breaking it in your project

MarkHest

August 08, 2012, 07:54:06 pm #19 Last Edit: August 08, 2012, 08:02:36 pm by MarkHest
Strange! :O.o:

Let me test out a few things...




EDIT: Nope, I tested it out on a new project and $game_system.monster_dist_thresh still isn't doing what $monster_dist_thresh does.
And if I use $monster_dist_thresh instead it won't be saved when I restart the engine, like I explained before.

Are you sure I don't have to change anything in the call scripts of the patrolling events?