212121 14 Postado Fevereiro 2, 2013 Share Postado Fevereiro 2, 2013 (editado) Ola, Eu estava usando meu npc de Egg System(SkyDangerous) normalmente, mas agora mexi em alguma coisa que esta interferindo na checagem de tal item... Então gostaria que algúem me desse uma ajudinha no que está faltando pois não sou muito experiente em script. • Eplicação da função do npc: Ao falar "hi" o npc diz que ele pode cuidar dos eggs, ao falar "care" ele pede um preço + o egg para ser cuidado, ao falar "yes" remove o price + o egg da bag, e assim começa uma contagem de tempo, ai você pode checar o tempo do egg "check", ou pega-lo devolta "back". Quando passar o tempo, você diz "back" e recebe um novo egg(chocado). • Problema: Quando eu digo "yes" o npc retira do player o preço(5000 dollar) e também o egg(id: 12319) e começa a contagem normalmente, massss ele não está checando se possúi o egg, removendo mesmo assim os 2 itens pedidos. Ai da pra falar "yes" sem ter o egg, só o dinheiro. • Possível solução: Fazer uma função if PlayerRemoveItem(cid, 12319,1) fazer o npc exigir o egg falando "You don't have an egg" junto com o dinheiro cobrado. • Script (modificado): local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() end function onCreatureSayCallback(cid, type, msg) local config = { price = 50000, delay = 3 * 1, control = {10555, 10556}, eggn = 12319 } if not npcHandler:isFocused(cid) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, "care") then local p = (config.price % 1000 == 0 and (config.price / 1000) or config.price) if getPlayerStorageValue(cid, config.control) > os.time() then selfSay("Sorry, but I am already caring one of your eggs.", cid) else selfSay("Do you want me to take care of your egg for ".. p .." ".. (p == config.price and "" or "k") .."?", cid) talkState[talkUser] = 1 end elseif msgcontains(msg, "check") then if getPlayerStorageValue(cid, config.control[2]) == 1 then selfSay("Hello, do you came to pick up your egg?", cid) talkState[talkUser] = 2 else selfSay("Sorry, but I am not caring eggs from you.", cid) end elseif msgcontains(msg, "back") then local t = getPlayerStorageValue(cid, config.control[1]) if getPlayerStorageValue(cid, config.control[2]) == -1 then selfSay("Sorry, but I am not caring eggs from you.", cid) else if t < os.time() then doPlayerAddItem(cid, 12310, 1) selfSay("Yay, your egg has started to hatch, take it.", cid) setPlayerStorageValue(cid, config.control[1], -1) setPlayerStorageValue(cid, config.control[2], -1) else 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) end end end if talkState[talkUser] == 1 then if msgcontains(msg, "yes") then if getPlayerStorageValue(cid, config.control[2]) == -1 then if doPlayerRemoveMoney(cid, config.price) then doPlayerRemoveItem(cid, 12319, 1) setPlayerStorageValue(cid, config.control[2], 1) setPlayerStorageValue(cid, config.control[1], os.time()+config.delay) selfSay("Okay! Check back soon.",cid) else selfSay("Sorry, you don't have enough money. You need more ".. (config.price - getPlayerMoney(cid)) .." dollars.", cid) end else selfSay("I am already taking care of a egg for you.", cid) end elseif msgcontains(msg, "no") then selfSay("Too pricey for you, heh?", cid) end elseif talkState[talkUser] == 2 then local x = getPlayerStorageValue(cid, config.control) local t = getPlayerStorageValue(cid, config.control[1]) if msgcontains(msg, "yes") then if x > os.time() then doPlayerAddItem(cid, 12310, 1) doItemSetAttribute(item, "description", "A hatched egg.") selfSay("Take it!", cid) setPlayerStorageValue(cid, control[2], -1) setPlayerStorageValue(cid, control[1], -1) else selfSay("Sorry, but your egg need care for more ".. (math.floor((t - os.time()) / 3) > 0 and "".. math.floor((t - os.time()) / 3) .." minutes and" or "") .." ".. (t - os.time()) % 3 .." seconds.", cid) end end end return true end 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}.") npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSayCallback) npcHandler:addModule(FocusModule:new()) Roxo: local do problema (eu acho). Preciso de ajuda, sempre resolvi tudo aqui pelo Xtibia, tem muita gente legal aqui, obrigado. Editado Fevereiro 2, 2013 por 0BoM Link para o comentário Compartilhar em outros sites More sharing options...
StyloMaldoso 330 Postado Fevereiro 2, 2013 Share Postado Fevereiro 2, 2013 (editado) tenta assim local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() end function onCreatureSayCallback(cid, type, msg) local config = { price = 50000, delay = 3 * 1, control = {10555, 10556}, eggn = 12319 } if not npcHandler:isFocused(cid) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, "care") then local p = (config.price % 1000 == 0 and (config.price / 1000) or config.price) if getPlayerStorageValue(cid, config.control) > os.time() then selfSay("Sorry, but I am already caring one of your eggs.", cid) else selfSay("Do you want me to take care of your egg for ".. p .." ".. (p == config.price and "" or "k") .."?", cid) talkState[talkUser] = 1 end elseif msgcontains(msg, "check") then if getPlayerStorageValue(cid, config.control[2]) == 1 then selfSay("Hello, do you came to pick up your egg?", cid) talkState[talkUser] = 2 else selfSay("Sorry, but I am not caring eggs from you.", cid) end elseif msgcontains(msg, "back") then local t = getPlayerStorageValue(cid, config.control[1]) if getPlayerStorageValue(cid, config.control[2]) == -1 then selfSay("Sorry, but I am not caring eggs from you.", cid) else if t < os.time() then doPlayerAddItem(cid, 12310, 1) selfSay("Yay, your egg has started to hatch, take it.", cid) setPlayerStorageValue(cid, config.control[1], -1) setPlayerStorageValue(cid, config.control[2], -1) else 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) end end end if talkState[talkUser] == 1 then if msgcontains(msg, "yes") then if getPlayerStorageValue(cid, config.control[2]) == -1 then if getPlayerItemCount(cid, 12319) < 1 then SelfSay("desculpe mais você não tem o egg!", cid) talkState[talkUser] = 0 return true end if doPlayerRemoveMoney(cid, config.price) then doPlayerRemoveItem(cid, 12319, 1) setPlayerStorageValue(cid, config.control[2], 1) setPlayerStorageValue(cid, config.control[1], os.time()+config.delay) selfSay("Okay! Check back soon.",cid) else selfSay("Sorry, you don't have enough money. You need more ".. (config.price - getPlayerMoney(cid)) .." dollars.", cid) end else selfSay("I am already taking care of a egg for you.", cid) end elseif msgcontains(msg, "no") then selfSay("Too pricey for you, heh?", cid) end elseif talkState[talkUser] == 2 then local x = getPlayerStorageValue(cid, config.control) local t = getPlayerStorageValue(cid, config.control[1]) if msgcontains(msg, "yes") then if x > os.time() then doPlayerAddItem(cid, 12310, 1) doItemSetAttribute(item, "description", "A hatched egg.") selfSay("Take it!", cid) setPlayerStorageValue(cid, control[2], -1) setPlayerStorageValue(cid, control[1], -1) else selfSay("Sorry, but your egg need care for more ".. (math.floor((t - os.time()) / 3) > 0 and "".. math.floor((t - os.time()) / 3) .." minutes and" or "") .." ".. (t - os.time()) % 3 .." seconds.", cid) end end end return true end 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}.") npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSayCallback) npcHandler:addModule(FocusModule:new()) Editado Fevereiro 2, 2013 por StyloMaldoso Link para o comentário Compartilhar em outros sites More sharing options...
Slicer 1070 Postado Fevereiro 2, 2013 Share Postado Fevereiro 2, 2013 local incorreto, movido e amigo, use.. [ spoiler] seu script aki [ /spoiler] para postar scripts desse tamanho! Link para o comentário Compartilhar em outros sites More sharing options...
212121 14 Postado Fevereiro 2, 2013 Autor Share Postado Fevereiro 2, 2013 (editado) @StyloMaldoso Obrigado pela atenção, mas ta dando um errinho na hora q falo "yes": [02/02/2013 12:57:20] data/npc/scripts/eggsystem.lua:onCreatureSay [02/02/2013 12:57:20] Description: [02/02/2013 12:57:20] data/npc/scripts/eggsystem.lua:61: attempt to call global 'SelfSay' (a nil value) [02/02/2013 12:57:20] stack traceback: [02/02/2013 12:57:20] data/npc/scripts/eggsystem.lua:61: in function 'callback' [02/02/2013 12:57:20] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay' [02/02/2013 12:57:20] data/npc/scripts/eggsystem.lua:9: in function <data/npc/scripts/eggsystem.lua:9> @Slicer Foi movido por ser um script de servidor derivado? AEUEAhaeUHAEuaE Desculpe pela falta do spoiler, eu tinha colocado depois tirei achando q nao tava grande. Editado Fevereiro 2, 2013 por 0BoM Link para o comentário Compartilhar em outros sites More sharing options...
Slicer 1070 Postado Fevereiro 2, 2013 Share Postado Fevereiro 2, 2013 sim qlqr duvida relacionada a um servidor derivado deve ser postado aki... e va na linha 61 e troque isso.. SelfSay por isso.. selfSay Link para o comentário Compartilhar em outros sites More sharing options...
212121 14 Postado Fevereiro 2, 2013 Autor Share Postado Fevereiro 2, 2013 (editado) @Slicer e StyloMaldoso Muito obrigado aos dois, sei que sempre posso contar com xtibia pq tem muita gente boa aqui. Agora nao estou conseguiu só uma coisinha: selfSay("Sorry, but your egg need care for more ".. (math.floor((t - os.time()) / 3) > 0 and "".. math.floor((t - os.time()) / 3) .." minutes and" or "") .." ".. (t - os.time()) % 3 .." seconds.", cid) Eu gostaria de adicionar a opção hours(horas) na contagem do math.floor, que no caso vou deixar o tempo do egg por 24hrs = 1440 * 60. Editado Fevereiro 2, 2013 por 0BoM Link para o comentário Compartilhar em outros sites More sharing options...
161996 3 Postado Fevereiro 2, 2013 Share Postado Fevereiro 2, 2013 Gostei do seu script, bem criativo posso usar ele num server? ._. Enquanto a essa opção de hours acho q é facil fazer mas eu nao iria conseguir... talvez o Slicer resolva num instante. Link para o comentário Compartilhar em outros sites More sharing options...
Slicer 1070 Postado Fevereiro 2, 2013 Share Postado Fevereiro 2, 2013 nao gosto de mexer com 'tempo' mas.. pq n usa.. string.timediff(diff) ? tpw.. selfSay("I will be caring your egg for more ".. string.timediff(t - os.time()), cid) nao garanto q va da certo ^^ Link para o comentário Compartilhar em outros sites More sharing options...
212121 14 Postado Fevereiro 2, 2013 Autor Share Postado Fevereiro 2, 2013 (editado) Nossa eu coloquei errado a parte para mudar ... a correta seria : selfSay("Sorry, but your egg need care for more ".. (math.floor((t - os.time()) / 3) > 0 and "".. math.floor((t - os.time()) / 3) .." minutes and" or "") .." ".. (t - os.time()) % 3 .." seconds.", cid) Eu gostaria de adicionar a opção hours(horas) na contagem do math.floor, que no caso vou deixar o tempo do egg por 24hrs = 1440 * 60. Alguem pode ajudar? por favor ! Editado Fevereiro 2, 2013 por 0BoM Link para o comentário Compartilhar em outros sites More sharing options...
Slicer 1070 Postado Fevereiro 2, 2013 Share Postado Fevereiro 2, 2013 eh a ms coisa amigo u,U selfSay("Sorry, but your egg need care for more ".. string.timediff(t - os.time()), cid) Link para o comentário Compartilhar em outros sites More sharing options...
212121 14 Postado Fevereiro 2, 2013 Autor Share Postado Fevereiro 2, 2013 @Slicer Essa função de string time nem ta funcionando, mas vlw pela atenção @All Alguém pode me ajudar? >.< Link para o comentário Compartilhar em outros sites More sharing options...
Slicer 1070 Postado Fevereiro 2, 2013 Share Postado Fevereiro 2, 2013 (editado) oq esta acontecendo amigo? nao adianta soh dizer q n ta funconando.. ate pq eu uso ela aki e funciona normalmente... oia o test aki.. string.timediff = function (diff) local format = { {"week", diff / 60 / 60 / 24 / 7}, {"day", diff / 60 / 60 / 24 % 7}, {"hour", diff / 60 / 60 % 24}, {"minute", diff / 60 % 60}, {"second", diff % 60} } local t = {} for k, v in ipairs(format) do local d, tmp = math.floor(v[2]), "" if(d > 0) then tmp = (k < table.maxn(format) and (table.maxn(t) > 0 and ", " or "") or " and ") .. d .. " " .. v[1] .. (d ~= 1 and "s" or "") table.insert(t, tmp) end end return table.concat(t) end local time = os.time() + 24 * 60 * 60 + 30 print(string.timediff(time - os.time())) retornou 1 day and 30 seconds Editado Fevereiro 2, 2013 por Slicer Link para o comentário Compartilhar em outros sites More sharing options...
212121 14 Postado Fevereiro 3, 2013 Autor Share Postado Fevereiro 3, 2013 Tipo ele simplesmente buga o server quando coloquei o timediff, acho q coloquei errado na verdade .... nao tenho idéia de onde colocar isso. Link para o comentário Compartilhar em outros sites More sharing options...
Stigal 584 Postado Fevereiro 12, 2013 Share Postado Fevereiro 12, 2013 Tópico movido para a seção de dúvidas e pedidos resolvidos. Link para o comentário Compartilhar em outros sites More sharing options...
Stigal 584 Postado Abril 21, 2018 Share Postado Abril 21, 2018 A questão neste tópico de suporte foi encerrada por falta de respostas. Este tópico está fechado e foi movido para Suporte - Tópicos Sem Resposta. + Caso a dúvida não tenha sido resolvida você poderá criar outro tópico solicitando ajuda. * Lembre-se que é permitido dar UP no tópico a cada 24 horas para assim o destacar e manter movimentado. Link para o comentário Compartilhar em outros sites More sharing options...
Posts Recomendados