Postado Fevereiro 13, 2021 4 anos Solução @knepperzik Então o jeito que eu tinha feito é que toda fez que o player logar iria resetar as storages da task, então ele teria que finalizar a task sempre online. Eu fiz uma alteração no script tente fazer desta forma pra ver se funciona, toda vez que o servidor iniciar ele vai zerar todas as storages dos players que começaram a task, segue o script: Primeiro de tudo, vá no arquivo data/creaturescripts/scripts e abra o login.lua e remova as linhas que você adicionou usando o script anterior: Mostrar conteúdo oculto if getPlayerStorageValue(cid, task_start) > 0 then ClearAllStoragePlayer(cid) setPlayerStorageValue(cid, task_start, -1) end if getPlayerStorageValue(cid, task_finish) > 0 then setPlayerStorageValue(cid, task_finish , -1) end if getPlayerStorageValue(cid, task_start_opcao1) > 0 then setPlayerStorageValue(cid, task_start_opcao1, -1) end if getPlayerStorageValue(cid, task_start_opcao2) > 0 then setPlayerStorageValue(cid, task_start_opcao2, -1) end Vá em data/globalevents/scripts e crie um arquivo chamado dailyReset.lua e cole isto dentro: Mostrar conteúdo oculto function onStartup() local players = db.getResult("SELECT `id` FROM `players`;") findPlayersID(players) end function findPlayersID(players) if(players:getID() ~= -1) then repeat local playerID = players:getDataInt("id") findPlayersStorageKey(playerID) until not(result:next()) players:free() end end function findPlayersStorageKey(playerID) local playerStorage = db.getResult("SELECT `key` FROM `player_storage` WHERE player_id = "..playerID..";") if(playerStorage:getID() ~= -1) then repeat querysResetValueStoragePlayer(playerID) until not(result:next()) end end function querysResetValueStoragePlayer(playerID) local storageValueReset = -1 db.executeQuery("UPDATE `player_storage` SET `value` = "..storageValueReset.." WHERE `player_id` = ".. playerID .." AND `key` = "..task_start..";") db.executeQuery("UPDATE `player_storage` SET `value` = "..storageValueReset.." WHERE `player_id` = ".. playerID .." AND `key` = "..task_start..";") db.executeQuery("UPDATE `player_storage` SET `value` = "..storageValueReset.." WHERE `player_id` = ".. playerID .." AND `key` = "..task_start_opcao1..";") db.executeQuery("UPDATE `player_storage` SET `value` = "..storageValueReset.." WHERE `player_id` = ".. playerID .." AND `key` = "..task_start_opcao2..";") end Registre o script no globalevents.xml adicionando esta linha nele : Mostrar conteúdo oculto <globalevent name="dailyReset" type="startup" event="script" value="dailyReset.lua"/> Agora, vá em data/npc/scripts e procuro pelo script do NPC daily que se chama tasker (caso tenha mudado o nome então procuro pelo nome que voce alterou) e troque por esse script : Mostrar conteúdo oculto 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 local opcao1 = nil local opcao2 = nil local pokemonNameOpcao1 = '' local pokemonNameOpcao2 = '' local opcaoSelecionada = nil function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end if msgcontains(msg, 'daily') then if (getPlayerStorageValue(cid, task_start) >= 1) then return selfSay("Voce ja escolheu uma task hoje, termine-a primeiro.") end if (getPlayerStorageValue(cid, task_storage_time) > os.time()) then return selfSay("Voce ja terminou a sua task hoje, volte amanha.") end setPlayerStorageValue(cid, task_storage_time, -1) selfSay("Diga 'monsters' para saber quais monsters estao disponiveis hoje.") talkState[cid] = 0 end if (getPlayerStorageValue(cid, task_storage_time) < os.time()) then if msgcontains(msg, 'monsters') and talkState[cid] == 0 and pokemonNameOpcao1 == '' and pokemonNameOpcao2 == '' then opcao1 = PokemonOpcao1() opcao2 = PokemonOpcao2() pokemonNameOpcao1 = opcao1.PokemonName pokemonNameOpcao2 = opcao2.PokemonName selfSay("Opcao 1: Voce tera que derrotar "..opcao1.Count.." "..opcao1.PokemonName.."(s).") selfSay("Opcao 2: Voce tera que derrotar "..opcao2.Count.." "..opcao2.PokemonName.."(s).") talkState[cid] = 1 end if msgcontains(msg, 'monsters') and talkState[cid] == 0 and pokemonNameOpcao1 ~= '' and pokemonNameOpcao2 ~= '' then selfSay("Essas sao as opcoes de monsters para voce hoje.") selfSay("Opcao 1: Voce tera que derrotar "..opcao1.Count.." "..opcao1.PokemonName.."(s).") selfSay("Opcao 2: Voce tera que derrotar "..opcao2.Count.." "..opcao2.PokemonName.."(s).") talkState[cid] = 1 end end if msgcontains(string.lower(msg), string.lower(pokemonNameOpcao1)) and talkState[cid] == 1 then opcaoSelecionada = opcao1 GetOpcaoSelecionada(cid, msg, opcao1) StorageStartTaskOpcao1 = opcao1 setPlayerStorageValue(cid, task_start_opcao1, task_info_table_opcao1) talkState[cid] = 0 end if msgcontains(string.lower(msg), string.lower(pokemonNameOpcao2)) and talkState[cid] == 1 then opcaoSelecionada = opcao2 GetOpcaoSelecionada(cid, msg, opcao2) setPlayerStorageValue(cid, task_start_opcao2, task_info_table_opcao2) talkState[cid] = 0 end if (getPlayerStorageValue(cid, task_finish) >= 1) then if (msgcontains(msg, 'reward')) then if (opcaoSelecionada ~= nil) then selfSay("Parabens voce acabou a task diaria de hoje. Voce ganhou "..opcaoSelecionada.Experience.." de experiencia e "..opcaoSelecionada.Reward..".") doPlayerAddExperience(cid, opcaoSelecionada.Experience) doPlayerAddItem(cid, opcaoSelecionada.Reward) setPlayerStorageValue(cid, task_storage_time, os.time() + (60 * 60 * task_time)) setPlayerStorageValue(cid, task_start, -1) setPlayerStorageValue(cid, task_finish, -1) pokemonNameOpcao1 = '' pokemonNameOpcao2 = '' opcaoSelecionada = nil talkState[cid] = 0 end end end return TRUE end function GetOpcaoSelecionada(cid, msg, opcao) if (string.lower(msg) == string.lower(opcao.PokemonName)) then ClearAllStoragePlayer(cid) setPlayerStorageValue(cid, task_start, 1) selfSay("Voce comecou a task, voce precisa matar ["..opcao.Count.." "..opcao.PokemonName.."]. Boa Sorte!") npcHandler:releaseFocus(cid) talkState[cid] = 0 end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
Postado Fevereiro 27, 2021 4 anos Autor Em 13/02/2021 em 17:37, MatteusDeli disse: @knepperzik Então o jeito que eu tinha feito é que toda fez que o player logar iria resetar as storages da task, então ele teria que finalizar a task sempre online. Eu fiz uma alteração no script tente fazer desta forma pra ver se funciona, toda vez que o servidor iniciar ele vai zerar todas as storages dos players que começaram a task, segue o script: Primeiro de tudo, vá no arquivo data/creaturescripts/scripts e abra o login.lua e remova as linhas que você adicionou usando o script anterior: Mostrar conteúdo oculto Mostrar conteúdo oculto if getPlayerStorageValue(cid, task_start) > 0 then ClearAllStoragePlayer(cid) setPlayerStorageValue(cid, task_start, -1) end if getPlayerStorageValue(cid, task_finish) > 0 then setPlayerStorageValue(cid, task_finish , -1) end if getPlayerStorageValue(cid, task_start_opcao1) > 0 then setPlayerStorageValue(cid, task_start_opcao1, -1) end if getPlayerStorageValue(cid, task_start_opcao2) > 0 then setPlayerStorageValue(cid, task_start_opcao2, -1) end Vá em data/globalevents/scripts e crie um arquivo chamado dailyReset.lua e cole isto dentro: Mostrar conteúdo oculto Mostrar conteúdo oculto function onStartup() local players = db.getResult("SELECT `id` FROM `players`;") findPlayersID(players) end function findPlayersID(players) if(players:getID() ~= -1) then repeat local playerID = players:getDataInt("id") findPlayersStorageKey(playerID) until not(result:next()) players:free() end end function findPlayersStorageKey(playerID) local playerStorage = db.getResult("SELECT `key` FROM `player_storage` WHERE player_id = "..playerID..";") if(playerStorage:getID() ~= -1) then repeat querysResetValueStoragePlayer(playerID) until not(result:next()) end end function querysResetValueStoragePlayer(playerID) local storageValueReset = -1 db.executeQuery("UPDATE `player_storage` SET `value` = "..storageValueReset.." WHERE `player_id` = ".. playerID .." AND `key` = "..task_start..";") db.executeQuery("UPDATE `player_storage` SET `value` = "..storageValueReset.." WHERE `player_id` = ".. playerID .." AND `key` = "..task_start..";") db.executeQuery("UPDATE `player_storage` SET `value` = "..storageValueReset.." WHERE `player_id` = ".. playerID .." AND `key` = "..task_start_opcao1..";") db.executeQuery("UPDATE `player_storage` SET `value` = "..storageValueReset.." WHERE `player_id` = ".. playerID .." AND `key` = "..task_start_opcao2..";") end Registre o script no globalevents.xml adicionando esta linha nele : Mostrar conteúdo oculto Mostrar conteúdo oculto <globalevent name="dailyReset" type="startup" event="script" value="dailyReset.lua"/> Agora, vá em data/npc/scripts e procuro pelo script do NPC daily que se chama tasker (caso tenha mudado o nome então procuro pelo nome que voce alterou) e troque por esse script : Mostrar conteúdo oculto Mostrar conteúdo oculto 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 local opcao1 = nil local opcao2 = nil local pokemonNameOpcao1 = '' local pokemonNameOpcao2 = '' local opcaoSelecionada = nil function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end if msgcontains(msg, 'daily') then if (getPlayerStorageValue(cid, task_start) >= 1) then return selfSay("Voce ja escolheu uma task hoje, termine-a primeiro.") end if (getPlayerStorageValue(cid, task_storage_time) > os.time()) then return selfSay("Voce ja terminou a sua task hoje, volte amanha.") end setPlayerStorageValue(cid, task_storage_time, -1) selfSay("Diga 'monsters' para saber quais monsters estao disponiveis hoje.") talkState[cid] = 0 end if (getPlayerStorageValue(cid, task_storage_time) < os.time()) then if msgcontains(msg, 'monsters') and talkState[cid] == 0 and pokemonNameOpcao1 == '' and pokemonNameOpcao2 == '' then opcao1 = PokemonOpcao1() opcao2 = PokemonOpcao2() pokemonNameOpcao1 = opcao1.PokemonName pokemonNameOpcao2 = opcao2.PokemonName selfSay("Opcao 1: Voce tera que derrotar "..opcao1.Count.." "..opcao1.PokemonName.."(s).") selfSay("Opcao 2: Voce tera que derrotar "..opcao2.Count.." "..opcao2.PokemonName.."(s).") talkState[cid] = 1 end if msgcontains(msg, 'monsters') and talkState[cid] == 0 and pokemonNameOpcao1 ~= '' and pokemonNameOpcao2 ~= '' then selfSay("Essas sao as opcoes de monsters para voce hoje.") selfSay("Opcao 1: Voce tera que derrotar "..opcao1.Count.." "..opcao1.PokemonName.."(s).") selfSay("Opcao 2: Voce tera que derrotar "..opcao2.Count.." "..opcao2.PokemonName.."(s).") talkState[cid] = 1 end end if msgcontains(string.lower(msg), string.lower(pokemonNameOpcao1)) and talkState[cid] == 1 then opcaoSelecionada = opcao1 GetOpcaoSelecionada(cid, msg, opcao1) StorageStartTaskOpcao1 = opcao1 setPlayerStorageValue(cid, task_start_opcao1, task_info_table_opcao1) talkState[cid] = 0 end if msgcontains(string.lower(msg), string.lower(pokemonNameOpcao2)) and talkState[cid] == 1 then opcaoSelecionada = opcao2 GetOpcaoSelecionada(cid, msg, opcao2) setPlayerStorageValue(cid, task_start_opcao2, task_info_table_opcao2) talkState[cid] = 0 end if (getPlayerStorageValue(cid, task_finish) >= 1) then if (msgcontains(msg, 'reward')) then if (opcaoSelecionada ~= nil) then selfSay("Parabens voce acabou a task diaria de hoje. Voce ganhou "..opcaoSelecionada.Experience.." de experiencia e "..opcaoSelecionada.Reward..".") doPlayerAddExperience(cid, opcaoSelecionada.Experience) doPlayerAddItem(cid, opcaoSelecionada.Reward) setPlayerStorageValue(cid, task_storage_time, os.time() + (60 * 60 * task_time)) setPlayerStorageValue(cid, task_start, -1) setPlayerStorageValue(cid, task_finish, -1) pokemonNameOpcao1 = '' pokemonNameOpcao2 = '' opcaoSelecionada = nil talkState[cid] = 0 end end end return TRUE end function GetOpcaoSelecionada(cid, msg, opcao) if (string.lower(msg) == string.lower(opcao.PokemonName)) then ClearAllStoragePlayer(cid) setPlayerStorageValue(cid, task_start, 1) selfSay("Voce comecou a task, voce precisa matar ["..opcao.Count.." "..opcao.PokemonName.."]. Boa Sorte!") npcHandler:releaseFocus(cid) talkState[cid] = 0 end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Voltou a dar o mesmo erro Parece que não estava salvando a storage
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.