Random Encounter, but no enemy

● ARCHIVED · READ-ONLY
Started by Ruby 15 posts View original ↗
  1. Is anyone familiar with Dokapon Kingdom?

    In the game, they have random encounters, but with NPCs. It happens in game when you land on an empty field space, some characters are travelling salespeople, some are doctors who will cure you for a price, random beggars, princesses. However, that game is set up like a board game and I would simply use the random enemy encounter but use these 'random' NPCs instead of enemy's since my game does not have battles in that sense.

    Is this a neat feature? Do a lot of RM games use something like this?

    The encounter will use random townsfolk (ones that you have never met) and allow you to simply interact with them for a short time if you choose to. Something like "You see a horse in the distance, do you choose to interact?" will pop up, and it will only be a feature the world map.

    (If this is in the wrong forum, I'm sorry!)
  2.     I love the idea, not just for games without battles, personally I think it would be a pretty cool take even on the standard rpg random encounter system if not all of your 'random encounters' were actually hostile. Especially if your game doesn't have battles and is more apt for exploration it could be made really interesting, as you could convert the default battle actions for a more tactful use. It is pretty odd that in most games the outside of large settlements only ever seem to be populated by monsters, bandits, and your player characters. any mechanic to change that is good in my book. Heck, if I was using random encounters at all I'd probably snatch this idea up for my own use.
  3. I think it's a great idea and easy to set up as well.
  4. You could possibly still create them as enemies but tailor the battle system to suit your needs - give them good skills so they'll heal you, or have a whole "cutscene" scripted in the Troops tab.


    Or just change the script where it initiates a battle on random encounters to turn on a particular switch that triggers a common event or something.


    I know you're probably not after the technical "how to", but those ideas just popped into my head. It's an interesting idea. Would it be a bit strange that SOME townspeople you can only interact with by approaching them, and others do the pop-up "invitation" even though you may never see them in town?
  5. Shaz said:
    Would it be a bit strange that SOME townspeople you can only interact with by approaching them, and others do the pop-up "invitation" even though you may never see them in town?
    In my game you can only leave your town at certain points during the game. So, since it would happen on the world map, I don't think it would be too strange as long as it is implemented correctly. These people wouldn't be townsfolk of your own town, just of a town.

    But I get what your saying. It definitely wouldn't work for every game.
  6. This is a really intriguing idea, makes me think of some of the people you'd meet in dragon age by just wandering around and coming across them...if you used a time system in your rpg, this could be a great way to make the world feel more alive, by having certain people appear in certain places at particular times - which would be sick in a like, open world harvest moon kinda thing, right?

    I'm defs gonna try and implement this
  7. Shaz said:
    I know you're probably not after the technical "how to", but those ideas just popped into my head. It's an interesting idea. Would it be a bit strange that SOME townspeople you can only interact with by approaching them, and others do the pop-up "invitation" even though you may never see them in town?
    I think the only way that would make sense is if the non-violent random encounters took place on the world map.  Then, we could say, for example, the party runs across a peaceful Caravan crossing the desert, or a band of pilgrims en route to a shrine.  Those would flow into the plot nicely.

    I agree it would be weird if some townspeople popped up while most you initiate contact with (outside of cutscenes), unless the pop-up ones are travelers who are passing through the area.
  8. I really like the idea. I can't imagine it would be too hard to event with a little creativity. I mean some randomly placed events with no image, then, if you wanted, use a random variable to determine which encounter pops up. The events could even roam around if you wanted them to.

    I love the idea though, I think it would add a really fun element to the game.
  9. Oh wow you have a nice idea there.. I'm glad you post it here, it's creative :)
  10. I didn't read all the above posts, but you could have it so you get in an encounter and you hace a choice of what to do.

    Let's put it like this:

    Text: A wild Thief Appeared! What will you do?

    Choices:

    >Attack

    >Talk

    >Give Item

    >Ect.

    Just some flavor to add to this, but maybe the more innocent people you attack or the more enemies you make friends with will effect how people think of you in game or how the game ends... great, now I want to use this idea for myself! XD
  11. @Seacliff : That's like Skyrim.But if you are in the Thief's Guild,you get an option to tell the thief to go away.
  12. It could also be made easier with a small script.  Said script would look for a notetag on the Troop like "friendly" and list a common event ID.  The common event numbered would be called if the game decided that particular Troop was going to be used for an encounter.  Syntax would look like this:

    <friendly event="1">
  13. Ultim said:
    @Seacliff : That's like Skyrim.But if you are in the Thief's Guild,you get an option to tell the thief to go away.
    Though I don't know too much about the Elder Scroll series, I can see that being in the game.

    Can't always think of something original though, but it would be interesting to see pulled off in a RPG Maker game.
  14. I just created a script to do this and allow the developer to easily turn specific encounters (friendly or not) on and off by a Switch, since I need it for my current game.  I've done a bit of testing and verified these 2 behaviors work

    To use, create a notetag in this format: <encounter troop="(troop id)" switch="(switch id)" friendly="(friendly common event)">

    The "troop" tag is required and lists the Troop ID which will have its behavior changed.

    The "switch" tag is optional.  If it's present, the Troop will never execute if the switch is OFF.

    The "friendly" tag is optional.  If it's present, when the Troop would execute, the game will call this Common Event ID instead.

    I haven't tested its interaction with any other scripts, especially since it completely replaces the "encounter" method to handle the "friendly" common events.

    Here it is:

    Spoiler
    #================================================
    #
    #    Script:    EncounterControl
    # by:        whitesphere (whitesphere@comcast.net)
    #                September 4 2014
    #================================================
    =begin
    ================================================================================

    Description: Allows turning specific encounters ON or OFF based on a switch
        and allows an encounter to be Friendly (i.e. it will call a Common Event
        instead of a battle)
        

    --------------------------------------------------------------------------------
    History

    v1.0 (2014/09/04)
      Initial release
     
     
    --------------------------------------------------------------------------------
    Terms of Use

    - You are free to use this script for non-commercial or commercial projects.
    - Reported bug will be fixed, but no guarantee on requested features.
    - No guarantee either for compatibility fixes.
    - Give credit to whitesphere (me), and do not delete this header.
    --------------------------------------------------------------------------------

    In each Map, add one or more notetags like this:
    <encounter troop="35" switch="1" friendly="3">

    The "troop" tag defines the Troop ID.  This tag as well as at least one of the two other ones below must be present.
    If the "switch" tag is present, the troop can only be selected if the specified switch is ON
    If the "friendly" tag is present, instead of starting the battle, this script will call the Common Event ID listed.


    The above example says "On the current map, enable Troop ID 35 only if Switch 1 is ON.  And, when a Random Encounter would produce Troop ID 35, call Common Event 3 instead."

    --------------------------------------------------------------------------------
    =end


    ####################################################################
    # Module which reads XML formatted note tags and returns them as
    # HashMaps
    module Tag_reader
        
        ###################################################################
        # Represents a single XML node
        class XML_node
            
            #####################################
            # Constructor
            def initialize(name)
                @name=name
                
                # Set of name=value pairs
                @attributes={}
                
            end
            
            ###################################
            # Adds an attribute
            def add_attribute(name, value)
                @attributes[name]=value
            end
            
            ###################################
            # Returns this as an XML string
            def to_s
                result="<"+@name
                @attributes.each {
                    |key, value| result += " "+key+"=\""+value+"\""
                }
                result += " />\n"
                return result
            end
            
            attr_reader :)name)
            attr_reader :)attributes)
            
        end

        #######################################################
        # Reads a set of XML tags    
        class XML_Reader
            def initialize()
                @nodes=[]
            end
            
            ##########################################################
            # Reads the XML tags in note_string.  Does nothing if the
            # note string is empty or nil.  Returns the set of nodes read
            # from the note_string.  This may be empty
            def read(note_string)
                @nodes.clear
                if (note_string == nil)
                    return @nodes
                end
                note_s=note_string.to_s.strip
                # Ignore empty strings
                string_len=note_s.length
                if (string_len == 0)
                    return
                end
                index=0
                worker=""
                right_index=0
                node_name=""
                
                # Parse the XML string
                while (index < string_len)
                    
                    # Search for < mark
                    if (note_s[index] != '<')
                        index += 1
                        next
                    end
                    
                    # Find the > mark after the < mark
                    right_index=note_s.index("/>",index)
                    if (right_index == nil)
                        right_index=note_s.index('>',index)
                        if (right_index == nil)
                            break
                        end
                    end
                    
                    # This is a string from < to >
                    worker=note_s.slice(index, right_index-index+1)
                    worker=worker.strip
                    
                    # Find name="value" pairs
                    
                    # Skip the <name part of the XML
                    attr_index=worker.index(' ')
                    node_name=worker.slice(1,attr_index).strip
                    
                    new_node=XML_node.new(node_name)
                    while (worker.length > attr_index)
                        if (worker[attr_index] == ' ')
                            attr_index += 1
                            next
                        end
                        value_index=worker.index("=\"", attr_index)
                        if (value_index == nil)
                            break
                        end
                        
                        # Backspace to find the previous space or < mark - start of the
                        # attribute
                        attr_start_index=value_index-1
                        while (worker[attr_start_index] != '<' &&
                            worker[attr_start_index] != ' ')
                            attr_start_index -=1
                        end
                        # Get to the start of the attribute name
                        attr_start_index += 1
                        
                        # Skip the =" marker after attribute name
                        second_quote=worker.index("\"", value_index+3)
                        if (second_quote == nil)
                            break
                        end
                        attr=worker.slice(attr_start_index, value_index-attr_index)
                        value=worker.slice(value_index+2, second_quote-value_index-2)
                        new_node.add_attribute(attr, value)
                        attr_index = second_quote+1
                    end
                        @nodes << new_node
                    index=right_index+1
                end
                return @nodes
            end
        end
    end


    #
    module EncounterControl
        
        
        ##########################################################################
        # CONSTANTS
        
        # Extra information we require
        class Extra_data
        
            attr_reader:)switch_id)
            attr_reader:)friendly_event_id)
            attr_reader:)troop_id)

            # The Constructor
            def initialize(troop_id, switch_id, friendly_event_id)
            
                @troop_id=troop_id.to_i
                @switch_id=nil
                @friendly_event_id=nil
                if (switch_id != nil)
                    @switch_id=switch_id.to_i
                end
                if (friendly_event_id != nil)
                    @friendly_event_id=friendly_event_id.to_i
                end
            end
        end
        
        # Lists the extra-data for each Troop ID
        class Troop_group
        
            def initialize(extra_data_set)
                @extra_data={}
                if (extra_data_set != nil)
                    extra_data_set.each {
                        |entry|  @extra_data[entry.troop_id]=entry
                    }
                end
            end
            
            def get_extra_data(troop_id)
                return @extra_data[troop_id]
            end
        end
        
        def self.init()
            @@troop_group=nil
        end
        
        def self.load()
            @@troop_group=Troop_group.new($game_map.extra_data_set)
        end
        
        def self.get_extra_data(troop_id)
            if (@@troop_group == nil)
                return nil
            end
            return @@troop_group.get_extra_data(troop_id)
        end
    end


    # Create the static member
    EncounterControl::init()

    # Stores the new encounter data
    class Game_Map
        
        attr_reader :)map_id)
        
        alias EncounterControl_setup setup
        
        def setup(map_id)
            EncounterControl_setup(map_id)
            
            # Load the new data
            EncounterControl::load()
        end

        # We fetch these from the RPG::Map method
        def extra_data_set
            return @map.extra_data_set
        end
        
    end

    #--------------------------------------------------------------------------
    # We override these 2 methods to change the encounter logic
    class Game_Player  < Game_Character


      alias EncounterControl_encounter encounter
      alias EncounterControl_encounter_ok? encounter_ok?
      #--------------------------------------------------------------------------
      # * Check the switch ID if need be
      #--------------------------------------------------------------------------
      def encounter_ok?(encounter)
        extra_data=EncounterControl::get_extra_data(encounter.troop_id)
        if (extra_data != nil && extra_data.switch_id != nil &&
            $game_switches[extra_data.switch_id] == false)
            return false
        end
        return EncounterControl_encounter_ok?(encounter)
        end
        
        # Add the check for friendly events.  Can't call the alias because
        # the troop id is created within the method.
        def encounter
            return false if $game_map.interpreter.running?
            return false if $game_system.encounter_disabled
            return false if @encounter_count > 0
            make_encounter_count
            troop_id = make_encounter_troop_id
            return false unless $data_troops[troop_id]
            extra_data=EncounterControl::get_extra_data(troop_id)
            if (extra_data != nil && extra_data.friendly_event_id != nil)
                $game_temp.reserve_common_event(extra_data.friendly_event_id)
                return false
            else
                BattleManager.setup(troop_id)
                BattleManager.on_encounter
                return true
            end
        end

      end


            
    class RPG::Map
            
        def read_note_tag_as_nodes
            if (@node_set == nil)
                reader=Tag_reader::XML_Reader.new
                @node_set=reader.read(@note)
            end
            return @node_set
        end
        
        # Returns the current set of special encounter data
        def extra_data_set
            if (@extra_data_set != nil)
                if (@extra_data_set.empty?)
                    return nil
                end
                return @extra_data_set
            end
            @extra_data_set=[]
            nodes=read_note_tag_as_nodes
            if (nodes == nil)
                return nil
            end
            nodes.each {
                |current|
                if (current.name != "encounter")
                    next
                end
                troop_id=current.attributes["troop"]
                switch_id=current.attributes["switch"]
                friendly_event_id=current.attributes["friendly"]
                if (troop_id == nil)
                    next
                end
                if (switch_id == nil && friendly_event_id == nil)
                    next
                end
                new_mapping=EncounterControl::Extra_data.new(troop_id, switch_id, friendly_event_id)
                @extra_data_set << new_mapping
            }
            return @extra_data_set
        end
        
    end
    Hope other people find this tiny script useful.
  15. God that is so beautiful. <3

    Thank you so much!! It wll be super helpful to my game and hopefully someone elses!