Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Airship Events, Allowing the airship to conditionally trigger events
Mauron
post Aug 11 2010, 03:02 AM
Post #1


Level 1
Group Icon

Group: Member
Posts: 11
Type: Scripter
RM Skill: Beginner




Airship Events and Collisions

Version 1.0
Author Mauron
Release Date 8/11/2010




Introduction
After learning that the airship did not have any normal event interaction, I deciced to upgrade it to have optional interaction.

This is my first publicly released script, so any feedback would be appreciated. I aliased old methods (when I thought) possible, and rewrote them the rest of the time.

Features
- The airship can now interact with events.
- The airship can now collide with "above player" events and tiles.

Script
The script!
CODE
#################################################################
###############
#
# Place this script in the materials section.
# Created by Mauron, 8/11/2010
# Version 1.0
#
################################################################################
module AirshipEventSettings
AirshipEventCollisions = false
AirshipTileCollisions = false
end

class Game_Character
alias :maurons_old_collide_with_characters? :collide_with_characters?
def collide_with_characters?(x, y)
if @vehicle_type == 2
return true if $game_map.airship.pos_nt?(x, y)
for event in $game_map.events_xy(x, y) # Matches event position
unless event.through # Passage OFF?
return false unless AirshipEventSettings::AirshipEventCollisions
return true if event.priority_type == 2 # Target is above char
end
end
return false
else
maurons_old_collide_with_characters?(x, y)
end
end
end

class Game_Player < Game_Character
def map_passable?(x, y)
case @vehicle_type
when 0 # Boat
return $game_map.boat_passable?(x, y)
when 1 # Ship
return $game_map.ship_passable?(x, y)
when 2 # Airship
return true unless AirshipEventSettings::AirshipTileCollisions
return $game_map.airship_passable?(x, y)
else # Walking
return $game_map.passable?(x, y)
end
end

def get_on_airship
@vehicle_getting_on = true # Start boarding operation
@vehicle_type = 2 # Set vehicle type
@walking_bgm = RPG::BGM::last # Memorize walking BGM
$game_map.airship.get_on # Boarding processing
end

def check_touch_event
return check_event_trigger_here([1,2])
end

def check_action_event
return true if check_event_trigger_here([0])
return check_event_trigger_there([0,1,2])
end

def check_event_trigger_here(triggers)
return false if $game_map.interpreter.running?
result = false
for event in $game_map.events_xy(@x, @y)
if triggers.include?(event.trigger)
if in_airship? and event.air_accessible
event.start
result = true if event.starting
elsif !in_airship? and event.land_accessible
event.start
result = true if event.starting
end
end
end
return result
end

def check_event_trigger_there(triggers)
return false if $game_map.interpreter.running?
result = false
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
for event in $game_map.events_xy(front_x, front_y)
if triggers.include?(event.trigger)
if !in_airship? and event.land_accessible
event.start
result = true
elsif in_airship? and event.air_accessible
event.start
result = true
end
end
end
if result == false and $game_map.counter?(front_x, front_y)
front_x = $game_map.x_with_direction(front_x, @direction)
front_y = $game_map.y_with_direction(front_y, @direction)
for event in $game_map.events_xy(front_x, front_y)
if triggers.include?(event.trigger) and event.priority_type >= 1
if in_airship? and event.air_acFcessible
event.start
result = true if event.starting
elsif !in_airship? and event.land_accessible
event.start
result = true if event.starting
end
end
end
end
return result
end

def check_event_trigger_touch(x, y)
return false if $game_map.interpreter.running?
result = false
for event in $game_map.events_xy(x, y)
if [1,2].include?(event.trigger) and event.priority_type >= 1
if in_airship? and event.air_accessible
event.start
result = true
elsif !in_airship? and event.land_accessible
event.start
result = true
end
end
end
return result
end
end

class Game_Event < Game_Character
attr_accessor :air_accessible
attr_accessor :land_accessible

alias :maurons_old_initialize :initialize
def initialize(map_id, event)
maurons_old_initialize(map_id, event)
if @event.name[/AirOnly/i]
@air_accessible = true
@land_accessible = false
elsif @event.name[/AirYes/i]
@air_accessible = true
@land_accessible = true
else
@air_accessible = false
@land_accessible = true
end
end
end

class Game_Map
def airship_passable?(x, y)
for event in $game_map.events_xy(x, y) # Matches event position
unless event.through # Passage OFF?
return false if event.priority_type == 2 # Target is above char
end
end
return true if $game_map.airship.pos_nt?(x, y)
return passable?(x, y, 0x00)
end

def passable?(x, y, flag = 0x01)
for event in events_xy(x, y) # events with matching coordinates
next if event.tile_id == 0 # graphics are not tiled
next if event.priority_type > 0 # Same as characters
next if event.through # pass-through state
pass = @passages[event.tile_id] # get passable attribute
if pass & 0x10 == 0x10 # *: Airship collide
if $game_player.vehicle_type == 2
return false
else
next
end
end
return true if pass & flag == 0x00 # o: Passable
return false if pass & flag == flag # x: Impassable
end
for i in [2, 1, 0] # in order from on top of layer
tile_id = @map.data[x, y, i] # get tile ID
return false if tile_id == nil # failed to get tile: Impassable
pass = @passages[tile_id] # get passable attribute
if pass & 0x10 == 0x10 # *: Airship collide
if $game_player.vehicle_type == 2
if tile_id == 0
next
else
return false
end
else
next
end
end
return true if pass & flag == 0x00 # o: Passable
return false if pass & flag == flag # x: Impassable
end
return false # Impassable
end
end


Customization
AirshipEventCollisions: Set to true if you want events that are above the player to block the airship.
AirshipTileCollisions: Set to true if you want tiles marked with a * to block the airship

Compatibility
No known compatibility issues at this time.

DEMO
Download Now!
The demo has AirshipEventCollisions and AirshipTileCollisions both set to true.

Installation
Place the script in the matiarials section. Add "AirOnly" to the name of any events that should only be accessible by airship, and "AirYes" to the name of any events that should be accessible by the player and the airship. Quotation marks are not necessary.

Terms and Conditions
Use or modify as you desire, but credit the original author somewhere.


__________________________
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 18th May 2013 - 01:19 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker