Advertisement
Skymagnum

Untitled

May 31st, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.79 KB | None | 0 0
  1. local focus = 0
  2. local max_distance = 8
  3. local talk_start = 0
  4. local conv = 0
  5. local fighting = false
  6. local challenger = 0
  7. local afk_limit_time = 30 -- seconds
  8. local afk_time = 0 -- don't change
  9. local battle_turn = 1 -- don't change
  10. local challenger_turn = 0 -- don't change
  11. local masterpos = {}
  12. local time_to_fight_again = 15 -- seconds, not ms (so 30 * 60 means 30 minutes)
  13.  
  14. local can_walk = true -- true to make this npc walks randomly
  15. local max_distance = 5 -- maximum distance this npc can get far (sqms)
  16. local walk_delay = 7 -- every seconds make this npc walk
  17.  
  18. local cooldown_table = {}
  19.  
  20. local min_pokemons_to_battle = 1-- change to whatever you want
  21. local number_of_pokemons = 0 -- don't change
  22.  
  23. local prizes = {
  24. [1] = {{itemid = 2393, count = 30}, {itemid = 2392, count = 20}},
  25. [2] = {{itemid = 2393, count = 40}, {itemid = 2392, count = 30}},
  26. [3] = {{itemid = 2393, count = 50}, {itemid = 2392, count = 40}},
  27. [4] = {{itemid = 2393, count = 60}, {itemid = 2392, count = 50}},
  28. [5] = {{itemid = 2393, count = 70}, {itemid = 2392, count = 60}},
  29. [6] = {{itemid = 2393, count = 80}, {itemid = 2392, count = 70}}}
  30.  
  31. local pokemons = {
  32. {name = "Cloyster", optionalLevel = 50, sex = SEX_MALE, nick = "Crusher", ball = "super"},
  33. {name = "Lapras", optionalLevel = 50, sex = SEX_FEMALE, nick = "Laura", ball = "normal"},
  34. {name = "Electabuzz", optionalLevel = 50, sex = SEX_MALE, nick = "Eletron", ball = "great"},
  35. {name = "Pinsir", optionalLevel = 50, sex = SEX_MALE, nick = "Headcutter", ball = "normal"},
  36. {name = "Dragonair", optionalLevel = 50, sex = SEX_FEMALE, nick = "Dragonix", ball = "ultra"},
  37. }
  38.  
  39.  
  40. local function doSummonGymPokemon(npc)
  41. local this = npc
  42. if not isCreature(this) then return true end
  43. if #getCreatureSummons(this) >= 1 or focus == 0 then return true end
  44. local it = pokemons[battle_turn]
  45. doSummonMonster(this, it.name)
  46. local summon = getCreatureSummons(this)[1]
  47. local balleffect = pokeballs["normal"].effect
  48. if it.ball and pokeballs[it.ball] then
  49. balleffect = pokeballs[it.ball].effect
  50. end
  51. doSendMagicEffect(getThingPos(summon), balleffect)
  52. setPlayerStorageValue(summon, 10000, balleffect)
  53. setPlayerStorageValue(summon, 10001, gobackmsgs[math.random(#gobackmsgs)].back:gsub("doka", it.nick ~= "" and it.nick or it.name))
  54. setPlayerStorageValue(summon, 1007, it.nick ~= "" and it.nick or it.name)
  55. doSetMonsterGym(summon, focus)
  56. local name = it.nick ~= "" and it.nick or getCreatureName(this).."s "..it.name
  57. addEvent(adjustWildPoke, 15, summon, it.optionalLevel)
  58. doCreatureSay(this, gobackmsgs[math.random(#gobackmsgs)].go:gsub("doka", getPlayerStorageValue(summon, 1007)), 1)
  59. fighting = true
  60. battle_turn = battle_turn + 1
  61. end
  62.  
  63. local function doWinDuel(cid, npc)
  64. if not isCreature(cid) then return true end
  65. local this = npc
  66. local x = prizes[number_of_pokemons]
  67. for n = 1, #x do
  68. doPlayerAddItem(cid, x[n].itemid, x[n].count)
  69. end
  70. doCreatureSay(npc, "Congratulations! You won, here is your prize.", 1)
  71. cooldown_table[getCreatureName(cid)] = os.clock() + time_to_fight_again
  72. return true
  73. end
  74.  
  75. function onCreatureSay(cid, type, msg)
  76.  
  77. local msg = string.lower(msg)
  78.  
  79. if focus == cid then
  80. talk_start = os.clock()
  81. end
  82.  
  83. if msgcontains(msg, 'hi') and focus == 0 and getDistanceToCreature(cid) <= 4 then
  84.  
  85. if cooldown_table[getCreatureName(cid)] and cooldown_table[getCreatureName(cid)] - os.clock() > 0 then
  86. selfSay("Hello "..getCreatureName(cid)..", I really enjoyed our last battle!")
  87. conv = 10
  88. else
  89. selfSay("Hello "..getCreatureName(cid)..", are you up to a duel? I can give prizes if you win!")
  90. conv = 1
  91. end
  92.  
  93. focus = cid
  94. talk_start = os.clock()
  95. return true
  96. end
  97.  
  98. if (isDuelMsg(msg) or isConfirmMsg(msg)) and (conv == 1 or conv == 10) and focus == cid then
  99.  
  100. if conv == 10 then
  101. selfSay("We have just battled! Please wait for me to recover from out last battle!")
  102. focus = 0
  103. return true
  104. end
  105.  
  106. if not hasPokemon(cid) then
  107. selfSay("You need pokemons to battle!")
  108. return true
  109. end
  110.  
  111. selfSay("Ok, tell me how many pokemons will fight.")
  112. conv = 2
  113.  
  114. return true
  115. end
  116.  
  117. if conv == 2 and focus == cid then
  118.  
  119. if not tonumber(msg) then
  120. selfSay("Tell me the number of pokemons that will battle.")
  121. return true
  122. elseif tonumber(msg) > #pokemons then
  123. selfSay("I have only "..#pokemons..", so the maximum is "..#pokemons.."!")
  124. return true
  125. elseif tonumber(msg) < min_pokemons_to_battle or tonumber(msg) < 1 then
  126. selfSay("It has to be more than "..min_pokemons_to_battle..".")
  127. return true
  128. else
  129. number_of_pokemons = tonumber(msg)
  130. selfSay("Ok, the first that defeats "..number_of_pokemons.." wins, let's start!")
  131. challenger = focus
  132. setPlayerStorageValue(cid, 990, 1)
  133. addEvent(doSummonGymPokemon, 850, getThis())
  134. conv = 3
  135. return true
  136. end
  137.  
  138.  
  139. return true
  140. end
  141.  
  142. if isNegMsg(msg) and conv == 1 and focus == cid then
  143.  
  144. focus = 0
  145. selfSay("It is better for you to refuse a battle against me!")
  146.  
  147. return true
  148. end
  149.  
  150. if msgcontains(msg, 'bye') and focus == cid then
  151. selfSay('Bye and do your best trainer!')
  152. setPlayerStorageValue(focus, 990, -1)
  153. focus = 0
  154. return true
  155. end
  156. end
  157.  
  158. local afk_warning = false
  159. local change = false
  160. local walkdelay = 0
  161.  
  162. function onThink()
  163.  
  164. if not masterpos.x then
  165. masterpos = getThingPos(getThis())
  166. end
  167.  
  168. if focus == 0 then
  169. selfTurn(2)
  170. fighting = false
  171. challenger = 0
  172. change = false
  173. challenger_turn = 0
  174. battle_turn = 1
  175. afk_time = 0
  176. afk_warning = false
  177.  
  178. if #getCreatureSummons(getThis()) >= 1 then
  179. setPlayerStorageValue(getCreatureSummons(getThis())[1], 1006, 0)
  180. doCreatureAddHealth(getCreatureSummons(getThis())[1], -getCreatureMaxHealth(getCreatureSummons(getThis())[1]))
  181. end
  182.  
  183. walkdelay = walkdelay - 0.5
  184.  
  185. if walkdelay <= 0 then
  186. walkdelay = walk_delay
  187. local pos = getThingPos(getThis())
  188. local npos = {}
  189. for a = 0, 3 do
  190. if getDistanceBetween(getPosByDir(pos, a), masterpos) <= max_distance and canWalkOnPos(getPosByDir(pos, a), true, false, true, true, false) then
  191. table.insert(npos, getPosByDir(pos, a))
  192. end
  193. end
  194.  
  195. if npos and #npos > 0 then
  196. doTeleportThing(getThis(), npos[math.random(#npos)])
  197. end
  198. end
  199.  
  200. return true
  201. else
  202.  
  203. if not isCreature(focus) then
  204. focus = 0
  205. return true
  206. end
  207.  
  208. if fighting then
  209.  
  210. talk_start = os.clock()
  211.  
  212. if not isCreature(getCreatureTarget(getThis())) then
  213. if #getCreatureSummons(challenger) >= 1 then
  214. if getCreatureOutfit(getCreatureSummons(challenger)[1]).lookType ~= 2 then --alterado v1.6
  215. selfAttackCreature(getCreatureSummons(challenger)[1])
  216. change = true
  217. afk_time = 0
  218. end
  219. else
  220. afk_time = afk_time + 0.5
  221. if change then
  222. change = false
  223. challenger_turn = challenger_turn + 1
  224. end
  225. end
  226. end
  227.  
  228. if afk_time > afk_limit_time then
  229. setPlayerStorageValue(focus, 990, -1)
  230. focus = 0
  231. selfSay("I have waited too long, come back when you are ready!")
  232. return true
  233. end
  234.  
  235. if not afk_warning and afk_time > afk_limit_time / 2 then
  236. selfSay("Where's your pokemon? Let's fight!")
  237. afk_warning = true
  238. end
  239.  
  240.  
  241. if #getCreatureSummons(getThis()) == 0 then
  242. if battle_turn > number_of_pokemons then
  243. addEvent(doWinDuel, 1000, focus, getThis())
  244. setPlayerStorageValue(focus, 990, -1)
  245. focus = 0
  246. return true
  247. end
  248. addEvent(doSummonGymPokemon, 1000, getThis())
  249. end
  250.  
  251. if not hasPokemon(challenger) or challenger_turn > 6 or challenger_turn >= number_of_pokemons then
  252. selfSay("You lost our duel! Maybe some other time you'll defeat me.")
  253. setPlayerStorageValue(focus, 990, -1)
  254. focus = 0
  255. return true
  256. end
  257.  
  258. end
  259.  
  260. local npcpos = getThingPos(getThis())
  261. local focpos = getThingPos(focus)
  262.  
  263. if npcpos.z ~= focpos.z then
  264. setPlayerStorageValue(focus, 990, -1)
  265. focus = 0
  266. selfSay("Bye then.")
  267. return true
  268. end
  269.  
  270. if (os.clock() - talk_start) > 30 then
  271. selfSay("Good bye and keep training!")
  272. setPlayerStorageValue(focus, 990, -1)
  273. focus = 0
  274. end
  275.  
  276. if getDistanceToCreature(focus) > max_distance then
  277. setPlayerStorageValue(focus, 990, -1)
  278. focus = 0
  279. return true
  280. end
  281.  
  282. local dir = doRedirectDirection(getDirectionTo(npcpos, focpos))
  283. selfTurn(dir)
  284. end
  285. return true
  286. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement