skydangerous

Untitled

Nov 23rd, 2011
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 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 = 2 * 60,
  16.         control = 5052,
  17.         test = math.random(0,1),
  18.         sto = 5152
  19.     }
  20.     if not npcHandler:isFocused(cid) then
  21.         return false
  22.     end
  23.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  24.    
  25.     if msgcontains(msg, "care") then
  26.         local p = (config.price % 1000 == 0 and (config.price / 1000) or config.price)
  27.         if getPlayerStorageValue(cid, config.control) > os.time() then
  28.             selfSay("Sorry, but I am already caring one of your eggs.", cid)
  29.         else
  30.             selfSay("Do you want me to take care of your egg for ".. p .." ".. (p == config.price and "" or "k") .."?", cid)
  31.             talkState[talkUser] = 1
  32.         end
  33.    
  34.     elseif msgcontains(msg, "back") then
  35.             local s = getPlayerStorageValue(cid,config.sto)    
  36.                     if s == true then
  37.                 selfSay("Ola, voce veio pegar seu ovo?.", cid)
  38.             else
  39.             selfSay("Desculpa, voce nao pois nemhum ovo para chocar",cid)
  40.             talkState[talkUser] = 2
  41.         end
  42.    
  43.     elseif msgcontains(msg, "check") then
  44.         local t = getPlayerStorageValue(cid, config.control)
  45.         if t < os.time() then
  46.             selfSay("Yay, your egg has hatched and I've encountered a cute pet!", cid)
  47.         else
  48.             selfSay("I will be caring your egg for more ".. math.floor((t - os.time()) / 60) .." minutes and ".. (t - os.time()) % 60 .." seconds.", cid)
  49.         end
  50.      
  51.     elseif talkState[talkUser] == 1 then
  52.         if msgcontains(msg, "yes") then
  53.             if doPlayerRemoveMoney(cid, config.price) then
  54.                 setPlayerStorageValue(cid, config.control, os.time()+config.delay)
  55.                 setPlayerStorageValue(cid,sky.sto)         
  56.                 selfSay("Okay! Check back soon.", cid)
  57.             else
  58.                 selfSay("Sorry, you don't have enough money. You need more ".. (config.price - getPlayerMoney(cid)) .." coins.", cid)
  59.             end
  60.         elseif talkState[talkUser] == 2 then
  61.             local x = getPlayerStorageValue(cid, config.control)
  62.                 if msgcontains(msg, "yes") then
  63.                 if x > os.time() then
  64.                 selfSay("Tome seu ovo.", cid)
  65.             else
  66.                 selfSay("Desculpa voce deve esperar o tempo para pegar.", cid)
  67.             end
  68.                
  69.         elseif msgcontains(msg, "no") then
  70.             selfSay("Too pricey for you, heh?", cid)
  71.         end  
  72.         end
  73.        end  
  74.     return true
  75.     end
  76.  
  77.  
  78. 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.")
  79. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSayCallback)
  80. npcHandler:addModule(FocusModule:new())    
  81.  
Advertisement
Add Comment
Please, Sign In to add comment