Guest User

Untitled

a guest
Mar 13th, 2014
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2. Event Respawner
  3. Autor: Raizen
  4. Comunity: www.centrorpg.com
  5. Compatible with: RMVXAce
  6. The script allows an event to be spawned in a map,
  7. respecting or not tile passabilities and respecting
  8. if the player will be trapped by the spawned event.
  9.  
  10. To use the command to event spawn, you only need to Call Script
  11. in the third tab of events commands, and write the command like this.
  12. event_spawn(check, move, distance, switch)
  13. where move can bem 1 or 0.
  14. 1 = event will appear in only passable tiles.
  15. 0 = event will appear anywhere on the map.
  16. the value check, is used to check if after the event spawns on a map,
  17. it will not trap the player, mainly used for non-movable events like
  18. chests and switches. Its value is true(doesn´t allow traps) or
  19. false(doesn´t matter where it will appear).
  20. distance represents the distance in tiles the event will spawn on a map.
  21. switch é the local switch it will turn off after the event spawn.
  22. An exemple on how to use correctly the script.
  23. Call Script: event_spawn(true, 1, 4, "A")
  24. If no switch is needed to be turned off you can write this way
  25. the command.
  26. Call Script: event_spawn(true, 1, 4)
  27. You can also event spawn other events not being themselfs writing instead
  28. of a local switch, the ID number of the event this way.
  29. Exemple: Call Script: event_spawn(false, 1, 4, 5, "A")
  30. In this example I spawn the event with ID 5, and then turn off
  31. Local Switch A of that event.
  32. You can also not turn off the Local Switch like this.
  33. Exemple: Call Script: event_spawn(true, 1, 4, 5)
  34.  
  35. Here starts the script
  36. =======================================================
  37. =end
  38.  
  39. class Game_Interpreter
  40. def event_spawn(check, move, distance, switch = "", switch2 = "")
  41. switch.is_a?(Integer) ? event_id = switch : event_id = @event_id
  42. switch = switch2 unless switch2 == ""
  43. x = $game_map.width
  44. y = $game_map.height
  45. cx = $game_player.x
  46. cy = $game_player.y
  47. count = - 1
  48. while count <= distance
  49. if move == 1
  50. x = rand($game_map.width)
  51. y = rand($game_map.height)
  52. x - cx >= 0 ? count = x - cx : count = - x + cx
  53. y - cy >= 0 ? count2 = y - cy : count2 = - y + cy
  54. count = count2 if count2 >= count
  55. count = - 1 unless $game_map.check_passage(x, y, 0x0f)
  56. else
  57. x = rand($game_map.width)
  58. y = rand($game_map.height)
  59. x - cx >= 0 ? count = x - cx : count = - x + cx
  60. y - cy >= 0 ? count2 = y - cy : count2 = - y + cy
  61. count = count2 if count2 >= count
  62. end
  63. if check
  64. count = - 1 if $game_map.spawner_passable(x, y)
  65. end
  66. end
  67. $game_map.events[event_id].moveto(x,y)
  68. $game_self_switches[[@map_id, event_id, switch]] = false unless switch == ""
  69. return
  70. end
  71. end
  72. class Game_Map
  73. def spawner_passable(x, y)
  74. return false if check_passage(x - 1,y , 0x0f) and check_passage(x ,y -1, 0x0f) and check_passage(x - 1,y -1, 0x0f)
  75. return false if check_passage(x + 1,y , 0x0f) and check_passage(x ,y -1, 0x0f) and check_passage(x + 1,y -1, 0x0f)
  76. return false if check_passage(x - 1,y , 0x0f) and check_passage(x ,y +1, 0x0f) and check_passage(x - 1,y +1, 0x0f)
  77. return false if check_passage(x + 1,y , 0x0f) and check_passage(x ,y +1, 0x0f) and check_passage(x + 1,y +1, 0x0f)
  78. return true
  79. end
  80. end
RAW Paste Data