Postado Abril 13, 2024 1 ano Autor 7 horas atrás, L3K0T disse: logout: local storage = 55512 -- Storage para controlar a spell local stages = {20, 30, 40} -- Tempos de duração para cada estágio em segundos local remainingTime = exhaustion.get(cid, storage) -- Obtém o tempo restante da spell local stage = 1 for i, stageDuration in ipairs(stages) do if remainingTime <= stageDuration then stage = i break end remainingTime = remainingTime - stageDuration end -- Salva o estágio e o tempo restante da spell no storage do jogador setPlayerStorageValue(cid, storage, stage) exhaustion.set(cid, storage, remainingTime) login local storage = 55512 -- Storage para controlar a spell local stages = {20, 30, 40} -- Tempos de duração para cada estágio em segundos local remainingTime = getPlayerStorageValue(cid, storage) or 0 -- Obtém o tempo restante da spell do storage local stage = 1 -- Determina o estágio com base no tempo restante for i, stageDuration in ipairs(stages) do if remainingTime <= stageDuration then stage = i break end remainingTime = remainingTime - stageDuration end -- Restaura o estágio da spell para o jogador setPlayerStorageValue(cid, storage, stage) exhaustion.set(cid, storage, remainingTime) spells function onCastSpell(cid, var) local storage = 55512 -- Storage para controlar a spell local stage = getPlayerStorageValue(cid, storage) or 0 -- Obtém o estágio atual da spell, se não houver nenhum, assume 0 local waittimes = {20, 30, 40} -- Tempos de espera para cada estágio em segundos if stage > 0 then doPlayerSendCancel(cid, "Você já está sob o efeito da spell.") return false end if not isCreature(cid) then return false end -- Definir o estágio inicial da spell setPlayerStorageValue(cid, storage, 1) stage = 1 -- Função para avançar para o próximo estágio após o término do atual local function advanceStage() if stage < #waittimes then stage = stage + 1 setPlayerStorageValue(cid, storage, stage) -- Programar o próximo avanço de estágio addEvent(advanceStage, waittimes[stage] * 1000) else -- Resetar a storage quando todos os estágios terminarem setPlayerStorageValue(cid, storage, -1) end end -- Iniciar o avanço de estágio addEvent(advanceStage, waittimes[stage] * 1000) -- Definir a exhaustion e aplicar os efeitos iniciais da spell local waittime = waittimes[1] -- Definir o tempo de exhaustion baseado no primeiro estágio exhaustion.set(cid, storage, waittime) OpenGate(cid, Select_Stages(getCreatureOutfit(cid).lookType), 1) -- Definir a storage de volta para -1 após o término do efeito da spell addEvent(function() setPlayerStorageValue(cid, storage, -1) end, waittime * 1000) -- Convertendo segundos para milissegundos return true end [13/04/2024 12:53:52] Chaves has logged in. [13/04/2024 12:53:52] [Error - CreatureScript Interface] [13/04/2024 12:53:52] data/creaturescripts/scripts/login.lua:onLogin [13/04/2024 12:53:52] Description: [13/04/2024 12:53:52] data/creaturescripts/scripts/login.lua:58: attempt to compare boolean with number [13/04/2024 12:53:52] stack traceback: [13/04/2024 12:53:52] data/creaturescripts/scripts/login.lua:58: in function <data/creaturescripts/scripts/login.lua:6> [13/04/2024 12:53:52] Chaves has logged out. coloquei as duas tags em login.lua ta certo? o char nem loga e aparece esse erro ai na distro. mano não teria um codigo pra colocar no login.lua que quando logasse tirasse essa storage de todos player? porque so vou usar essa spell pra esse buff de um personagem mesmo e se o cara deslogar e logar ele ja perderia o buff se fosse pra todos que logarem perder essa storage tava de boa porque so uma voc iria conseguir usar essa spell ele teria q esperar o tempo da spell voltar porque estou usando outra storage pra setar o tempo de usar a spell dnv, obrigado por dar uma atenção cara vc é fera! facilitaria bem mais com o codigo de resetar essa storage toda vez que relogasse, morresse, etc. porque a spell ta funcionando perfeitamente do jeito q eu quero aqui o problema é so a storage que fica travado nos stages quando reloga,morre,etc. Editado Abril 13, 2024 1 ano por Gabrielx17 (veja o histórico de edições)
Postado Abril 13, 2024 1 ano Não há necessidade de fazer isso no onLogin e onLogout, pois, caso o jogador relogue ou morra, esse addvent é capaz de identificar o CID do jogador se ele estiver online. Nesse caso, ele passará pela storage para resetá-la, utilizando, por exemplo, setPlayerStorageValue(cid, 4000, 0), que é responsável por esse reset. O método mais apropriado é utilizar getPlayerGUID() em vez disso. Dessa forma, se desejar que o addEvent seja acionado no jogador mesmo após ele ter deslogado ou morrido, será necessário recriar o objeto do jogador de forma convencional, porém utilizando getPlayerGUID(). Além disso, o GUID é um identificador permanente. Assim, ao invés de utilizar isPlayer(cid), é recomendado utilizar getPlayerGUID(). Desta maneira, caso o jogador realize login e logout, e o evento adicional esteja ocorrendo, será possível recriar o objeto do jogador utilizando o GUID e encontrar o jogador novamente. Sem usar esse método 'GUID', o addvent não consegue encontrar o jogador após a morte ou relogar. Isso poderia causar um crash no servidor. function onCastSpell(cid, var) local storage = 55512 -- Storage para controlar a spell local stages = { {time = 20, value = 1}, -- 20 segundos, storage = 1 {time = 30, value = 2}, -- 30 segundos adicionais, storage = 2 {time = 40, value = 3} -- 40 segundos adicionais, storage = 3 } -- Verificar se o jogador já usou a spell if getPlayerStorageValue(cid, storage) > 0 then doPlayerSendCancel(cid, "Você já está sob o efeito da spell.") return false end if not isCreature(cid) then return false end -- Função para alterar a storage e verificar se o jogador está online local function changeStorage(playerGUID, newValue, previousTime) local player = getPlayerByGUID(playerGUID) if player then setPlayerStorageValue(player, storage, newValue) if newValue == -1 then doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, "O efeito da spell terminou.") end end end -- Obter o GUID do jogador local playerGUID = getPlayerGUID(cid) -- Definir a storage inicial setPlayerStorageValue(cid, storage, stages[1].value) -- Agendar as mudanças de storage local accumulatedTime = 0 for i, stage in ipairs(stages) do accumulatedTime = accumulatedTime + stage.time addEvent(changeStorage, accumulatedTime * 1000, playerGUID, stage.value, accumulatedTime) end -- Agendar o reset da storage para o valor -1 após o último estágio accumulatedTime = accumulatedTime + stages[#stages].time addEvent(changeStorage, accumulatedTime * 1000, playerGUID, -1, accumulatedTime) return true end -- Função auxiliar para encontrar o jogador pelo GUID function getPlayerByGUID(guid) for _, pid in ipairs(getPlayersOnline()) do if getPlayerGUID(pid) == guid then return pid end end return nil -- Jogador não encontrado ou offline end Editado Abril 13, 2024 1 ano por Mateus Robeerto (veja o histórico de edições)
Postado Abril 13, 2024 1 ano Autor 20 minutos atrás, Mateus Robeerto disse: Não há necessidade de fazer isso no onLogin e onLogout, pois, caso o jogador relogue ou morra, esse addvent é capaz de identificar o CID do jogador se ele estiver online. Nesse caso, ele passará pela storage para resetá-la, utilizando, por exemplo, setPlayerStorageValue(cid, 4000, 0), que é responsável por esse reset. O método mais apropriado é utilizar getPlayerGUID() em vez disso. Dessa forma, se desejar que o addEvent seja acionado no jogador mesmo após ele ter deslogado ou morrido, será necessário recriar o objeto do jogador de forma convencional, porém utilizando getPlayerGUID(). Além disso, o GUID é um identificador permanente. Assim, ao invés de utilizar isPlayer(cid), é recomendado utilizar getPlayerGUID(). Desta maneira, caso o jogador realize login e logout, e o evento adicional esteja ocorrendo, será possível recriar o objeto do jogador utilizando o GUID e encontrar o jogador novamente. Sem usar esse método 'GUID', o addvent não consegue encontrar o jogador após a morte ou relogar. Isso poderia causar um crash no servidor. function onCastSpell(cid, var) local storage = 55512 -- Storage para controlar a spell local stages = { {time = 20, value = 1}, -- 20 segundos, storage = 1 {time = 30, value = 2}, -- 30 segundos adicionais, storage = 2 {time = 40, value = 3} -- 40 segundos adicionais, storage = 3 } -- Verificar se o jogador já usou a spell if getPlayerStorageValue(cid, storage) > 0 then doPlayerSendCancel(cid, "Você já está sob o efeito da spell.") return false end if not isCreature(cid) then return false end -- Função para alterar a storage e verificar se o jogador está online local function changeStorage(playerGUID, newValue, previousTime) local player = getPlayerByGUID(playerGUID) if player then setPlayerStorageValue(player, storage, newValue) if newValue == -1 then doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, "O efeito da spell terminou.") end end end -- Obter o GUID do jogador local playerGUID = getPlayerGUID(cid) -- Definir a storage inicial setPlayerStorageValue(cid, storage, stages[1].value) -- Agendar as mudanças de storage local accumulatedTime = 0 for i, stage in ipairs(stages) do accumulatedTime = accumulatedTime + stage.time addEvent(changeStorage, accumulatedTime * 1000, playerGUID, stage.value, accumulatedTime) end -- Agendar o reset da storage para o valor -1 após o último estágio accumulatedTime = accumulatedTime + stages[#stages].time addEvent(changeStorage, accumulatedTime * 1000, playerGUID, -1, accumulatedTime) return true end -- Função auxiliar para encontrar o jogador pelo GUID function getPlayerByGUID(guid) for _, pid in ipairs(getPlayersOnline()) do if getPlayerGUID(pid) == guid then return pid end end return nil -- Jogador não encontrado ou offline end funciona os stages de storage mas no caso como é uma spell de buff, o buff é cortado quando desloga ou morre, e o stages continuam, o certo seria os stages serem cortados juntos com os buffs da spell(voltar para -1 a storage caso morra ou deslogue). e no caso cortou o buff e os efeitos, não esta dando os atributos que são: ml,fist,sword,club e axe. vou deixar um codigo aqui pra vcs terem uma noção de como a spell estava funcionando certinho, porem tinha somente esse erro da storage não voltar a -1 quando morresse ou deslogasse, a storage ela continuava no ultimo stage tipo desloguei enquanto tava no stage3, o player continuava com a storage 55512=3. Spoiler function onCastSpell(cid, var) local storage = 55512 -- Storage para controlar a spell local stage = getPlayerStorageValue(cid, storage) or 0 -- Obtém o estágio atual da spell, se não houver nenhum, assume 0 local waittimes = {30, 30, 40, 50, 60} -- Tempos de espera para cada estágio em segundos local storage2 = 55513 local waittime3 = 310 if exhaustion.check(cid, storage2) then doPlayerSendCancel(cid, "Aguarde " .. exhaustion.get(cid, storage2) .. " segundos para usar a spell novamente.") return false end if not isCreature(cid) then return false end if stage > 0 then doPlayerSendCancel(cid, "Você já está sob o efeito da spell.") return false end -- Definir o estágio inicial da spell setPlayerStorageValue(cid, storage, 1) stage = 1 -- Função para avançar para o próximo estágio após o término do atual local function advanceStage() if stage < #waittimes then stage = stage + 1 setPlayerStorageValue(cid, storage, stage) -- Programar o próximo avanço de estágio addEvent(advanceStage, waittimes[stage] * 1000) else -- Resetar a storage quando todos os estágios terminarem setPlayerStorageValue(cid, storage, -1) end end -- Iniciar o avanço de estágio addEvent(advanceStage, waittimes[stage] * 1000) -- Definir a exhaustion e aplicar os efeitos iniciais da spell local waittime = waittimes[1] -- Definir o tempo de exhaustion baseado no primeiro estágio exhaustion.set(cid, storage2, waittime3) OpenGate(cid, Select_Stages(getCreatureOutfit(cid).lookType), 1) -- Definir a storage de volta para -1 após o término do efeito da spell addEvent(function() setPlayerStorageValue(cid, storage, -1) end, waittime * 1000) -- Convertendo segundos para milissegundos return true end ai no caso tem uma storage pra setar o tempo que o player vai poder usar a spell dnv e outra storage que ira setar os stages.
Postado Abril 14, 2024 1 ano function onCastSpell(cid, var) local waittime = 310 -- Tempo de exaustão local storage = 55512 -- Storage para controlar a spell local stages = { {time = 20, value = 1}, -- 20 segundos, storage = 1 {time = 30, value = 2}, -- 30 segundos adicionais, storage = 2 {time = 40, value = 3} -- 40 segundos adicionais, storage = 3 } if not isCreature(cid) then return false end -- Verificar se o jogador já usou a spell if getCreatureStorageValue(cid, storage) > 0 then doSendCancel(cid, "Você já está sob o efeito da spell.") return false end -- Definir a exaustão e a storage inicial doSetExhaustion(cid, storage, waittime) setCreatureStorageValue(cid, storage, 1) -- Função para alterar a storage e verificar se o jogador está online local function changeStorage(cidGUID, newValue) local creature = getCreatureByGUID(cidGUID) if creature and isCreature(creature) then setCreatureStorageValue(creature, storage, newValue) if newValue == -1 then doSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_BLUE, "O efeito da spell terminou.") else local creaturePos = getCreaturePosition(creature) for i = 1, 5 do doSendMagicEffect(creaturePos, CONST_ME_FIREWORK_RED) end doSendTextMessage(creature, MESSAGE_INFO_DESCR, "Você recebeu os atributos ML, FIST, SWORD, CLUB e AXE!") doAddCondition(creature, createConditionObject(CONDITION_ATTRIBUTES, 60 * 1000, { [CONDITION_PARAM_STAT_MAGICLEVEL] = 3, [CONDITION_PARAM_STAT_MAXHITPOINTS] = 3, [CONDITION_PARAM_STAT_MAXMANAPOINTS] = 3, [CONDITION_PARAM_STAT_SOULPOINTS] = 3, [CONDITION_PARAM_STAT_MAGICPOINTS] = 3 })) end end end -- Obter o GUID do jogador local cidGUID = getPlayerGUID(cid) -- Agendar as mudanças de storage local accumulatedTime = 0 for i, stage in ipairs(stages) do accumulatedTime = accumulatedTime + stage.time addEvent(changeStorage, accumulatedTime * 1000, cidGUID, stage.value) end -- Agendar o reset da storage para o valor -1 após o último estágio accumulatedTime = accumulatedTime + stages[#stages].time addEvent(changeStorage, accumulatedTime * 1000, cidGUID, -1) -- Verificar se o jogador já está transformado if not getCreatureCondition(cid, CONDITION_ATTRIBUTES) then OpenGate(cid, Select_Stages(getCreatureOutfit(cid).lookType), 1) return true else doSendCancel(cid, "Você já está transformado.") return false end end
Postado Abril 18, 2024 1 ano Autor Em 14/04/2024 em 17:48, Mateus Robeerto disse: function onCastSpell(cid, var) local waittime = 310 -- Tempo de exaustão local storage = 55512 -- Storage para controlar a spell local stages = { {time = 20, value = 1}, -- 20 segundos, storage = 1 {time = 30, value = 2}, -- 30 segundos adicionais, storage = 2 {time = 40, value = 3} -- 40 segundos adicionais, storage = 3 } if not isCreature(cid) then return false end -- Verificar se o jogador já usou a spell if getCreatureStorageValue(cid, storage) > 0 then doSendCancel(cid, "Você já está sob o efeito da spell.") return false end -- Definir a exaustão e a storage inicial doSetExhaustion(cid, storage, waittime) setCreatureStorageValue(cid, storage, 1) -- Função para alterar a storage e verificar se o jogador está online local function changeStorage(cidGUID, newValue) local creature = getCreatureByGUID(cidGUID) if creature and isCreature(creature) then setCreatureStorageValue(creature, storage, newValue) if newValue == -1 then doSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_BLUE, "O efeito da spell terminou.") else local creaturePos = getCreaturePosition(creature) for i = 1, 5 do doSendMagicEffect(creaturePos, CONST_ME_FIREWORK_RED) end doSendTextMessage(creature, MESSAGE_INFO_DESCR, "Você recebeu os atributos ML, FIST, SWORD, CLUB e AXE!") doAddCondition(creature, createConditionObject(CONDITION_ATTRIBUTES, 60 * 1000, { [CONDITION_PARAM_STAT_MAGICLEVEL] = 3, [CONDITION_PARAM_STAT_MAXHITPOINTS] = 3, [CONDITION_PARAM_STAT_MAXMANAPOINTS] = 3, [CONDITION_PARAM_STAT_SOULPOINTS] = 3, [CONDITION_PARAM_STAT_MAGICPOINTS] = 3 })) end end end -- Obter o GUID do jogador local cidGUID = getPlayerGUID(cid) -- Agendar as mudanças de storage local accumulatedTime = 0 for i, stage in ipairs(stages) do accumulatedTime = accumulatedTime + stage.time addEvent(changeStorage, accumulatedTime * 1000, cidGUID, stage.value) end -- Agendar o reset da storage para o valor -1 após o último estágio accumulatedTime = accumulatedTime + stages[#stages].time addEvent(changeStorage, accumulatedTime * 1000, cidGUID, -1) -- Verificar se o jogador já está transformado if not getCreatureCondition(cid, CONDITION_ATTRIBUTES) then OpenGate(cid, Select_Stages(getCreatureOutfit(cid).lookType), 1) return true else doSendCancel(cid, "Você já está transformado.") return false end end Spoiler function onCastSpell(cid, var) local waittime = 310 -- Tempo de exaustão local storage = 55512 -- Storage para controlar a spell local storage2 = 55513 -- Storage para controlar a spell local stages = { {time = 0, value = 1}, -- 0 segundos, storage = 1 {time = 30, value = 2}, -- 30 segundos adicionais, storage = 2 {time = 30, value = 3}, -- 40 segundos adicionais, storage = 3 {time = 40, value = 4}, -- 50 segundos adicionais, storage = 4 {time = 50, value = 5} -- 60 segundos adicionais, storage = 5 } if exhaustion.check(cid, storage2) then doPlayerSendCancel(cid, "Aguarde " .. exhaustion.get(cid, storage2) .. " segundos para usar a spell novamente.") return false end if not isCreature(cid) then return false end -- Verificar se o jogador já usou a spell if getPlayerStorageValue(cid, storage) > 0 then return false end -- Definir a exaustão e a storage inicial exhaustion.set(cid, storage2, waittime) setPlayerStorageValue(cid, storage, 1) -- Função para alterar a storage e verificar se o jogador está online local function changeStorage(cidGUID, newValue) local creature = getPlayerByGUID(cidGUID) if creature and isCreature(creature) then setPlayerStorageValue(creature, storage, newValue) if newValue == -1 then end end end -- Obter o GUID do jogador local cidGUID = getPlayerGUID(cid) -- Agendar as mudanças de storage local accumulatedTime = 0 for i, stage in ipairs(stages) do accumulatedTime = accumulatedTime + stage.time addEvent(changeStorage, accumulatedTime * 1000, cidGUID, stage.value) end -- Agendar o reset da storage para o valor -1 após o último estágio accumulatedTime = accumulatedTime + stages[#stages].time addEvent(changeStorage, accumulatedTime * 1000, cidGUID, -1) -- Verificar se o jogador já está transformado if getCreatureCondition(cid, CONDITION_ATTRIBUTES, 50) == false and getCreatureCondition(cid, CONDITION_HASTE, 51) == false and getCreatureCondition(cid, CONDITION_REGENERATION, 52) == false then OpenGate(cid, Select_Stages(getCreatureOutfit(cid).lookType), 1) return true else doPlayerSendCancel(cid, "Você já está transformado.") return true end end editei um pouco o codigo pra funcionar estava dando uns erros na distro, mais mesmo assim se deslogar durante o buff e estiver com uma storage, como a 3 por exemplo, (55512 = 3) depois de um tempo o player logar ela n volta pra -1, ele continua com a 3 ai no caso o player n iria conseguir usar o buff mais, não existe um codigo pra colocar no creaturescript pra quando todos os players logarem terem essa storage 55512 = -1?? facilitaria muito mais pois o codigo da spell ja esta funcional aqui. Editado Abril 18, 2024 1 ano por Gabrielx17 (veja o histórico de edições)
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.