Guest User

peach.lua

a guest
Dec 26th, 2013
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. local talkState = {}
  5.  
  6. local Aluguel_mounts = {
  7.     ["brown war horse"] = {price = 10000, days = 2, mountid = 17, level = 10, premium = false, storage = 50561},
  8.     ["fire war horse"] = {price = 30000, days = 1, mountid = 23, level = 20, premium = false, storage = 50562},
  9.     ["king scorpion"] = {price = 50000, days = 1, mountid = 21, level = 30, premium = false, storage = 50563}
  10. }
  11.  
  12. function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
  13. function onCreatureDisappear(cid)            npcHandler:onCreatureDisappear(cid)            end
  14. function onCreatureSay(cid, type, msg)            npcHandler:onCreatureSay(cid, type, msg)        end
  15. function onThink()                    npcHandler:onThink()                    end
  16.  
  17. function creatureSayCallback(cid, type, msg)
  18.     if not npcHandler:isFocused(cid) then
  19.         return false
  20.     end
  21.    
  22.     local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
  23.     local msg = string.lower(msg)
  24.     if isInArray({"rent", "mounts", "mount"}, msg) then
  25.         selfSay("You can buy {brown war horse}, {fire war horse} and {king scorpion}!", cid)
  26.         talkState[talkUser] = 1
  27.     elseif talkState[talkUser] == 1 then
  28.         if Aluguel_mounts[msg] then
  29.             if Aluguel_mounts[msg].premium == true and not isPremium(cid) then
  30.                 selfSay('You need to be premium to rent this mount.', cid) return true
  31.             elseif getPlayerLevel(cid) < Aluguel_mounts[msg].level then
  32.                 selfSay('You need level ' .. Aluguel_mounts[msg].level .. ' or more to rent this mount.', cid) return true
  33.             elseif getPlayerStorageValue(cid, Aluguel_mounts[msg].storage) >= os.time() then
  34.                 selfSay('you already have rented this mount!', cid) return true
  35.             end
  36.            
  37.             name, price, stor, days, mountid = msg, Aluguel_mounts[msg].price, Aluguel_mounts[msg].storage, Aluguel_mounts[msg].days, Aluguel_mounts[msg].mountid
  38.             selfSay('You want to rent the mount '..name..' for '..days..' day'..(days > 1 and 's' or '')..' the price '..price..' gps? {yes}', cid)
  39.             talkState[talkUser] = 2
  40.         else
  41.             selfSay('Sorry, I do not sell this mount.', cid)
  42.         end
  43.     elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
  44.         if doPlayerRemoveMoney(cid, price) then
  45.             doPlayerAddMount(cid, mountid)
  46.             setPlayerStorageValue(cid, stor, os.time()+days*86400)
  47.             selfSay('Here is your mount '..name..', it will last until '..os.date("%d %B %Y %X", getPlayerStorageValue(cid,stor))..'.', cid)
  48.         else
  49.             selfSay('you do not have enough money to rent the mount!', cid)
  50.             talkState[talkUser] = 0
  51.         end
  52.     elseif msgcontains(msg, "no") then
  53.         selfSay("Then not", cid)
  54.         talkState[talkUser] = 0
  55.         npcHandler:releaseFocus(cid)
  56.     end
  57.     return true
  58. end
  59.  
  60. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  61. npcHandler:addModule(FocusModule:new())
RAW Paste Data