Ok, trying to write a simple projectile script so you know where I'm coming from for starters. I know projectile scripts already exist but I'm wanting to do this to learn a bit more about scripting.
Firstly, when a key is pressed this snippet is ran in a common event:
Spoiler
spawn_event(34, $game_variables[83], 9, $game_variables[84], $game_variables[85])
@shurikentoss = Shuriken_Toss.new
spawn_event is simply:
Spoiler
def spawn_event(spawn_from_map_id, _map_id, _event_id, _x, _y)
map = load_data(sprintf("Data/Map%03d.rvdata2", spawn_from_map_id))
event_id = $game_map.events.keys.max + 1
preprocess = map.events[_event_id]
preprocess.id = event_id
event = $game_map.events[event_id] = Game_Event.new(_map_id, preprocess)
sp_map = SceneManager.scene.instance_eval('@spriteset')
sp_map_char_sprs = sp_map.instance_eval('@character_sprites')
sp_map_view_1 = sp_map.instance_eval('@viewport1')
sp_map_char_sprs.push(Sprite_Character.new(sp_map_view_1, event))
event.moveto(_x, _y)
end
For the projectile script I have started:
Spoiler
class Shuriken_Toss < Game_Character
def initialize
if $game_variables[88] == 2
south_check
elsif $game_variables[88] == 4
west_check
elsif $game_variables[88] == 6
east_check
elsif $game_variables[88] == 8
north_check
end
end
def south_check
$game_variables[37] = $game_variables[84] # current event x pos equal to player pos
$game_variables[38] = $game_variables[85] # current event y pos equal to player pos
$game_variables[36] = $game_variables[85] # 'next tile' collision check variable
$game_variables[36] += 1 # looks at next y pos
eventid = $game_map.event_id_xy($game_variables[37], $game_variables[38])
if passable?($game_variables[37], $game_variables[36], 2) == true
move_route = RPG::MoveRoute.new
move_route.repeat = false
move_route.skippable = true
m = RPG::MoveCommand.new
m.code = 1
move_route.list.insert(0,m.clone)
$game_map.events[eventid].force_move_route(move_route)
end
end
def west_check
end
def east_check
end
def north_check
end
end
*Edit - Left out a line in the class.
Whenever I put a p eventid just after the eventid variable is created and set, it shows up with the correct event id in the console so I'm pretty positive that this is being passed later in the method.