Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.58 KB | None | 0 0
  1.  local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. local talkState = {}
  5.  
  6. function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
  7. function onCreatureDisappear(cid)            npcHandler:onCreatureDisappear(cid)            end
  8. function onCreatureSay(cid, type, msg)            npcHandler:onCreatureSay(cid, type, msg)        end
  9. function onThink()                    npcHandler:onThink()                    end
  10.  
  11. function creatureSayCallback(cid, type, msg)
  12.     if(not npcHandler:isFocused(cid)) then
  13.         return false
  14.     end
  15.  
  16.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  17.  
  18.     if msgcontains(msg, 'marry') or msgcontains(msg, 'marriage') then
  19.         if getPlayerStorageValue(cid,3066) == -1 then
  20.             selfSay('Would you like to get married?', cid)
  21.             talkState[talkUser] = 1
  22.         elseif getPlayerStorageValue(cid,3066) == 1 then
  23.             local fid = getPlayerGUID(cid)
  24.             local marrystatus = getOwnMarryStatus(fid)
  25.             if marrystatus ~= 0 then
  26.                 local newpartner = getPlayerNameByGUID(marrystatus)
  27.                 selfSay('You already set a wedding date with {' .. newpartner .. '}, now I must talk to your partner. Do you want to {cancel} it?', cid)
  28.                 talkState[talkUser] = 5
  29.             else
  30.                 setPlayerStorageValue(cid,3066,-1)
  31.                 selfSay('Would you like to get married?', cid)
  32.                 talkState[talkUser] = 1
  33.             end
  34.         elseif getPlayerStorageValue(cid,3066) == 2 then
  35.             selfSay('You are already married. If you want to {divorce}, just say it.', cid)
  36.             talkState[talkUser] = 0
  37.         end
  38.  
  39.     elseif msgcontains(msg, 'divorce') then
  40.         if getPlayerStorageValue(cid,3066) == 2 then
  41.             selfSay('Would you like to divorce of your partner?', cid)
  42.             talkState[talkUser] = 6
  43.         else
  44.             selfSay('You are not married. If you want to get married, just say {marry}.', cid)
  45.             talkState[talkUser] = 0
  46.         end
  47.     end
  48.  
  49.     if talkState[talkUser] == 1 then
  50.         if msgcontains(msg, 'yes') then
  51.             local fid = getPlayerGUID(cid)
  52.             local marrystatus = getMarryStatus(fid)
  53.             if marrystatus == FALSE then
  54.                 selfSay('And what\'s the name of your future partner?', cid)
  55.                 talkState[talkUser] = 2
  56.             else
  57.                 local marryname = getPlayerNameByGUID(marrystatus)
  58.                 selfSay('{' .. marryname .. '} has set a wedding date with you. Do you want to {proceed} or {cancel} the wedding?', cid)
  59.                 talkState[talkUser] = 4
  60.             end
  61.         end
  62.  
  63.     elseif talkState[talkUser] == 2 then
  64.         local p = msg
  65.         local player = getPlayerName(cid)
  66.         local fid = getPlayerGUID(cid)
  67.         local sid = getPlayerGUIDByName(p)
  68.         if sid == 0 then
  69.             selfSay('A player with that name does not exists.', cid)
  70.             talkState[talkUser] = 0
  71.         elseif sid == fid then
  72.             selfSay('Don\'t worry, you will always be married with yourself, kid.', cid)
  73.             talkState[talkUser] = 0
  74.         else
  75.             local marrystatus = getMarryStatus(fid)
  76.             local pmarriage = getPlayerMarriage(sid)
  77.             local ownstatus = getOwnMarryStatus(cid)
  78.             if pmarriage == FALSE then
  79.                 if marrystatus == FALSE then
  80.                     if ownstatus == FALSE then
  81.                         setPlayerStorageValue(cid,3066,1)
  82.                         addMarryStatus(fid,sid)
  83.                         selfSay('You\'ve just set a wedding date with {' .. p .. '}.', cid)
  84.                         talkState[talkUser] = 0
  85.                     else
  86.                         local partnername = getPlayerNameByGUID(ownstatus)
  87.                         selfSay('{' .. p .. '} has already set a wedding date with {' .. partnername .. '}.', cid)
  88.                         talkState[talkUser] = 0
  89.                     end
  90.                 else
  91.                     local marryname = getPlayerNameByGUID(marrystatus)
  92.                     selfSay('{' .. marryname .. '} has set a wedding date with you. Do you want to {proceed} or {cancel} the wedding?', cid)
  93.                     talkState[talkUser] = 4
  94.                 end
  95.             else
  96.                 local pname = getPlayerNameByGUID(pmarriage)
  97.                 selfSay('Sorry, but {' .. p .. '} is already married to {' .. pname .. '}.', cid)
  98.                 talkState[talkUser] = 0
  99.             end
  100.         end
  101.  
  102.     elseif talkState[talkUser] == 4 then
  103.         if msgcontains(msg, 'proceed') then
  104.             local fid = getPlayerGUID(cid)
  105.             local sid = getMarryStatus(fid)
  106.             local marryname = getPlayerNameByGUID(sid)
  107.             local pid = getPlayerByNameWildcard(marryname)
  108.                 local tmf = getCreaturePosition(cid)
  109.                 local   tms = getCreaturePosition(pid)
  110.                 local text = {'I love you!','My love!','Baby dear!'}
  111.                 local chance1 = math.random(1,table.getn(text))
  112.                 local chance2 = math.random(1,table.getn(text))
  113.                 local dateFormat = "%A %d"..getMonthDayEnding(os.date("%d")).." %B %Y"
  114.                                 local ring = doPlayerAddItem(cid,10502,1)
  115.                                 local ring2 = doPlayerAddItem(pid,10502,1)
  116.  
  117.             if isOnline(fid) == TRUE and isOnline(sid) == TRUE then
  118.             if getDistanceBetween(tmf, tms) <= 3 then
  119.                     setPlayerStorageValue(cid,3066,2)
  120.                     setPlayerStorageValue(pid,3066,2)
  121.                     doCancelMarryStatus(fid)
  122.                     doCancelMarryStatus(sid)
  123.                     setPlayerPartner(cid,sid)
  124.                     setPlayerPartner(pid,fid)
  125.                                         doPlayerAddOutfitId(cid,34,0)
  126.                                         doPlayerAddOutfitId(pid,34,0)
  127.                                         doSetItemSpecialDescription(ring, "" .. getCreatureName(cid) .. " & " .. getCreatureName(pid) .. " forever - married on " ..os.date(dateFormat).. ".")
  128.                                         doSetItemSpecialDescription(ring2, "" .. getCreatureName(cid) .. " & " .. getCreatureName(pid) .. " forever - married on " ..os.date(dateFormat).. ".")
  129.                     doCreatureSay(cid, text[chance1], TALKTYPE_ORANGE_1)
  130.                     doCreatureSay(pid, text[chance2], TALKTYPE_ORANGE_1)
  131.                     doSendMagicEffect(tmf, 35)
  132.                     doSendMagicEffect(tms, 35)
  133.                     selfSay('Congratulations! Now you may kiss your partner! Everytime you wanna make this effect, just say {love}. You must be close to your partner.', cid)
  134.                     talkState[talkUser] = 0
  135.  
  136.                 else
  137.                     selfSay('Your partner must be close to you so you can marry!', cid)
  138.                     talkState[talkUser] = 0
  139.                 end
  140.             else
  141.                 selfSay('You and your new partner must be online at the same time.', cid)
  142.                 talkState[talkUser] = 0
  143.             end
  144.            
  145.  
  146.  
  147.         elseif msgcontains(msg, 'cancel') then
  148.             local fid = getPlayerGUID(cid)
  149.             local sid = getMarryStatus(fid)
  150.             local marryname = getPlayerNameByGUID(sid)
  151.             local pid = getPlayerByNameWildcard(marryname)
  152.             if isOnline(sid) == TRUE then
  153.                 setPlayerStorageValue(pid,3066,-1)
  154.             end
  155.             doCancelMarryStatus(sid)
  156.             selfSay('You just canceled your wedding date with {' .. marryname .. '}.', cid)
  157.             talkState[talkUser] = 0
  158.         end
  159.  
  160.     elseif talkState[talkUser] == 5 then
  161.         if msgcontains(msg, 'cancel') or msgcontains(msg, 'yes') then
  162.             local fid = getPlayerGUID(cid)
  163.             setPlayerStorageValue(cid,3066,-1)
  164.             doCancelMarryStatus(fid)
  165.             talkState[talkUser] = 0
  166.         end
  167.  
  168.     elseif talkState[talkUser] == 6 then
  169.         if msgcontains(msg, 'yes') then
  170.             local fid = getPlayerGUID(cid)
  171.             local sid = getPlayerPartner(cid)
  172.             local marryname = getPlayerNameByGUID(sid)
  173.             local pid = getPlayerByNameWildcard(marryname)
  174.             if (isOnline(fid) == TRUE and isOnline(sid) == TRUE) then
  175.                 setPlayerStorageValue(cid,3066,-1)
  176.                 setPlayerStorageValue(pid,3066,-1)
  177.                 setPlayerPartner(cid,0)
  178.                 setPlayerPartner(pid,0)
  179.                                 doPlayerAddOutfitId(cid,34,-1)
  180.                                 doPlayerAddOutfitId(pid,34,-1)
  181.                 selfSay('You\'ve just divorced of your old partner.', cid)
  182.                 talkState[talkUser] = 0
  183.             else
  184.                 selfSay('You and your new partner must be online at the same time.', cid)
  185.                 talkState[talkUser] = 0
  186.             end
  187.         end
  188.  
  189.     end
  190.  
  191.  
  192.     return TRUE
  193. end
  194.  
  195. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  196. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement