skydangerous

Untitled

Nov 24th, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. local talkState = {}
  6.  
  7. function onCreatureAppear(cid)          npcHandler:onCreatureAppear(cid)            end
  8. function onCreatureDisappear(cid)       npcHandler:onCreatureDisappear(cid)         end
  9. function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)        end
  10. function onThink()              npcHandler:onThink()                    end
  11.  
  12. function onCreatureSayCallback(cid, type, msg)
  13.     local config = {
  14.         price = 50000,
  15.         delay = 5 * 60,
  16.         control = {10555, 10556},
  17.         eggn = 4850
  18.     }
  19.     if not npcHandler:isFocused(cid) then
  20.         return false
  21.     end
  22.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  23.    
  24.     if msgcontains(msg, "care") then
  25.         local p = (config.price % 1000 == 0 and (config.price / 1000) or config.price)
  26.         if getPlayerStorageValue(cid, config.control) > os.time() then
  27.             selfSay("Sorry, but I am already caring one of your eggs.", cid)
  28.         else
  29.             selfSay("Do you want me to take care of your egg for ".. p .." ".. (p == config.price and "" or "k") .."?", cid)
  30.             talkState[talkUser] = 1
  31.         end
  32.    
  33.     elseif msgcontains(msg, "back") then
  34.         if getPlayerStorageValue(cid, config.control[2]) == 1 then
  35.             selfSay("Hello, do you came to pick up your egg?", cid)
  36.             talkState[talkUser] = 2
  37.         else
  38.             selfSay("Sorry, but I am not caring eggs from you.", cid)
  39.         end
  40.    
  41.     elseif msgcontains(msg, "check") then
  42.         local t = getPlayerStorageValue(cid, config.control[1])
  43.         if getPlayerStorageValue(cid, config.control[2]) == -1 then
  44.             selfSay("Sorry, but I am not caring eggs from you.", cid)
  45.         else
  46.             if t < os.time() then
  47.                 selfSay("Yay, your egg has started to hatch, take it.", cid)
  48.                 setPlayerStorageValue(cid, config.control[1], -1)
  49.                 setPlayerStorageValue(cid, config.control[2], -1)
  50.                 else
  51.                 selfSay("I will be caring your egg for more ".. (math.floor((t - os.time()) / 60) > 0 and "".. math.floor((t - os.time()) / 60) .." minutes and" or "") .." ".. (t - os.time()) % 60 .." seconds.", cid)
  52.             end
  53.         end
  54.     end
  55.      
  56.     if talkState[talkUser] == 1 then
  57.         if msgcontains(msg, "yes") then
  58.             if getPlayerStorageValue(cid, config.control[2]) == -1 then
  59.                 if doPlayerRemoveMoney(cid, config.price) then
  60.                     setPlayerStorageValue(cid, config.control[2], 1)       
  61.                     setPlayerStorageValue(cid, config.control[1], os.time()+config.delay)
  62.                     selfSay("Okay! Check back soon.", cid)
  63.                 else
  64.                     selfSay("Sorry, you don't have enough money. You need more ".. (config.price - getPlayerMoney(cid)) .." coins.", cid)
  65.                 end
  66.             else
  67.                 selfSay("I am already taking care of a egg for you.", cid)
  68.             end
  69.         elseif msgcontains(msg, "no") then
  70.             selfSay("Too pricey for you, heh?", cid)
  71.         end  
  72.     elseif talkState[talkUser] == 2 then
  73.         local x = getPlayerStorageValue(cid, config.control)
  74.         local t = getPlayerStorageValue(cid, config.control[1])
  75.         if msgcontains(msg, "yes") then
  76.             if x > os.time() then
  77.                 local item = doPlayerAddItem(cid, config.eggn, 1)
  78.                 doItemSetAttribute(item, "description", "A hatched egg.")
  79.                 selfSay("Take it!", cid)               
  80.                 setPlayerStorageValue(cid, control[2], -1)
  81.                 setPlayerStorageValue(cid, control[1], -1)
  82.             else
  83.                 selfSay("Sorry, but your egg need care for more ".. (math.floor((t - os.time()) / 60) > 0 and "".. math.floor((t - os.time()) / 60) .." minutes and" or "") .." ".. (t - os.time()) % 60 .." seconds.", cid)
  84.             end
  85.         end
  86.     end  
  87.     return true
  88. end
  89.    
  90. npcHandler:setMessage(MESSAGE_GREET, "Hello, |PLAYERNAME|. I am a pet egg carer. Do you want me to {care} your pet eggs? Also you can {check} the egg status and if you have any egg here, you can get it {back}.")
  91. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSayCallback)
  92. npcHandler:addModule(FocusModule:new())    
  93.  
  94.  
Advertisement
Add Comment
Please, Sign In to add comment