Advertisement
Dekita

capture 1.1

Jan 15th, 2013
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.04 KB | None | 0 0
  1. =begin =========================================================================
  2. Dekita's v1.1
  3. ★ Pokémon Capture™ ★
  4.  
  5. ================================================================================
  6. Script Information:
  7. ====================
  8. This script replicates the capture feature from pokemon, e.g capture enemies
  9. and add them into the party.
  10.  
  11. This script requires Dekita - Pokémon CORE
  12.  
  13. ================================================================================
  14. ★☆★☆★☆★☆★☆★☆★☆★ TERMS AND CONDITIONS: ☆★☆★☆★☆★☆★☆★☆★☆★☆
  15. ================================================================================
  16. 1. You must give credit to "Dekita"
  17. 2. You are NOT allowed to repost this script.(or modified versions)
  18. 3. You are NOT allowed to convert this script.(into other game engines e.g RGSS2)
  19. 4. You are NOT allowed to use this script for Commercial games.
  20. 5. ENJOY!
  21.  
  22. "FINE PRINT"
  23. By using this script you hereby agree to the above terms and conditions,
  24. if any violation of the above terms occurs "legal action" may be taken.
  25. Not understanding the above terms and conditions does NOT mean that
  26. they do not apply to you.
  27. If you wish to discuss the terms and conditions in further detail you can
  28. contact me at http://dekitarpg.wordpress.com/ or DekitaRPG@gmail.com
  29.  
  30. ================================================================================
  31. History:
  32. =========
  33. D /M /Y
  34. 14/o1/2o13 - compatability update, (Enemy Natures (evs))
  35. 13/11/2o12 - finished,
  36.  
  37. ================================================================================
  38. Credit and Thanks to :
  39. =======================
  40.  
  41. ================================================================================
  42. Known Bugs:
  43. ============
  44. N/A
  45.  
  46. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  47. If a new bug is found please contact me at
  48. http://dekitarpg.wordpress.com/
  49.  
  50. ================================================================================
  51. INSTRUCTIONS:
  52. ==============
  53. Place this script UNDER "▼ Materials" and ABOVE "▼ Main" in your script editor.
  54. Place this script below "Dekita Pokémon CORE"
  55.  
  56. ================================================================================
  57. Notetags:
  58. ==========
  59. ~ ENEMIES
  60. <poke id: X>
  61. notetag for enemies so the game knows which actor
  62. to aqquire when enemy is captured.
  63. Replace X with the actors id
  64.  
  65. <catch rate: X>
  66. notetag for enemies catch rates
  67. replace X with a value between 0 - 255
  68. Higher = Easier to catch (default is random)
  69.  
  70. ~ SKILLS / ITEMS
  71. <pokeball: X>
  72. replace X with a float value (e.g 1.8) to change that items capture rate
  73. NOTE : capture rates are usually between 1.0 and 3.5 (modern pokemon games)
  74. NOTE 2 : Masterballs have a value of 255 (this guarantees capture)
  75.  
  76. ~ STATUS EFFECTS (states)
  77. <capt rate mod: X>
  78. Notetag for status effects to modify capture rate
  79. replace X with a float value (e.g 1.8)
  80. Note : stat modifiers are usually between 1.0 - 2.0
  81. Default is 1.0
  82.  
  83.  
  84.  
  85. SCRIPT CALLS
  86.  
  87. $game_party.party_can_capture = boolean
  88.  
  89. replace boolean with true or false
  90. true = can capture enemies
  91. false = can't
  92.  
  93. =end #==========================================================================#
  94. module Dekita__Pokémon_Capture
  95. #==============================================================================
  96.  
  97. # This script requires Pokemon CORE
  98.  
  99. # This is the animation that happens when a pokemon breaks out
  100. # of the pokeball.
  101. Capture_Fail_Ani = 37#25
  102.  
  103. # Time to wait before capture success / failure
  104. Capture_Wait_time = 360 # Frames
  105.  
  106. #===============================================================================#
  107. #☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#
  108. # #
  109. # http://dekitarpg.wordpress.com/ #
  110. # #
  111. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆#
  112. #===============================================================================#
  113. # ARE YOU MODIFYING BEYOND THIS POINT? \.\. #
  114. # YES?\.\. #
  115. # OMG, REALLY? \| #
  116. # WELL SLAP MY FACE AND CALL ME A DITTO.\..\.. #
  117. # I REALLY DIDN'T THINK YOU HAD IT IN YOU.\..\.. #
  118. #===============================================================================#
  119.  
  120. unless $imported[:Dekita__Pokémon_CORE]
  121. msgbox("'Dekita__Pokémon_Capture'
  122. The Above Script Requires 'Dekita__Pokémon_CORE' in order to function properly,
  123. It must also be placed below it!
  124.  
  125. You can get the latest version of all my scripts @
  126. http://dekitarpg.wordpress.com/")
  127. exit
  128. end
  129.  
  130. end # Dekita__Pokémon_Capture
  131.  
  132. $imported = {} if $imported.nil?
  133. $imported[:Dekita_Pokémon_Capture] = true
  134.  
  135. #==============================================================================
  136. module DataManager
  137. #==============================================================================
  138.  
  139. class <<self; alias load_database_Poké_Capt load_database; end
  140. def self.load_database
  141. load_database_Poké_Capt
  142. load_notetags_Poké_Capt
  143. end
  144.  
  145. def self.load_notetags_Poké_Capt
  146. groups = [$data_items, $data_enemies, $data_states]
  147. for group in groups
  148. for obj in group
  149. next if obj.nil?
  150. obj.load_notetags_Poké_Capt
  151. end
  152. end
  153. end
  154.  
  155. end # DataManager
  156.  
  157. #==============================================================================
  158. module BattleManager
  159. #==============================================================================
  160. class <<self; alias bmanager_Process_Vict_for_Capturez process_victory; end
  161. def self.process_victory
  162. bmanager_Process_Vict_for_Capturez
  163. addthepokemonintoparty
  164. end
  165.  
  166. def self.addthepokemonintoparty
  167. $game_troop.members.each do |member|
  168. next unless $data_enemies[member.enemy_id].note =~ /<poke id: (.*)>/i
  169. next unless member.captured
  170. $game_temp.captured_enemy = member
  171. $game_party.capture_pokemon($data_enemies[member.enemy_id].pokemon_id)
  172. end
  173. $game_temp.captured_enemy = nil
  174. $game_temp.captured_enemyBEFORE = [nil, nil, [nil]]
  175. end
  176.  
  177. end # BattleManager
  178.  
  179. #===============================================================================#
  180. class Game_Temp
  181. #===============================================================================#
  182.  
  183. attr_accessor :captured_enemy
  184. attr_accessor :captured_enemyBEFORE
  185. attr_accessor :pokeball_used
  186. attr_accessor :capture_status
  187.  
  188. alias pokecapturegtinit initialize
  189. def initialize
  190. pokecapturegtinit
  191. @captured_enemy = nil
  192. @captured_enemyBEFORE = [nil, nil, [nil]] # [hp , mp, [states]]
  193. @pokeball_used = []
  194. @capture_status = [false, 0]
  195. end
  196.  
  197. end # Game_Temp
  198.  
  199. #==============================================================================
  200. class Game_Party < Game_Unit
  201. #==============================================================================
  202.  
  203. attr_accessor :party_can_capture
  204.  
  205. alias canptureinit initialize
  206. def initialize
  207. canptureinit
  208. @party_can_capture = true
  209. end
  210.  
  211. def capture_pokemon(actor_id)
  212. new_actor = $data_actors[actor_id].clone
  213. new_actor.id = $data_actors.size
  214. $data_actors.push(new_actor)
  215. @actors.push(new_actor.id) unless @actors.include?(new_actor.id)
  216. $game_player.refresh
  217. $game_map.need_refresh = true
  218. get_enemy_stats(new_actor.id)
  219. get_pokeball_aftermod(new_actor.id)
  220. name_pokemon?(new_actor.id) if $imported[:Dekita_Pokémon_Capture["RENAME"]]
  221. end
  222.  
  223. def get_enemy_stats(actor_id)
  224. _GT = $game_temp.captured_enemy
  225. _GTB = $game_temp.captured_enemyBEFORE
  226. _GA = $game_actors[actor_id]
  227. get_nature_shit(_GA, _GT) if $imported[:Dekita_Pokémon_Natures]
  228. get_regular_shit(_GA, _GT, _GTB)
  229. $game_party.members[0].add_pokemon_into_team(actor_id)
  230. end
  231.  
  232. def get_nature_shit(_GA, _GT)
  233. 8.times {|i| _GA.init_ivs[i] = _GT.init_ivs[i] }
  234. 8.times {|i| _GA.curr_evs[i] = _GT.curr_evs[i] }
  235. _GA.nature = _GT.nature
  236. end
  237.  
  238. def get_regular_shit(_GA, _GT, _GTB)
  239. gpm0 = $game_party.members[0]
  240. _GA.change_level(_GT.level, false)
  241. _GA.hp = _GTB[0]
  242. _GA.mp = _GTB[1]
  243. _GTB[2].each {|state| _GA.add_state(state.id) }
  244. _GA.capt_inf[5] = _GA.level
  245. _GA.capt_inf[6] = gpm0.name
  246. _GA.capt_inf[7] = gpm0.trainer_id
  247. # _GA.ot(gpm0.orig_trainer) if _GA.orig_trainer == ""
  248. end
  249.  
  250. def get_ot_inf(_GA)
  251. end
  252.  
  253. def name_pokemon?(actor_id)
  254. SceneManager.call(Scene_Rename_Pokemon)
  255. SceneManager.scene.prepare(actor_id)
  256. end
  257.  
  258. end
  259.  
  260. #==============================================================================
  261. class RPG::Enemy < RPG::BaseItem
  262. #==============================================================================
  263.  
  264. attr_accessor :pokemon_id
  265. attr_accessor :catch_rate
  266.  
  267. def load_notetags_Poké_Capt
  268. @pokemon_id = 0
  269. @catch_rate = rand(256)
  270. self.note.split(/[\r\n]+/).each { |line|
  271. case line
  272. when /<poke id: (.*)>/i
  273. @pokemon_id = $1.to_i
  274. #---
  275. when /<catch rate: (.*)>/i
  276. @catch_rate = $1.to_i
  277. #---
  278. end
  279. } # self.note.split
  280. #---
  281. end
  282.  
  283. end # RPG::Enemy
  284.  
  285. #==============================================================================
  286. class RPG::State < RPG::BaseItem
  287. #==============================================================================
  288.  
  289. attr_accessor :capture_modifier
  290.  
  291. def load_notetags_Poké_Capt
  292. @capture_modifier = 1.0
  293. self.note.split(/[\r\n]+/).each { |line|
  294. case line
  295. when /<capt rate mod: (.*)>/i
  296. @capture_modifier = $1.to_f
  297. #---
  298. end
  299. } # self.note.split
  300. #---
  301. end
  302.  
  303. end # RPG::State < RPG::BaseItem
  304.  
  305. #==============================================================================
  306. class RPG::UsableItem < RPG::BaseItem
  307. #==============================================================================
  308.  
  309. attr_accessor :capture_item
  310. attr_accessor :pokeball_capt_rate
  311. attr_accessor :pokeball_effect
  312.  
  313. def load_notetags_Poké_Capt
  314. @capture_item = false
  315. @pokeball_capt_rate = 0.0
  316. @pokeball_effect = [false, 0]
  317. self.note.split(/[\r\n]+/).each { |line|
  318. case line
  319. when /<pokeball: (.*)>/i
  320. @pokeball_capt_rate = $1.to_f
  321. @capture_item = true
  322. end
  323. } # self.note.split
  324. #---
  325. end
  326.  
  327. end # RPG::Enemy
  328.  
  329. #==============================================================================
  330. class Game_Enemy < Game_Battler
  331. #==============================================================================
  332.  
  333. attr_accessor :captured
  334. attr_accessor :pokemon_id
  335. attr_accessor :catch_rate
  336.  
  337. alias gamepokenmyinit initialize
  338. def initialize(index, enemy_id)
  339. gamepokenmyinit(index, enemy_id)
  340. @captured = false
  341. @pokemon_id = $data_enemies[enemy_id].pokemon_id
  342. @catch_rate = $data_enemies[enemy_id].catch_rate
  343. end
  344.  
  345. alias captred_pokemon_xp_rate exp
  346. def exp
  347. return 0 if @captured == true
  348. captred_pokemon_xp_rate
  349. end
  350.  
  351. alias captred_pokemon_gold_rate gold
  352. def gold
  353. return 0 if @captured == true
  354. captred_pokemon_gold_rate
  355. end
  356.  
  357. alias captred_pokemon_drop_items_rate drop_item_rate
  358. def drop_item_rate
  359. return 0 if @captured == true
  360. captred_pokemon_drop_items_rate
  361. end
  362.  
  363. end # Game_Enemy
  364.  
  365. #==============================================================================
  366. module Cache
  367. #==============================================================================
  368.  
  369. def self.pokeballs(filename)
  370. load_bitmap("Graphics/System/Pokeballs/", filename)
  371. end
  372.  
  373. end
  374.  
  375. #==============================================================================
  376. class Scene_Battle < Scene_Base
  377. #==============================================================================
  378.  
  379. alias capturebattlesstart start
  380. def start
  381. capturebattlesstart
  382. @battle_turn_count = 0
  383. @capturing_now = false
  384. @inside_pokeball = false
  385. @capture_failed = false
  386. end
  387.  
  388. alias invoke_pokemon_captureitem invoke_item
  389. def invoke_item(target, item)
  390. if target.is_a?(Game_Enemy) && !(target.pokemon_id == (nil || 0)) && item.capture_item
  391. capture_pokemon?(target, item)
  392. end
  393. invoke_pokemon_captureitem(target, item)
  394. end
  395.  
  396. def capture_pokemon?(target, item)
  397. if $game_party.party_can_capture
  398. create_pokeball_sprite(target)
  399. @capturing_now = true
  400. did_capture?(target, item)
  401. else
  402. $game_message.add("Cant Capture This Enemy")
  403. end
  404. end
  405.  
  406. def did_capture?(target, item)
  407. ball_rate = get_pokeball_capture_rate(target, item)
  408. t = target
  409. status_capt_mod = get_states_modifier(t)
  410. catchValue = ((3*t.mhp-2*t.hp)*(t.catch_rate*ball_rate)/(3*t.mhp))*status_capt_mod
  411. catch = (2**20-2**4)/Math.sqrt(Math.sqrt((2**24-2**16)/catchValue))
  412. regular_capture(t, item, catch.round)
  413. p "catchValue = #{catchValue}"
  414. p "catch = #{catch}"
  415. end
  416.  
  417. def get_pokeball_capture_rate(target, item)
  418. value = item.pokeball_capt_rate
  419. return value
  420. end
  421.  
  422. def get_states_modifier(target)
  423. value = 1.0
  424. t = target
  425. t.states.size.times {|i| value *= t.states[i].capture_modifier }
  426. return value
  427. end
  428.  
  429. def masterball_capture(target, item)
  430. amount = Dekita__Pokémon_Capture::Capture_Wait_time
  431. target.captured = true
  432. amount.times {|i| update_for_wait }
  433. sucessfullcapture(target, item)
  434. end
  435.  
  436. def regular_capture(target, item, catch)
  437. amount = (Dekita__Pokémon_Capture::Capture_Wait_time / 3).to_i
  438. value = catch
  439. success = rand(65535+1)
  440. 50.times {|| update_for_wait }
  441. target.animation_id = 37
  442. @inside_pokeball = true
  443. 60.times {||update_basic }
  444. target.screen_y -= (Graphics.height * 2)
  445. amount.times {|i| update_for_wait }
  446. if success > value
  447. p "Failed at try 1"
  448. else
  449. success = rand(65535+1)
  450. if success > value
  451. p "Failed at try 2"
  452. else
  453. success = rand(65535+1)
  454. if success > value
  455. p "Failed at try 3"
  456. else
  457. success = rand(65535+1)
  458. if success > value
  459. p "Failed at try 4"
  460. else
  461. target.captured = true
  462. end
  463. end
  464. end
  465. end
  466. if target.captured
  467. sucessfullcapture(target, item)
  468. else
  469. capture_failed(target, item)
  470. end
  471. end
  472.  
  473. def sucessfullcapture(target, item)
  474. $game_temp.captured_enemyBEFORE[0] = target.hp
  475. $game_temp.captured_enemyBEFORE[1] = target.mp
  476. $game_temp.captured_enemyBEFORE[2] = target.states
  477. $game_temp.pokeball_used = item
  478. target.hp -= target.hp
  479. end
  480.  
  481. def capture_failed(target, item)
  482. @capture_failed = true
  483. target.screen_y += (Graphics.height * 2)
  484. target.animation_id = Dekita__Pokémon_Capture::Capture_Fail_Ani
  485. 20.times {|i| update_for_wait }
  486. end
  487.  
  488. def pokemon_already_captured?(poke_id)
  489. istrue = 0
  490. $game_party.members.size.times{|i|
  491. istrue += 1 if $game_party.members[i].pokemon_database_id == poke_id
  492. }
  493. return true if istrue > 0
  494. return false
  495. end
  496.  
  497. alias turn_end_count_forpoke turn_end
  498. def turn_end
  499. turn_end_count_forpoke
  500. @battle_turn_count += 1
  501. p "#{@battle_turn_count} <= @battle_turn_count"
  502. end
  503.  
  504. end
  505.  
  506. #===============================================================================#
  507. # - SCRIPT END - #
  508. #===============================================================================#
  509. # http://dekitarpg.wordpress.com/ #
  510. #===============================================================================#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement