skydangerous

Untitled

Nov 23rd, 2011
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 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.         eggn = 4850,
  20.        
  21.     }
  22.     if not npcHandler:isFocused(cid) then
  23.         return false
  24.     end
  25.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  26.    
  27.     if msgcontains(msg, "care") then
  28.         local p = (config.price % 1000 == 0 and (config.price / 1000) or config.price)
  29.         if getPlayerStorageValue(cid, config.control) > os.time() then
  30.             selfSay("Sorry, but I am already caring one of your eggs.", cid)
  31.         else
  32.             selfSay("Do you want me to take care of your egg for ".. p .." ".. (p == config.price and "" or "k") .."?", cid)
  33.             talkState[talkUser] = 1
  34.         end
  35.    
  36.     elseif msgcontains(msg, "back") then
  37.             local s = getPlayerStorageValue(cid,config.sto)    
  38.                     if s == 1 then
  39.                 selfSay("Hello, you came to pick up your egg?.", cid)
  40.             else
  41.             selfSay("Sorry, you do not because no egg to hatch",cid)
  42.             talkState[talkUser] = 2
  43.         end
  44.    
  45.     elseif msgcontains(msg, "check") then
  46.         local t = getPlayerStorageValue(cid, config.control)
  47.         if t < os.time() then
  48.             selfSay("Yay, your egg has hatched and I've encountered a cute pet!", cid)
  49.         else
  50.             selfSay("I will be caring your egg for more ".. math.floor((t - os.time()) / 60) .." minutes and ".. (t - os.time()) % 60 .." seconds.", cid)
  51.         end
  52.      
  53.     elseif talkState[talkUser] == 1 then
  54.         if msgcontains(msg, "yes") then
  55.             if doPlayerRemoveMoney(cid, config.price) then
  56.                 setPlayerStorageValue(cid, config.control, os.time()+config.delay)
  57.                 selfSay("Okay! Check back soon.", cid)
  58.             else
  59.                 selfSay("Sorry, you don't have enough money. You need more ".. (config.price - getPlayerMoney(cid)) .." coins.", cid)
  60.             end
  61.            
  62.        
  63.         elseif talkState[talkUser] == 2 then
  64.             local x = getPlayerStorageValue(cid, config.control)
  65.                     if msgcontains(msg, "yes") then
  66.                 if x > os.time() then
  67.                     if doPlayerTakeItem(cid,onfig.eggn,1) then
  68.                  doSetItemSpecialDescription(config.eggn, "Shocked egg")
  69.                 selfSay("take your egg.", cid)             
  70.             else
  71.                 selfSay("Sorry you must wait long to get.", cid)
  72.             end
  73.                
  74.         elseif msgcontains(msg, "no") then
  75.             selfSay("Too pricey for you, heh?", cid)
  76.         end  
  77.         end
  78.        end  
  79.         end
  80.     return true
  81.     end
  82.    
  83.    
  84.  
  85. 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, if you want to get your egg talk {back}.")
  86. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSayCallback)
  87. npcHandler:addModule(FocusModule:new())    
  88.  
Advertisement
Add Comment
Please, Sign In to add comment