beeki

Premium por Points NPC

May 29th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. local talkState = {}
  5. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  6. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  7. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  8. function onThink() npcHandler:onThink() end
  9. function creatureSayCallback(cid, type, msg)
  10. if(not npcHandler:isFocused(cid)) then
  11. return false
  12. end
  13. function getNumber(txt)
  14. x = string.gsub(txt,"%a","")
  15. x = tonumber(x)
  16. if x ~= nill and x > 0 then
  17. return x
  18. else
  19. return 0
  20. end
  21. end
  22. local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
  23. msg = string.lower(msg)
  24. sell = {[7] = 10, [15] = 20, [30] = 50}
  25. if (msgcontains(msg, 'premium'))then
  26. npcHandler:say("Eu vendo {7}, {15} e {30} dias de premium, qual o senhor deseja comprar?", cid)
  27. talkState[talkUser] = 1
  28. elseif talkState[talkUser] == 1 then
  29. if sell[getNumber(msg)] then
  30. days,p = getNumber(msg),sell[getNumber(msg)]
  31. selfSay('você quer comprar '..days..' dias de premium por '..p..' points? {yes}', cid)
  32. talkState[talkUser] = 2
  33. else
  34. npcHandler:say("escolha somente números, 7, 15 ou 30 dias.", cid)
  35. end
  36. elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
  37. if getAccountPoints(cid) >= p then
  38. if getPlayerPremiumDays(cid) < 360 then
  39. doPlayerAddPremiumDays(cid, days)
  40. doAccountRemovePoints(cid, p)
  41. npcHandler:say("Obrigado, você comprou "..days.." dias de premium com sucesso, relogue completamente agora.", cid)
  42. talkState[talkUser] = 0
  43. else
  44. npcHandler:say("Você não pode ter mais que 360 dias de premium.", cid)
  45. end
  46. else
  47. npcHandler:say("Você precisa ter "..p.." points.", cid)
  48. end
  49. elseif msg == "no" and talkState[talkUser] >= 1 then
  50. selfSay("tudo bem então.", cid)
  51. talkState[talkUser] = 0
  52. npcHandler:releaseFocus(cid)
  53. end
  54. return TRUE
  55. end
  56. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  57. npcHandler:addModule(FocusModule:new())
Add Comment
Please, Sign In to add comment