• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Alternative way for the trainers to spot the player

  • 224
    Posts
    9
    Years
    • Seen Feb 20, 2025
    In Essentials, the trainers spot the player when he walks into their line of sight.

    How would I do an alternative system, where the fight starts if the player is too close of the trainer?

    I would like the trainer to spot the player as on the picture on the right. He would turn towards the player and engage him.
    [PokeCommunity.com] Alternative way for the trainers to spot the player


    Also as the trainer would move, it can't be done by eventing each case.

    If anyone got an idea of how to start... I'd be glad to hear it!
     
    Last edited by a moderator:
    You can put a Players Touch event that makes the trainer move and face to him according to the tile the player is on, and use switches to end it with no loop continuity.
     
    First of all, into Game_Player script section, before def pbCheckEventTriggerAfterTurning, add this:

    Code:
      def pbTriggeredAreaEvents(triggers,checkIfRunning=true)
        result = []
        # If event is running
        if checkIfRunning && $game_system.map_interpreter.running?
          return result
        end
        # All event loops
        for event in $game_map.events.values
          next if !event.name[/^Area\((\d+)\)$/]
          distance=$~[1].to_i
          # If event coordinates and triggers are consistent
          if pbPlayerInEventArea?(event,self,distance) and triggers.include?(event.trigger)
            # If starting determinant is front event (other than jumping)
            if not event.jumping? and not event.over_trigger?
              result.push(event)
            end
          end
        end
        return result
      end

    Then, into def pbCheckEventTriggerFromDistance(triggers), after this line:

    Code:
    ret.concat(pbTriggeredCounterEvents(triggers))

    Add this line:

    Code:
    ret.concat(pbTriggeredAreaEvents(triggers))

    Then, into def check_event_trigger_touch(x, y), after this entire lines:

    Code:
          if event.name[/^Counter\((\d+)\)$/]
            distance=$~[1].to_i
            next if !pbEventFacesPlayer?(event,self,distance)
          end

    Add the following lines:

    Code:
          if event.name[/^Area\((\d+)\)$/]
            distance=$~[1].to_i
            next if !pbPlayerInEventArea?(event,self,distance)
          end



    Into PField_Field script section, before def pbEventFacesPlayer?(event,player,distance), add this:

    Code:
    def pbPlayerInEventArea?(event,player,distance)
      x1=event.x
      x2=event.x
      y1=event.y
      y2=event.y
      found=false
      for i in 0...distance
        x1-=1
        x2+=1
        y1-=1
        y2+=1
        if((player.x==x1 && player.y==event.y) ||
           (player.x==x2 && player.y==event.y) ||
           (player.x==event.x && player.y==y1) ||
           (player.x==event.x && player.y==y2))
          found=true
          break
        end
      end
      if((player.x==event.x-1 && player.y==event.y-1) ||
         (player.x==event.x+1 && player.y==event.y-1) ||
         (player.x==event.x-1 && player.y==event.y+1) ||
         (player.x==event.x+1 && player.y==event.y+1))
        found=true
      end
      return found
    end

    IT'S VERY IMPORTANT THAT YOUR EVENT MUST TO BE NAMED Area(x), LIKE Counter(x), AND IT MUST TO HAVE Event Touch TRIGGER. CHANGE THE X VALUE TO THE MAX DISTANCE OF THE EVENT'S SIGHT.
     
    Last edited:
    Back
    Top