I am trying to create a map persistence system for certain preset items (As in a vehicle is left in an area stays where it was ditched.) For this i plan to use a script to load all such objects from variables when a map is loaded. My question is this: Is it possible to create a map event or clone an existing one using a script then place it in a location specified by script variables (not game variables) (Lets call them Location_X and Location_y for now)? And if so can someone explain how to do this?
Also can variables with variable names be used in scripts (for instance a storage variable called Location_X_<Number of already existing stored objects +1>)?
I'm new to RPGmaker XP's scripting system, but not to codeing in general so I don't now exactly how things work in RPGmaker XP scripting system just yet.
class Scene_Map
attr_accessor :spriteset
end
class Spriteset_Map
create_character_sprite(character)
@character_sprites.push(Sprite_Character.new(character))
end
end
class Game_Map
clone_event(event_id)
return 0 if @events.size == 0 || @events[event_id] == nil
id = @events.keys.max
@events[id] = @events[event_id]
$scene.spriteset.create_character_sprite(@events[id])
@need_refresh = true
return id
end
end
If you use this script, you should be able to clone an event using this:
$game_map.clone_event(ID)
The method will return the ID of the new event or 0 if it wasn't created. The argument passed onto the method is the ID of the event that you want to clone. I haven't tested this, but it should work.
Creating an event is more complicated.
Events can be directly moved by using this code:
$game_map.events[ID].moveto(X, Y)
ID is the event ID, X and Y are the coordinates. Keep in mind that events created like this don't appear in the map editor.
If it a predefined event, though, you can just use the "Change Event Location" event command.
If you want to access variables via script use this:
Thank you Blizzard, I'll try that.
RPGmaker is telling me there is a syntax error in line 9...
class Scene_Map
attr_accessor :spriteset
end
class Spriteset_Map
def create_character_sprite(character)
@character_sprites.push(Sprite_Character.new(character))
end
end
class Game_Map
clone_event(event_id)
return 0 if @events.size == 0 || @events[event_id] == nil
id = @events.keys.max
@events[id] = @events[event_id]
$scene.spriteset.create_character_sprite(@events[id])
@need_refresh = true
return id
end
end
Fixed
Thank you.
Edit:
Ok... there is another error... actually a couple.
When I first tried the script I got an error further down, (clone_event(event_id), which I replaced with def clone_event(event_id) as per game_guy's first correction.)
Now I am getting a can't convert Game_Event into Viewport error (what?)
Also if I try to use it with blizzABS there seems to be an incompatibility induced no method error in line 4701 of part 3... If someone could make that not happen that would be good.
PS. Is this the point where I go to the script request forum? Because this is quickly turning in to a scripting problem...
OMA NO DOUBLE POSTING WITHING 24 HOURS!!! >8U
I was making a script like this today... before I read this topic XD
I got mine to actually work without errors, but it requires Blizz-ABS... XD
However... I'm still working on it for some features.
Blizz's version might be better, as in mine... events get removed when leaving the map XD
The fact that it requires Blizz ABS would be fine for me, as I use Blizz ABS for the game I need this script for. And the fact that events get removed is to be expected as the map gets reloaded every time a player leaves and reenters. That's why I'm trying to make the persistence system for such some things in the first place. (I of course mean the objects on the map are reset not the variables.)
If you have a working script can I have a copy please once you are done? (if you don't mind sharing it i mean.)
I need a version that wont clash with Blizz-ABS for my game.
This is the version that just has the basic function of spawning an event from a map.
Don't spread it around since it's not done :P
# Spawn Events
# By TerreAqua
class Interpreter
def spawn_event(event_id, x, y, mapid = 0)
mapid = $game_map.map_id if mapid == 0
map = load_data(sprintf('Data/Map%03d.rxdata', mapid))
event = map.events[event_id]
if event != 0
max = $game_map.events.keys.max
max = 0 if max == nil
max += 1
event.id = max
event.x = x
event.y = y
$game_map.events[max] = event
$game_map.events[max] = Game_Event.new($game_map.map_id, event)
sprite = Sprite_Character.new($scene.spriteset.viewport1, $game_map.events[max])
$scene.spriteset.character_sprites.push(sprite)
$game_map.events[max].spawned = true
end
end
end
class Game_Character
attr_accessor :spawned
end
class Game_System
alias spawn_event_removal event_removal
def event_removal
($game_map.events.values.find_all {|event|
event.spawned && event.terminate}).each {|event|
$game_map.events.delete(event.id)}
$game_map.need_refresh = true
end
end
spawn_event(EVENT_ID, MAP_X, MAP_Y, MAP_ID)
Event ID - Event ID of MAP_ID to be spawned on current map
MAP_X & MAP_Y - Coords of where event will appear
MAP_ID - Map ID to take event from - can be left blank or as 0 to use current map
$game_map.events.each_value {|e|
e.terminate = true if e.spawned}
Use this to get rid of the spawned events on the map
Thanks.
class Spriteset_Map
def create_character_sprite(character)
@character_sprites.push(@viewport1, Sprite_Character.new(character))
end
end