Advertisement
dalvorsn

incomplete npc

Feb 24th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1.  
  2. --[[
  3.     lua_register(m_luaState, "selfFocus", NpcScript::luaActionFocus);
  4.     lua_register(m_luaState, "selfSay", NpcScript::luaActionSay);
  5.     lua_register(m_luaState, "selfFollow", NpcScript::luaActionFollow);
  6.  
  7.     lua_register(m_luaState, "getNpcId", NpcScript::luaGetNpcId);
  8.     lua_register(m_luaState, "getNpcParameter", NpcScript::luaGetNpcParameter);
  9.  
  10.     lua_register(m_luaState, "getNpcState", NpcScript::luaGetNpcState);
  11.     lua_register(m_luaState, "setNpcState", NpcScript::luaSetNpcState);
  12.  
  13.     lua_register(m_luaState, "openShopWindow", NpcScript::luaOpenShopWindow);
  14.     lua_register(m_luaState, "closeShopWindow", NpcScript::luaCloseShopWindow);
  15.     lua_register(m_luaState, "getShopOwner", NpcScript::luaGetShopOwner);
  16. --]]
  17. -- general config
  18. local required_money = 80000
  19. local time_to_make = 24 * 60 * 600
  20.  
  21. -- storages
  22. local storage_state = 15000
  23. local storage_time = 15000
  24.  
  25. -- config of items' id
  26. local sword_broked_id = 2350
  27. local sword_reward_id = 10513
  28. local items_task = {
  29.     [2225] = 30, -- pieces of iron, 30
  30.     [2134] = 30, -- silver broochs, 10
  31. }
  32.    
  33. local function setState(state, cid)
  34.     if not isCreature(cid) then return false end
  35.    
  36.     doCreatureSetStorage(cid, storage_state, state)
  37. end
  38. local function getState(cid)
  39.     if not isCreature(cid) then return false end
  40.      
  41.     return getCreatureStorage(cid, storage_state)
  42. end
  43.    
  44. function onCreatureSay(cid, type, msg)
  45.     local state = tonumber(getState(cid))
  46.     local msg = msg:lower()
  47.     if isInArray({"hi", "hello", "oi", "olá"}, msg) then
  48.         selfFocus(cid)
  49.         if state < 3 then
  50.             selfSay(string.format("Ola %s, eu sou morador daqui, gosto deste lugar, me sinto protegido.", getCreatureName(cid)))
  51.             setState(1, cid)
  52.         elseif state == 5 then
  53.         else
  54.             selfSay("Trouxe o que lhe pedi?")
  55.             selfFocus(cid)
  56.             setState(4, cid)
  57.         end
  58.     end
  59.    
  60.     if isInArray({"espada", "sword"}, msg)  and state == 1 then
  61.         if getPlayerItemCount(cid, sword_broked_id) > 0 then
  62.             selfSay("Onde você encontrou esta espada quebrada? Com ela posso fazer uma poderosa espada, mas você vai precisar trazer 30 pieces of iron, 30 silver broochs, 10 golden mugs, 1 demonic finger e 80k. Aceita?")
  63.             setState(2, cid)
  64.         else
  65.             selfSay("Voce nao tem a espada que procuro")
  66.             setState(nil, cid)
  67.             selfFocus(getNpcId())
  68.         end
  69.     end
  70.    
  71.     if isInArray({"yes", "no", "sim", "nao"}, msg) then
  72.         if state == 2 and isInArray({"yes", "sim"}, msg) and doPlayerRemoveItem(cid, sword_broked_id, 1) then
  73.             selfSay("Otimo, me traga o que te pedi: 30 pieces of iron, 30 silver broochs, 10 golden mugs, 1 demonic finger e 80k.")
  74.             selfFocus(getNpcId())
  75.             setState(3, cid)
  76.         end
  77.        
  78.         if state == 4 and isInArray({"yes", "sim"}, msg) then
  79.             for itemid, count in pairs(items_task) do
  80.                 if not getPlayerItemCount(cid, itemid) >= count then
  81.                     selfSay(string.format("Voce não tem %d %s. Volte quando estiver com eles", count, itemid))
  82.                     selfFocus(getNpcId())
  83.                     setState(3, cid)
  84.                     return true
  85.                 end
  86.             end
  87.            
  88.             if not getPlayerMoney(cid) >= required_money then
  89.                 selfSay(string.format("Voce nao tem %d coins", required_money))
  90.                 selfFocus(getNpcId())
  91.                 selfState(3, cid)
  92.                 return true
  93.             end
  94.            
  95.             for itemid, count in pairs(items_task) do
  96.                 doPlayerRemoveItem(cid, itemid, count)
  97.             end
  98.             doPlayerRemoveMoney(cid, required_money)
  99.            
  100.             selfSay(
  101.             setState(5, cid)
  102.         end
  103.     end
  104.    
  105.    
  106.     return true
  107. end
  108.  
  109. function onCreatureDisappear(cid)
  110.     selfSay("How hude!")
  111.     selfFocus(getNpcId())
  112.     local state = getState(cid)
  113.     if state and state < 3 then
  114.         setState(nil, cid)
  115.     end
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement