VX Caterpillar System by Woratana

posted on 16 Feb 2009 16:55 by boxsuke  in Resources, ScriptsVX, WoraScripts

* สคริปต์สร้างตัวละครในปาร์ตี้เดินตามเราฮะ มีตัวเดินตามได้ไม่จำกัด =w=/ ขึ้นอยู่กับว่าในปาร์ตี้มีกี่คนอะน้อ~อันนี้ลองเขียนอะน้อ ถ้ามีบั๊กอะไรช่วยแจ้งด้วยฮะ ^^/ โค้ดแค่ 200 บรรทัดเองอะ หุหุ (ถ้าไม่นับคอมเม้นท์ก็ 150 กว่าบรรทัดเอง~) สคริปต์อยู่ด้านล่างน้อ เลื่อนลงไปเล้ย~

 

Caterpillar System
Version 2.0
by Woratana
Release Date: 02/03/2009


Introduction
It's just that one day I feel like scripting caterpillar system. I've never done it before, and it would teach me something.

So I tried, and here is the result.

It's probably need more work to make it perfect. tongue.gif Because I think my algorithm so far is not the best one.
Please let me know if you find any bugs. ^^/

Enjoy~^^


Features
Version 2.0
- Fix direction bug
- Fix vehicle bug
- Add max following members
- Fix dash bug
- More compatible with script that edit Spriteset_Map.create_characters
Version 1.0
- Unlimited following members
- Switch to hide/show following members temporarily


Screenshots



Script
#===============================================================
# ● [VX] ◦ Plug 'n Play Caterpillar System ◦ □
# * Create party members follow the player on map *
#--------------------------------------------------------------
# ◦ by Woratana [woratana@hotmail.com]
# ◦ Thaiware RPG Maker Community
# ◦ Released on: 29/02/2009
# ◦ Version: 2.0
#--------------------------------------------------------------
# ◦ Update:
#--------------------------------------------------------------
# □ Version 2.0 (29/02/2009)
# - Fix direction bug
# - Fix vehicle bug
# - Add max following members
# □ Version 1.5 (17/02/2009)
# - Fix dash bug
# - More compatible with script that edit Spriteset_Map.create_characters
#--------------------------------------------------------------
# ◦ Compatibility:
#--------------------------------------------------------------
# □ This script will rewrite 0 method(s):
#
#
# □ This script will alias 14 method(s):
#     Spriteset_Map.create_characters
#     Spriteset_Map.update_characters
#     Game_Player.move_down
#     Game_Player.move_left
#     Game_Player.move_right
#     Game_Player.move_up
#     Game_Player.move_lower_left
#     Game_Player.move_lower_right
#     Game_Player.move_upper_left
#     Game_Player.move_upper_right
#     Game_Player.jump
#     Game_Player.get_off_vehicle
#     Game_Player.moveto
#     Game_Map.setup
#
# □ This script should work with most scripts
#
#--------------------------------------------------------------
# ◦ Installation:
#--------------------------------------------------------------
# 1) This script should be placed JUST BEFORE ▼ Main Process.
#
# □ Like this:
# ▼ Materials
# ...
# ...
# * Caterpillar System
# ▼ Main Process
# Main
#
# 2) Setup this script in Setup Part below.
#
#--------------------------------------------------------------
# ◦ How to use:
#--------------------------------------------------------------
# □ Place this script and setup in the setup part.
#
#=================================================================

module Wora

  #=================================================================
  # ++ Setup Part
  #-----------------------------------------------------------------

  CATERPILLAR_HIDE_SWITCH = 1
  # Turn ON this switch to HIDE caterpillar actors
  # Turn OFF this switch to SHOW caterpillar actors

  CATERPILLAR_MAX_ACTORS = 5
  # Maximum number of the following actors

  #-----------------------------------------------------------------

  def self.add_upd_cater(code = nil)
    # Add new move action to caterpillar
    $game_cateracter.each_index do |i|
      act = $game_cateracter[i]
      eval($cater_movelist[$cater_movelist.size - 1 - i])
    end
    $cater_movelist.shift
    $cater_movelist.push(code) unless code.nil?
  end

  def self.reset_cater_pos
    # Reset caterpillar position
    $game_cateracter.each_index {|i| $game_cateracter[i].refresh }
    $cater_movelist = Array.new(Wora::CATERPILLAR_MAX_ACTORS - 1) {''}
  end
end

class Game_WCateracter < Game_Character
  attr_accessor :actor

  def initialize(member_id)
    super()
    @wmember_id = member_id
    refresh
  end

  def update(*args)
    super(*args)
    actor = $game_party.members[@wmember_id]
    unless actor.nil?
      @character_name = actor.character_name
      @character_index = actor.character_index
      @transparent = ($game_switches[Wora::CATERPILLAR_HIDE_SWITCH] or
    $game_player.in_vehicle? or $game_player.transparent)
      @opacity = $game_player.opacity
      @move_speed = $game_player.move_speed + ($game_player.dash? ? 1 : 0)
    else
      @character_name = ''
      @character_index = 0
    end
  end

  def screen_z
    return $game_player.screen_z
  end

  def check_event_trigger_touch(x, y)
    return false
  end

  def passable?(x, y)
    return true
  end

  def refresh
    @direction = $game_player.direction
    moveto($game_player.x, $game_player.y)
  end
end

class Spriteset_Map
  alias wora_cater_sprmap_crechara create_characters
  alias wora_cater_sprmap_updchara update_characters
  #--------------------------------------------------------------------------
  # * Create Character Sprite
  #--------------------------------------------------------------------------
  def create_characters(*args)
    wora_cater_sprmap_crechara(*args)
    # Remove Game_Player sprite, this will be add later
    ((@character_sprites.size-1)..0).each do |i|
      next if @character_sprites[i].nil?
      if @character_sprites[i].character.is_a?(Game_Player)
        @character_sprites[i].dispose
        @character_sprites.delete_at(i)
        break
      end
    end
    # Create party members sprite
    (1..(Wora::CATERPILLAR_MAX_ACTORS-1)).each do |n|
      @character_sprites.push(Sprite_Character.new(@viewport1, $game_cateracter[n-1]))
    end
    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
  end
  #--------------------------------------------------------------------------
  # * Update Character Sprite
  #--------------------------------------------------------------------------
  def update_characters(*args)
    $game_cateracter.each {|cater| cater.update }
    wora_cater_sprmap_updchara(*args)
  end
end

class Game_Player < Game_Character
  attr_reader :move_speed
  unless method_defined?('wora_cater_gampla_movdown')
    alias wora_cater_gampla_movdown move_down
    alias wora_cater_gampla_movleft move_left
    alias wora_cater_gampla_movright move_right
    alias wora_cater_gampla_movup move_up
    alias wora_cater_gampla_movll move_lower_left
    alias wora_cater_gampla_movlr move_lower_right
    alias wora_cater_gampla_movul move_upper_left
    alias wora_cater_gampla_movur move_upper_right
    alias wora_cater_gampla_jump jump
    alias wora_cater_gampla_getoffveh get_off_vehicle
    alias wora_cater_gampla_moveto moveto

    #--------------------------------------------------------------------------
    # * Move Down
    #--------------------------------------------------------------------------
    def move_down(turn_ok = true)
      wora_cater_gampla_movdown(turn_ok)
      Wora.add_upd_cater("act.move_down(#{turn_ok})") unless @move_failed
    end
    #--------------------------------------------------------------------------
    # * Move Left
    #--------------------------------------------------------------------------
    def move_left(turn_ok = true)
      wora_cater_gampla_movleft(turn_ok)
      Wora.add_upd_cater("act.move_left(#{turn_ok})") unless @move_failed
    end
    #--------------------------------------------------------------------------
    # * Move Right
    #--------------------------------------------------------------------------
    def move_right(turn_ok = true)
      wora_cater_gampla_movright(turn_ok)
      Wora.add_upd_cater("act.move_right(#{turn_ok})") unless @move_failed
    end
    #--------------------------------------------------------------------------
    # * Move up
    #--------------------------------------------------------------------------
    def move_up(turn_ok = true)
      wora_cater_gampla_movup(turn_ok)
      Wora.add_upd_cater("act.move_up(#{turn_ok})") unless @move_failed
    end
    #--------------------------------------------------------------------------
    # * Move Lower Left
    #--------------------------------------------------------------------------
    def move_lower_left
      wora_cater_gampla_movll
      Wora.add_upd_cater('act.move_lower_left') unless @move_failed
    end
    #--------------------------------------------------------------------------
    # * Move Lower Right
    #--------------------------------------------------------------------------
    def move_lower_right
      wora_cater_gampla_movlr
      Wora.add_upd_cater('act.move_lower_right') unless @move_failed
    end
    #--------------------------------------------------------------------------
    # * Move Upper Left
    #--------------------------------------------------------------------------
    def move_upper_left
      wora_cater_gampla_movul
      Wora.add_upd_cater('act.move_upper_left') unless @move_failed
    end
    #--------------------------------------------------------------------------
    # * Move Upper Right
    #--------------------------------------------------------------------------
    def move_upper_right
      wora_cater_gampla_movur
      Wora.add_upd_cater('act.move_upper_right') unless @move_failed
    end
    #--------------------------------------------------------------------------
    # * Jump
    #--------------------------------------------------------------------------
    def jump(x, y)
      wora_cater_gampla_jump(x, y)
      Wora.add_upd_cater("act.jump(#{x},#{y})")
    end
    #--------------------------------------------------------------------------
    # * Get Off Vehicle
    #--------------------------------------------------------------------------
    def get_off_vehicle(*args)
      wora_cater_gampla_getoffveh(*args)
      Wora.reset_cater_pos
    end
    #--------------------------------------------------------------------------
    # * Move to Designated Position
    #--------------------------------------------------------------------------
    def moveto(*args)
      wora_cater_gampla_moveto(*args)
      Wora.reset_cater_pos
    end
  end
end

class Game_Map
  attr_accessor :events

  alias wora_cater_gammap_setup setup
  def setup(*args)
    wora_cater_gammap_setup(*args)
    # Create caterpillar actors
    $game_cateracter = []
    (1..(Wora::CATERPILLAR_MAX_ACTORS-1)).each do |n|
      $game_cateracter.push(Game_WCateracter.new(n))
    end
    $cater_movelist = Array.new(Wora::CATERPILLAR_MAX_ACTORS - 1) {''}
  end
end
 
 
Instruction
- Setup script in the SETUP part
- The complete instruction is included in the script


Author's Notes
Free for use in your work if credit is included.
If you want to post it on any forum, please link to this topic.


Bug Report?
Please give me these informations:
QUOTE
- What is it says in error window?
- When is it get error? (Right after run game, when you choose something, etc.)
- What have you changed in setting part?
- Do you have any other scripts running in your game that may crash with this script?

 

 

edit @ 2 Mar 2009 20:43:36 by [+Boxsuke+]

Comment



smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry

Tweet

อ่าฮะ +0+ ผมมีแล้วงิ 55+ แต่ว่ารู้สึกมันจะมีบัค เดวเอาของพี่ลองก่อนนะ +.+

ขอบคุณสำหรับ Window note ด้วยงิ +.+

#1 By ๏Luvi๏`KunG (124.121.58.254) on 2009-02-16 21:47

Nice Wora^^

#2 By Rafidelis (187.25.156.64) on 2009-02-19 01:46

cool, but my game still error

#3 By (125.160.50.52) on 2009-02-21 15:35

Ow man, sorry. I don't see if i must turn off the switch. Thank You! Very nice Wora ^_^

#4 By (125.160.50.52) on 2009-02-21 15:39

Make it support PR ABS!!! PLEASE!!!! :D:D:D:D
Link to PR ABS:
http://www.rmxp.org/forums/viewtopic.php?f=11&t=56154

#5 By acrox999 (60.48.97.68) on 2009-02-23 10:33

Hey, nice script, and nice site, too but there is one glitch. When you run, the characters bounce. :/.

#6 By Craig. (96.243.183.149) on 2009-02-26 10:19

I will fix that bug pretty soon. Wait for next update. ^^

#7 By [+Boxsuke+] on 2009-02-26 22:47

This script conflicts with KGC_TilesetExtension. The methods involving collision that I discovered are:
Game_Player.move_down
Game_Player.move_left
Game_Player.move_right
Game_Player.move_up
Game_Player.move_lower_left
Game_Player.move_lower_right
Game_Player.move_upper_left
Game_Player.move_upper_right

#8 By Yanfly (74.160.6.73) on 2009-03-06 07:06

#8 I fixed it by:

Go find:
def passable?(x, y)

in Caterpillar script

Change it to:
def passable?(*args)

--------------------------------
I guess I should also fix the script on this entry. confused smile

#9 By [+Boxsuke+] on 2009-03-06 09:03

Hey man.. my game gives me this message

"Script 'follow_leader' (thats what i named it) line 141: NameError Occurred

undefined method 'create characters' for class 'Spriteset Map'

If you have a solution could you message me at rockercell@yahoo.com

#10 By Marcel (71.166.113.232) on 2009-03-26 08:01

Hello i am using you script but i still dont know how to get more than 4 people. could you tell me how?
sad smile

#11 By madmaz (81.193.84.25) on 2009-04-07 04:33

Thx!! i was searching sumthing like this! big smile

#12 By Kaaji (189.133.194.180) on 2009-04-12 01:26

Hey I have a really nasty problem that I dont even understand why it happens =/

When I sent my demo to 3 people all 3 of them get this error


Script 'Catepillar' line 159: NoMethodErrorOccured
undefined method [} for nil:NilClass

It always plays fine but when they try to load a saved game after having people in your party and they follow you around that error always seems to go out
and I never editted anything on that line either =/ Any help? angry smile

#13 By Kenta (67.191.13.20) on 2009-04-16 10:49

I have an error:S
The error say:
Script 'xy' line 97: Type error occurred
Undefined superclass 'Game_Character'

well,if i delet line 97 it say other line and so on...

#14 By Gamexandy (86.101.132.67) on 2009-04-17 23:52

AWESOME! I've always looked for a Caterpillar Script that actually works! And here it is! THANK YOU SO MUCH!open-mounthed smile

#15 By (75.174.198.220) on 2009-04-27 11:10

Hey, this script actually works!
It's very nice.

#16 By Bobbyno (90.206.33.223) on 2009-05-03 17:29

Awesome script, as are all of your scripts! Since I ain't a scripter (yet!) was trying to figure out how to have a caterpillar without success. It appears, though, that the script "resets" when teleporting from map to map and the other characters no longer form the caterpillar.

#17 By FereWulf (64.180.169.57) on 2009-05-09 16:30

I love this script its awesome!

#18 By Rentual (122.107.52.234) on 2009-07-10 17:50

Big fan of your work

#19 By makiemakie (173.31.6.125) on 2009-07-11 01:41

Very Nice script, here. Thank you very much for sharing it.

Also I have a question. Is it(or would it be)possible to add characters to the caterpillar, but not to the actual party?

#20 By (173.49.7.29) on 2009-07-14 08:45

weird the following characters diseapear as soon as I enter another map.

#21 By evilslime@hotmail.com (173.176.55.226) on 2009-08-12 11:06

It works but when i have an event, the characters dissapear and never come back. the event is text and the player moves down. is ther something wrong?

#22 By Booomshika (69.110.132.124) on 2009-08-21 11:26

i han hardly understand these instructions.. maby i need to learn more.. but i realy with you had better instructions on how to say, activate everything????

#23 By eyru (24.164.62.180) on 2009-08-27 18:01

Hey! thanks for the good script, works fine ,
one small bug is that if you turn on switch 1 in an event it will make the party members "disappear"(as in not folllowing you),
this only happens with switch one though, weird :S

#24 By MartPesk (81.207.100.251) on 2009-09-12 03:36

Hi
Thank you so much for putting this up!

But, after I have put it into the script section and test my game, it immediately says
"script''line 29: SyntaxError occurred"

Please can you help me
Have I put it in the script part incorrectly?


Thanks -Nikki

#25 By Nikki S. (99.238.180.103) on 2009-10-12 03:19

Hi
Thank you so much for putting this up!

But, after I have put it into the script section and test my game, it immediately says
"script''line 29: SyntaxError occurred"

Please can you help me
Have I put it in the script part incorrectly?


Thanks -Nikki

#26 By Nikki S. (99.238.180.103) on 2009-10-12 03:19

Script work fine expect when I load a game.

The error I get is similar to Kenta's (67.191.13.20) on 2009-04-16 10:49.

Why would it crash? Strange...

#27 By Okogawa (83.185.84.55) on 2009-12-05 00:24

i get this error
"script 'Caterpillar' line 92: NoMethodError occured
undefined method `each_index' for nil:NilClass"

#28 By Zero (93.107.151.26) on 2009-12-31 06:47