Dealing with multiple instances of the same NPC
Moderators: marionline, SDHawk
Dealing with multiple instances of the same NPC
Hello again,
I have another fun question for today. Let's say (as an example) I want to have something like the dots in pacman, where you walk over them and they disappear. What would be the best way to achieve this without having to make several dozen (or hundred) on-step one use only NPCs?
Basically I want to have NPCs that can be placed on the map, will wander and trigger on-touch or on-step, something will happen (eg a battle, a sound effect, a text box.. could be anything really), and they will disappear. I want to be able to have multiples of the same type of NPC on the same map, and not have all instances of that NPC disappear when just one of them is activated. Does that make sense?
Help is much appreciated.
I have another fun question for today. Let's say (as an example) I want to have something like the dots in pacman, where you walk over them and they disappear. What would be the best way to achieve this without having to make several dozen (or hundred) on-step one use only NPCs?
Basically I want to have NPCs that can be placed on the map, will wander and trigger on-touch or on-step, something will happen (eg a battle, a sound effect, a text box.. could be anything really), and they will disappear. I want to be able to have multiples of the same type of NPC on the same map, and not have all instances of that NPC disappear when just one of them is activated. Does that make sense?
Help is much appreciated.
vvight.wordpress.com
If you attach a script to an NPC ('Use Script') it receives two arguments when it's triggered: the first is the 'Script argument' in the NPC definition, the second is the NPC reference for the triggering NPC. You can use the npc ref to delete the npc:
Note that unlike setting a "one time usable" tag on an NPC, the effect of deletenpc is temporary. The NPC will be recreated when the map is reloaded. You can choose to save NPC data in the map settings menu, which prevents the NPCs from being reloaded when you leave and reenter the map, but maps always reload when you load a saved game (maps aren't stored in saved games).
Note that you can only place 300 NPCs on a map. You can also use tiles or slices to display something on the map, and an each-step script combined with zones to perform some action when you step on certain tiles.
See How do I make a battle start when you bump into an NPC?
Code: Select all
plotscript, an npc script, arg, npcref, begin
delete npc(npcref)
end
Note that you can only place 300 NPCs on a map. You can also use tiles or slices to display something on the map, and an each-step script combined with zones to perform some action when you step on certain tiles.
See How do I make a battle start when you bump into an NPC?
Last edited by TMC on Tue Mar 15, 2016 1:21 pm, edited 1 time in total.
Saving map state is tricky because we need to handle the case where the .rpg file has been edited since the game was saved. One strategy is to try to merge changes made to the .rpg with changes that occurred in-game. In fact this is already implemented for tilemaps, passmaps, and npc instances when you use 'Test Game', but the way NPCs are handled in saved games will be different.
NPCs are definitely the most work; we have a plan for saving npcs. I don't know when it will happen. Maybe for the next release.
Saving zones, tilemaps, and passmaps is easier; I plan to add those after Callipygous is released.
Slices attached to map layers or to NPC slices are another thing we would like to save.
There will probably be a setting for whether you want merging, so we can always implement the merging option at a later point.
NPCs are definitely the most work; we have a plan for saving npcs. I don't know when it will happen. Maybe for the next release.
Saving zones, tilemaps, and passmaps is easier; I plan to add those after Callipygous is released.
Slices attached to map layers or to NPC slices are another thing we would like to save.
There will probably be a setting for whether you want merging, so we can always implement the merging option at a later point.
Oh yeah, I definitely didn't think about the implications that could have on game edits. Clearly potential complications there.
I didn't realize how close we were to a new release. This is all great news. I've just been looking forward to this particular feature because I'm more prone to using bigger maps with random or procedurally generated features that can be impossible on the ohrrpgce if the scope is big enough. It will open up so many different avenues.
And by the way, outstanding job on all the additions you've made since the last release. I've been very impressed with a lot of the more recent features.
I didn't realize how close we were to a new release. This is all great news. I've just been looking forward to this particular feature because I'm more prone to using bigger maps with random or procedurally generated features that can be impossible on the ohrrpgce if the scope is big enough. It will open up so many different avenues.
And by the way, outstanding job on all the additions you've made since the last release. I've been very impressed with a lot of the more recent features.
Oh, so you specifically care about tile data? I assumed that you were asking about NPCs, which most people would care about. Well it's good news for you then.
BTW an alternative to saving a procedurally generated map is to instead save the random seed you used to generate it (using "reseed random"), and then recreate it when reentering it.
Another alternative to merge would be to have a special map trigger which is called instead of the map autorun when the map couldn't be loaded from the save file because the game has been edited since. But that sounds over-engineered to me. How would you want to handle it in your own game?
BTW an alternative to saving a procedurally generated map is to instead save the random seed you used to generate it (using "reseed random"), and then recreate it when reentering it.
Another alternative to merge would be to have a special map trigger which is called instead of the map autorun when the map couldn't be loaded from the save file because the game has been edited since. But that sounds over-engineered to me. How would you want to handle it in your own game?
Last edited by TMC on Wed Mar 23, 2016 12:28 am, edited 1 time in total.
NPCs would be nice as well, but I guess it's game specific as to which is more important. I want players to be able to alter their surroundings a la Minecraft/terraria. Virtually impossible to do right now with bigger maps. NPC behavior is tricky, but more plausible with some less than desirable workarounds.
I definitely see the benefit of merging and not merging as well.
I think maybe a good compromise might be an option to set the behavior you want. Since the maps I'm envisioning are generated and none of it is actually edited in custom I would obviously prefer the option to not have edits to the game affect the save files at all.
But for someone that wants their maps to change in game and also maybe add a new area I think they might prefer some sort of way to keep both.
I'm not sure really. That's sort of a tricky conundrum. I think there's the possibility of save games becoming obsolete if content is added to a map, but I also think that would be a small price to pay for the option.
In my case, I would have the maps that are saved take precedence over edited maps. I would have to be careful about updates. Games where the map changes in game don't carry as much weight may be okay letting the map edit override everything. I think all options are useful in different cases.
I definitely see the benefit of merging and not merging as well.
I think maybe a good compromise might be an option to set the behavior you want. Since the maps I'm envisioning are generated and none of it is actually edited in custom I would obviously prefer the option to not have edits to the game affect the save files at all.
But for someone that wants their maps to change in game and also maybe add a new area I think they might prefer some sort of way to keep both.
I'm not sure really. That's sort of a tricky conundrum. I think there's the possibility of save games becoming obsolete if content is added to a map, but I also think that would be a small price to pay for the option.
In my case, I would have the maps that are saved take precedence over edited maps. I would have to be careful about updates. Games where the map changes in game don't carry as much weight may be okay letting the map edit override everything. I think all options are useful in different cases.
Actually, both slices and strings get saved in saved games if you turn on the corresponding option, and both can store infinite amounts of data. Storing a map layer in a string is easy:
I guess that's a bit of a hack, and fingers crossed, this will be added soon anyway.
Yes, if players can edit the map that could make it a really bad idea to try to merge changes, unless you ensure that the parts of the map they can edit don't overlap with the parts you will edit.
Thanks for your comments. I've been thinking about this for a while but it's not clear what features people actually need. I also don't want to add too many options when some of them can be accomplished with script commands like "reset map state". There are so many possible options that could be provided. Should you be able to specify on a per-map basis which state is saved, or how exactly it should be merged/not merged? That might be useful for certain games with different types of maps. For example maybe you found a bug on one map and want to reset it... hmm, I'm having trouble thinking of examples which can't be solved with deletemapstate in a load-game script.
One possible scheme would be:
-In the global saved games options menu:
--for each of tilemaps, npcs, etc, have separate Save/Don't Save options plus separate "In case of editing clash: merge changes/prefer in-game edits/prefer editor edits" options
--An option "Always save map state for the player's current map". All other maps are only included in saves if their Tile Data/NPC Data are set to Remember.
-No new per-map options.
Code: Select all
for (x, 0, map width -- 1) do (
for (y, 0, map height -- 1) do (
append ascii (string id, read map block(x,y, map number))
)
)
Yes, if players can edit the map that could make it a really bad idea to try to merge changes, unless you ensure that the parts of the map they can edit don't overlap with the parts you will edit.
Thanks for your comments. I've been thinking about this for a while but it's not clear what features people actually need. I also don't want to add too many options when some of them can be accomplished with script commands like "reset map state". There are so many possible options that could be provided. Should you be able to specify on a per-map basis which state is saved, or how exactly it should be merged/not merged? That might be useful for certain games with different types of maps. For example maybe you found a bug on one map and want to reset it... hmm, I'm having trouble thinking of examples which can't be solved with deletemapstate in a load-game script.
One possible scheme would be:
-In the global saved games options menu:
--for each of tilemaps, npcs, etc, have separate Save/Don't Save options plus separate "In case of editing clash: merge changes/prefer in-game edits/prefer editor edits" options
--An option "Always save map state for the player's current map". All other maps are only included in saves if their Tile Data/NPC Data are set to Remember.
-No new per-map options.
I think it may warrant a pop-up sort of like it does when you change the frame rate, just because either way could cause some undesired effects.
Maybe the best way would be to add limited options at first and as people play around with it it would probably give them a better idea how it should be handled. I know I'm much better actually seeing it, because thinking of all the possibilities makes my head hurt lol.
Maybe the best way would be to add limited options at first and as people play around with it it would probably give them a better idea how it should be handled. I know I'm much better actually seeing it, because thinking of all the possibilities makes my head hurt lol.
You're right; I'm prone to over-thinking things because I try to have a perfect design before starting, but things like this can be built gradually -- we can always add more options later. I guess that's a result of having to live with so many design mistakes that we've made over the years, it's really made me cautious.
Never again.TMC wrote:You're right; I'm prone to over-thinking things because I try to have a perfect design before starting, but things like this can be built gradually -- we can always add more options later. I guess that's a result of having to live with so many design mistakes that we've made over the years, it's really made me cautious.
- Spoonweaver
- Liquid Metal King Slime
- Posts: 6461
- Joined: Mon Dec 08, 2008 7:07 am
- Contact:
Gizmog wrote:Never again.TMC wrote:You're right; I'm prone to over-thinking things because I try to have a perfect design before starting, but things like this can be built gradually -- we can always add more options later. I guess that's a result of having to live with so many design mistakes that we've made over the years, it's really made me cautious.
Backwards compatibility for spelling errors is truly a feature worth noting
Hi TMC,
Script works as intended, with one small caveat. If I, for instance, place 3 or 4 of the item in a row (in this case it is an HP pickup with a step on trigger) then if I run over them the first one will disappear and activate it's effect but there seems to be a slight delay before the next NPC is triggered. It has the effect that I can run over a row of 4 of the NPC but only the first one is removed unless I double back.
Here is my script
The attack "quicken" restores 20% of the hero's maximum HP. Another problem I've noticed is that even if the hero is at full HP the script still applies the effect and deletes the NPC.
Cheers
Script works as intended, with one small caveat. If I, for instance, place 3 or 4 of the item in a row (in this case it is an HP pickup with a step on trigger) then if I run over them the first one will disappear and activate it's effect but there seems to be a slight delay before the next NPC is triggered. It has the effect that I can run over a row of 4 of the NPC but only the first one is removed unless I double back.
Here is my script
Code: Select all
plotscript, HP Pickup, arg, npcref, begin
if ( get hero stat (find hero (0), stat:hp, current stat) < get hero stat (find hero (0), stat:hp, maximum stat) )
then (
map cure (atk:quicken, find hero (0), -1)
delete npc (8)
wait (1)
)
else ()
end
Cheers
Last edited by guo on Fri Apr 08, 2016 12:44 am, edited 1 time in total.
vvight.wordpress.com