hey there, i have been making a script to manage pushing movable object, the main part of it is changing the events previous x and y as unpassable until the event has finished moving, this is so that the event cant be spammed and so the graphics doesnt overlap the player while its moving to the next tile, heres my script:
class Interpreter
#--------------------------------------------------------------------------
# * push_object(event to push)
#--------------------------------------------------------------------------
def push_object(event_id)
#set event to push
event = $game_map.events[event_id]
# store x and y
old_x, old_y = event.x, event.y
#push the info into array
$game_system.movable_object.push([event_id, old_x, old_y])
p $game_system.movable_object
#p $game_system.movable_object
#event move down if player direction is 2 and event can enter the tile
event.move_down if $game_player.direction == 2 &&
$game_map.passable?(event.x, event.y + 1, 8)
#event move left if player direction is 4 and event can enter the tile
event.move_left if $game_player.direction == 4 &&
$game_map.passable?(event.x - 1, event.y, 6)
#event move right if player direction is 6 and event can enter the tile
event.move_right if $game_player.direction == 6 &&
$game_map.passable?(event.x + 1, event.y, 4)
#event move up if player direction is 8 and event can enter the tile
event.move_up if $game_player.direction == 8 &&
$game_map.passable?(event.x, event.y - 1, 2)
return unless event.moving?
#play the push sound if the event is moving
$game_system.se_play(RPG::AudioFile.new("bump"))
end
end
#
#
#
class Game_System
attr_accessor :movable_object
alias init_push initialize
def initialize
init_push
@movable_object = []
end
end
#
#
#
class Game_Player
def passable?(x, y, d)
# Get new coordinates
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
array = $game_system.movable_object
p array
for event in $game_map.events.values
#p array
if array.include?([event.id, new_x, new_y])
return false if event.moving?
array.delete([event.id, new_x, new_y) if $game_map.events[event.id].moving? == false
end
end
# If coordinates are outside of map
unless $game_map.valid?(new_x, new_y)
# Impassable
return false
end
# If debug mode is ON and ctrl key was pressed
if $DEBUG and Input.press?(Input::CTRL)
# Passable
return true
end
super
end
end
this code works fine, my main question is about how im deleting the array, at the moment its only deleting the array if i am entering the tile that was locked, i think the best way would be to delete any array if the asociated event is not moving, i did try it like this:
for i in 0...array.size
array.delete(array[i]) if array[i][0] == event.id &&
$game_map.events[event.id].moving? == false
end
but that didnt work