Save-Point

Full Version: Save-Point
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Board Message
Sorry, you do not have permission to access this resource.
Save-Point - Adding a function in this script!

Save-Point

Full Version: Adding a function in this script!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys, I do not remember if I asked here or on another site once but would again ask (if I've already asked XD) you help me with this script the path finder, would like it added a function to the event Next to a variable. In the script there ... explaining the functions "seguir" (follow) and "fugir" (flee) and definitions "(0 or No. (0 for event, if different will be coordinated), event or cordenada X (if you choose the 1), Y) ".
If I want the NPC NPC follow ountro I use "seguir (0, 2)," the same for the "fugir".
If you want the NPC to follow one cordenada map I use "seguir (1, 5, 7)" and the same goes for "fugir".
Well then, I need a function for the NPC to "seguir" and "fugir" to variables:
example:
"seguir(2 (for variables), varX ID, ID VarY)"
Can help me with this?
Script for editing:
Code:
    #=================================================================
    # Mais movimentos para eventos
    # Autor: Madajuv
    #-----------------------------------------------------------------
    # O script adiciona mais 4 comandos para os eventos:
    # - Seguir um outro evento
    # - Seguir uma posição do mapa
    # - Fugir de outro evento
    # - Fugir de uma posição do mapa
    #-----------------------------------------------------------------
    # Para usar:
    # Dentro de mover evento, selecione script e digite:
    # seguir(tipo, ID ou X, Y)
    # ou
    # fugir(tipo, ID ou X, Y)
    #
    # tipo: Se tipo for igual a 0 (zero) o parâmetro será um evento
    #   se tipo for diferente de zero o paraâmetro será uma posição
    #   do mapa.
    # ID: id do evento que se deseja perseguir ou fugir
    # X, Y: Coordenadas do mapa.
    #
    # Exemplos:
    #
    # seguir(0, 4) --> Isso fará o evento seguir o evento de ID 4.
    # fugir(0, 1) --> Isso fará o evento fugir do evento de ID 1.
    # seguir(1, 14, 10) --> Isso fará o evento seguir a
    #                       posição (14,10) do mapa. 14 = X / 10 = Y
    # fugir(99, 45, 72) --> Isso fará o evento fugir da posição
    #                       (45,72) do mapa. 45 = X/ 72 = Y
    #=================================================================
    class Game_Character
      def seguir(tipo, pos_x_id, posy=0)
        if tipo == 0
          sx = @x - $game_map.events[pos_x_id].x
          sy = @y - $game_map.events[pos_x_id].y
        else
          sx = @x - pos_x_id
          sy = @y - posy
        end
        return if sx == 0 && sy == 0
        abs_sx = sx.abs
        abs_sy = sy.abs
        (rand(2) == 0 ? abs_sx += 1 : abs_sy += 1) if abs_sx == abs_sy
        if abs_sx > abs_sy
          sx > 0 ? move_left : move_right
          (sy > 0 ? move_up : move_down) if !moving? && sy != 0
        else
          sy > 0 ? move_up : move_down
          (sx > 0 ? move_left : move_right) if !moving? && sx != 0
        end
      end
      def fugir(tipo, pos_x_id, posy=0)
        if tipo == 0
          sx = @x - $game_map.events[pos_x_id].x
          sy = @y - $game_map.events[pos_x_id].y
        else
          sx = @x - pos_x_id
          sy = @y - posy
        end
        return if sx == 0 && sy == 0
        abs_sx = sx.abs
        abs_sy = sy.abs
        (rand(2) == 0 ? abs_sx += 1 : abs_sy += 1) if abs_sx == abs_sy
        if abs_sx > abs_sy
          sx > 0 ? move_right : move_left
          (sy > 0 ? move_down : move_up) if !moving? && sy != 0
        else
          sy > 0 ? move_down : move_up
          (sx > 0 ? move_right : move_left) if !moving? && sx != 0
        end
      end
    end
I'm trying to understand...

Rather than the classic 'move to player' or 'move away from player' commands in the Event Editor, this system lets you move one event towards towards another event or map location by coordinates. Oddly enough, I kinda have that in another project.

But if I am correct, are you trying to make it so you can assign the event being controlled able to be set by variable?
Move (RMXP VARIABLE) to EVENT 3 // Move (RMXP VARIABLE) to MapX, MapY ???

The instructions are vague. You cannot call either seguir or fugir from a normal call. These can only be performed way of using the SET MOVE ROUTE event.... thus you need to say "player" seguir(0, 14) which would move the player one tile towards event #14

HOWEVER... you 'can' substitute varables in the call:
Code:
seguir(0, $game_variables[6])

This would make your character/event move one step towards whatever event is set by RMXP variable #6. I tested this with a MOVE ROUTE call and had my player move towards Event #20 just the same way. I just set my RMXP Variable #6 to a value of 20, and he moved towards the event I chose. Cheery I'm pretty sure fugir will work the same way.
You got it right, it's exactly that! I want to do the following events for a variable X, and a variable Y
I could not do it the way you mentioned ...
Then you may want to do an edit on the scripts...
Code:
#------------------------------
  # * Changed the arguments
  #------------------------------
  def seguir(tipo, var_x_id, var_y_id)
    # Changing passed variable IDs into data
    pos_x_id = $game_variables(var_x_id)
    posy = 0
    posy = $game_variables(var_y_id) unless var_y_id.nil?
    # The rest is the same
    if tipo == 0
      sx = @x - $game_map.events[pos_x_id].x
      sy = @y - $game_map.events[pos_x_id].y
      *etc*

This little edit should be easy to paste in place.
First, sorry the delay was without internet at home.
I do not know if I did right, but I pasted this:

[Image: 1911693_595899180533092_5405541208064257...e=54E7AFC1]

Is giving error on line 34 ...
Whoops, my bad. It's supposed to be:
Code:
pos_x_id = $game_variables[var_x_id]
with brackets around the 'var_x_id' value... not parenthesis.

Likewise, brackets around the variable in line 36. And for fugir, lines 59 and 61
I think you should make a demo with the script worked, because every issue you told me to do is not working ... :\
Here's the whole script.
Content Hidden

And you do realize this only makes an event move one step at a time, preferrably in a move route event?

The below is an EVENT that sets an event to move towards an X/Y location on the map based on data in game variables 5 and 6. The 'Script' box that lets me enter 'seguir(1,5,6)' to accomplish this is the bottom right event in the Move Route widget.
Code:
@>Set Move Route: This event
:                  : $>Script: seguir(1,5,6)
:                  : $>Script: seguir(1,5,6)
:                  : $>Script: seguir(1,5,6)
:                  : $>Script: seguir(1,5,6)

By having 4 statements of the seguir variety, the event will move 4 steps towards the desired location.
Thank you very much DerVV this will help me going forward, I am very grateful indeed!