I'm working on a project that's a bit code heavy because I'm biting off more than I can chew because of course I am. It's a clone of the arcade game Tapper, and I'm trying to create an event where mugs can be automatically/procedurally generated. Basically every time the left button is pressed, I want a mug that constantly moves left across the bar and either gets caught by a customer or falls off the bar and breaks. But rather than have 30 copies of the same mug waiting off-screen that all need to be accounted for individually (my current setup) I'd like to just have a common event that creates a copy of a dummy mug that gets created on the spot, then deletes itself once it's done it's thing. I'm sure I'll have to write custom script for this, but I'm not familiar with RGSS yet and this seems like a complicated task. If anyone has any advice or guidance that would be great.
If it were standard coding language I could just create function that instantiates a class but alas...
Moved to: RGSS3 Script Requests
I have merged your posts. Please just edit your post to provide additional information if needed, rather than posting multiple times in a row.
What you're looking for is an event spawner, which will require a script - can't be done with just events unless you take the approach you're already taking.
You just need to change 2 places to spawn events:
1, add it to $game_map.events
2, add it to the spriteset_map
And, that's basically the foundation of my procedurally generated town folks and vehicles.
It's very likely you will want to do it in the script editor.
For 2 reasons:
1, Those changes will likely have quite a few lines of code that will likely go beyond RMVXA's default script box's capacity. (I implemented an RMXP version which is more than 100 lines of code.)
2, It will be better to make a function that can be reused in different cases. Thus, a module/class/function implemented in the editor will be better than script commands.
If you want to do a scriptless implementation of this, figure out how many mugs you'll have on screen at any one time, maximum, and create that many blank events (making sure their IDs are sequential). Set aside a variable for event ID, and initialise its value to the ID of the first mug event. Have your "spawn" event check whether the event with ID matching your variable is blank; if not, increment the variable and reset it to its starting value if it's above the maximum ID. Then, set the event with ID matching the variable to a mug and teleport it to the spawn position.
When you "despawn" a mug, just set its graphic to blank and move it back to its original off-map position.
First, to make things a bit easier, I'd recommend setting up another map as a database and add the event you want to spawn on your current map in that database first so that when spawning an event it's just a clone.
To make things a bit more effective. That prototype map database can be stored in a global variable.
For example:
#We use the 1st map as an event data base.
#RMVXA's map may have a different naming structure. It certainly does not end with "rxdata".
$mapdb = Marshal.load(Marshal.dump(load_data(sprintf("Data/Map%03d.rxdata", 1))))
#Now we copy the 1st event from our database
#But, before that...
new_event_id = 2000 #you need to assign a new id for this event.
x = 1
y = 1 #you need to assign the spawn location for this event
m_id = 1 #this is the 1st event from the map database
$mapdb.events[m_id].id = new_event_id #you need to assign a new id for this event.
$mapdb.events[m_id].x,$mapdb.events[event_id].y = x,y
$game_map.events[new_event_id] = Game_Event.new(new_event_id,$mapdb.events[m_id])
#As the event part is done, we move on to graphics part.
$game_map.need_refresh = true
sprite = Sprite_Character.new($scene.spriteset.viewport1, $game_map.events[new_event_id])
$scene.spriteset.character_sprites.push(sprite)
That's basically the skeleton of this event spawning system.
But, it's written in RMXP. Thus, modification may be needed to suit RMVXA.