Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Jesse66126

Is there a way to make an event move toward another event and react on touch?

Question

Is there a way to make an event move toward another event and react on touch?

It's very easy to do this for the player with eventing, but how would you do this for event 1?

 

Let say event 1 is the princess, and events 2 and 3 are bandits, trying kidnap her.

How would I make it so, event 1 is abducted event 2 or 3 if they make contact?

Edited by Jesse66126

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

here be a script:


class Game_Character
#--------------------------------------------------------------------------
# * Move toward Event
#--------------------------------------------------------------------------
def move_toward_event(id)
return if moving?
# Get difference in player coordinates
sx = @x - $game_map.events[id].x
sy = @y - $game_map.events[id].y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Move towards player, prioritize left and right directions
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# If vertical distance is longer
else
# Move towards player, prioritize up and down directions
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
end

to use that use either:

  • $game_player.move_toward_event(ID)
  • $game_map.events[iD].move_toward_event(ID)

then a script to check if the event/player is next to an event or player:

class Game_Character
 def character_next_to?(character)
    return true if character.x == @x - 1 && character.y == @y &&
	  character.direction == 6
    return true if character.x == @x + 1 && character.y == @y &&
	  character.direction == 4
    return true if character.y == @y - 1 && character.x == @x &&
	  character.direction == 2
    return true if character.y == @y + 1 && character.x == @x &&
	  character.direction == 8
    return false
 end
end

to use that use either of the following script calls in a conditional branch:

  • $game_player.character_next_to?(CHARACTER)
  • $game_map.events[iD].character_next_to?(CHARACTER)

for CHARACTER replace that to the required:

  • $game_player
  • $game_map.events[iD]

obviously don't check it against itself, that would be stupid, i made it also check if they were facing the target, if you dont want that(but im guesing you do) just remove the "&& character.direction" parts of the ends of the conditions.

 

so set up a conditional branch with the script call that checks if the character is next to the target, then put the first script that makes it move towards the character in the else branch, so it moves towards if that condition is not met. :)

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

np, also as for the second script, i just noticed as i quickly wrote that, it wont account for y or x disposition when the x or y matches up, my bad, replace it with this:

class Game_Character
 def character_next_to?(character)
   return true if character.x == @x - 1 && character.y == @y &&
  character.direction == 6
   return true if character.x == @x + 1 && character.y == @y &&
  character.direction == 4
   return true if character.y == @y - 1 && character.x == @x &&
  character.direction == 2
   return true if character.y == @y + 1 && character.x == @x &&
  character.direction == 8
   return false
 end
end

Share this post


Link to post
Share on other sites
  • 0

diagostimo can you help me how to use this? to make it clear, can you give me an example of conditional branch with scripts? im fully lost :o

Share this post


Link to post
Share on other sites
  • 0

on the last tab to the right of a conditional branch(when selecting whether the condition be a switch or something) theres a script insert section, add the script call there as mentioned above

edit:

ok i just tested the above scripts, i found 1 glitch where the event would spam its movment and the event would get there before the graphic, i have updated the top script to fix that, also i typo'd a couple of script calls, i have corrected them too, just re get everthing :)

as for images how to set up an event:

 

 

event-19396.png

 

 

 

 

conditional-bra-19396.png

 

 

if the script call is to big for 1 line(the one that executes the movement) then you will have to break it up like i did in the image above for the event

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

Is this correct for conditional branch?

 

Conditional Branch: Script:$game_map.events[2].character_next_to?($game_map.events[1])

>

 

Thanks for putting your time

Edited by deathmoverz24

Share this post


Link to post
Share on other sites
  • 0

yes that is correct, that will check if event 1 is next to event 2, if your not getting results, that will be because of the "&& character.direction" part on the end of each condition within the script, as that checks if the event is facing it too, if you dont want that part, you can remove it as stated above and just put in your own conditions to direction via conditional branch if you ever need them

Share this post


Link to post
Share on other sites
  • 0

Alright! I finally figured my mistakes on removing the "character direction" part. I really like it thanks man. The move toward events is the one I needed for months. Okay, can u make a script on "move away from event?"

Share this post


Link to post
Share on other sites
  • 0

sure, here it is:

class Game_Character
 #--------------------------------------------------------------------------
 # * Move away from Event
 #--------------------------------------------------------------------------
 def move_away_from_event(id)
   # Get difference in player coordinates
   sx = @x - $game_map.events[id].x
   sy = @y - $game_map.events[id].y
   # If coordinates are equal
   if sx == 0 and sy == 0
  return
   end
   # Get absolute value of difference
   abs_sx = sx.abs
   abs_sy = sy.abs
   # If horizontal and vertical distances are equal
   if abs_sx == abs_sy
  # Increase one of them randomly by 1
  rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
   end
   # If horizontal distance is longer
   if abs_sx > abs_sy
  # Move away from player, prioritize left and right directions
  sx > 0 ? move_right : move_left
  if not moving? and sy != 0
    sy > 0 ? move_down : move_up
  end
   # If vertical distance is longer
   else
  # Move away from player, prioritize up and down directions
  sy > 0 ? move_down : move_up
  if not moving? and sx != 0
    sx > 0 ? move_right : move_left
  end
   end
 end
end

that should work just use the following calls:

  • $game_player.move_away_from_event(ID)
  • $game_map.events[iD].move_away_from_event(ID)

Share this post


Link to post
Share on other sites
  • 0

That seems quick. or you prepared it for an instance? hehe :-D! Great though. I wonder how many things you can do. How about "event approaches event"?

Share this post


Link to post
Share on other sites
  • 0

[XP] Heretic's Movement Enhancements - Turn or Move Toward or Away From Events

http://forum.chaos-p...ic,12295.0.html

 

Demo

http://www.775.net/~...nhancements.exe

 

This seems to be EXACTLY what you are looking for.

Edited by Heretic86

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...