Postado Abril 8, 2024 1 ano nao testado! local config = { minSkill = 10, -- Valor mínimo da habilidade para começar a treinar gainChance = 50, -- Chance de ganhar skill, em porcentagem requiredItemID = 1234, -- ID do item necessário para treinar trainInterval = 3000, -- Intervalo de tempo para tentar ganhar skill (em milissegundos) skillsToTrain = { -- Habilidades correspondentes para cada vocação [0] = {1, 2}, -- Vocação sem classe [1] = {1, 2}, -- Knight [2] = {3}, -- Paladin [3] = {4}, -- Sorcerer [4] = {4}, -- Druid [5] = {4}, -- Master Sorcerer [6] = {4} -- Elder Druid } } local skillEvents = {} -- Tabela para armazenar os eventos de treino function isInRange(playerPosition, centerPosition, range) return math.abs(centerPosition.x - playerPosition.x) <= range and math.abs(centerPosition.y - playerPosition.y) <= range and centerPosition.z == playerPosition.z end function onStepIn(cid, item, position, fromPosition) if not isPlayer(cid) then return false end local vocation = getPlayerVocation(cid) if not config.skillsToTrain[vocation] then return false end for _, skillToTrain in ipairs(config.skillsToTrain[vocation]) do local skillLevel = getPlayerSkillLevel(cid, skillToTrain) if skillLevel < config.minSkill then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não tem a habilidade necessária para treinar aqui.") return true end local rightSlotItem = getPlayerSlotItem(cid, CONST_SLOT_RIGHT) if not rightSlotItem or rightSlotItem.itemid ~= config.requiredItemID then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você precisa estar equipado com o item necessário para treinar aqui.") return true end if skillEvents[cid] then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você já está em treinamento.") return true end skillEvents[cid] = addEvent(function() if not isPlayer(cid) then skillEvents[cid] = nil return end local currentPlayerPosition = getCreaturePosition(cid) if not isInRange(currentPlayerPosition, position, 1) then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não está mais na posição correta para treinar.") stopEvent(skillEvents[cid]) skillEvents[cid] = nil return end if math.random(100) <= config.gainChance then doPlayerAddSkillTry(cid, skillToTrain) doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você ganhou experiência em " .. getSkillName(skillToTrain) .. ".") else doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não ganhou experiência em " .. getSkillName(skillToTrain) .. ".") end end, config.trainInterval) doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Iniciando treinamento em " .. getSkillName(skillToTrain) .. "...") end return true end function onLogout(cid) if skillEvents[cid] then stopEvent(skillEvents[cid]) skillEvents[cid] = nil end return true end
Postado Abril 8, 2024 1 ano Diretor Em 04/04/2024 em 14:04, HexusAlphos disse: continua igual posta sua lib 032-position pra nos ver que tipo de pos vc usa Eu sou um entusiasta da programação apaixonado por ajudar a comunidade open source a crescer. Sempre em busca de novos desafios e oportunidades para contribuir com meu código. #OpenSource #Programação #Contribuição
Postado Abril 8, 2024 1 ano Autor 11 horas atrás, L3K0T disse: posta sua lib 032-position pra nos ver que tipo de pos vc usa function isInRange(position, fromPosition, toPosition) return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z) end function getDistanceBetween(fromPosition, toPosition) local x, y = math.abs(fromPosition.x - toPosition.x), math.abs(fromPosition.y - toPosition.y) local diff = math.max(x, y) if(fromPosition.z ~= toPosition.z) then diff = diff + 9 + 6 end return diff end function getDirectionTo(pos1, pos2) local dir = NORTH if(pos1.x > pos2.x) then dir = WEST if(pos1.y > pos2.y) then dir = NORTHWEST elseif(pos1.y < pos2.y) then dir = SOUTHWEST end elseif(pos1.x < pos2.x) then dir = EAST if(pos1.y > pos2.y) then dir = NORTHEAST elseif(pos1.y < pos2.y) then dir = SOUTHEAST end else if(pos1.y > pos2.y) then dir = NORTH elseif(pos1.y < pos2.y) then dir = SOUTH end end return dir end function getCreatureLookPosition(cid) return getPosByDir(getThingPos(cid), getCreatureLookDirection(cid)) end function getPositionByDirection(position, direction, size) local n = size or 1 if(direction == NORTH) then position.y = position.y - n elseif(direction == SOUTH) then position.y = position.y + n elseif(direction == WEST) then position.x = position.x - n elseif(direction == EAST) then position.x = position.x + n elseif(direction == NORTHWEST) then position.y = position.y - n position.x = position.x - n elseif(direction == NORTHEAST) then position.y = position.y - n position.x = position.x + n elseif(direction == SOUTHWEST) then position.y = position.y + n position.x = position.x - n elseif(direction == SOUTHEAST) then position.y = position.y + n position.x = position.x + n end return position end function doComparePositions(position, positionEx) return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z end function getArea(position, x, y) local t = {} for i = (position.x - x), (position.x + x) do for j = (position.y - y), (position.y + y) do table.insert(t, {x = i, y = j, z = position.z}) end end return t end 11 horas atrás, Mateus Robeerto disse: nao testado! local config = { minSkill = 10, -- Valor mínimo da habilidade para começar a treinar gainChance = 50, -- Chance de ganhar skill, em porcentagem requiredItemID = 1234, -- ID do item necessário para treinar trainInterval = 3000, -- Intervalo de tempo para tentar ganhar skill (em milissegundos) skillsToTrain = { -- Habilidades correspondentes para cada vocação [0] = {1, 2}, -- Vocação sem classe [1] = {1, 2}, -- Knight [2] = {3}, -- Paladin [3] = {4}, -- Sorcerer [4] = {4}, -- Druid [5] = {4}, -- Master Sorcerer [6] = {4} -- Elder Druid } } local skillEvents = {} -- Tabela para armazenar os eventos de treino function isInRange(playerPosition, centerPosition, range) return math.abs(centerPosition.x - playerPosition.x) <= range and math.abs(centerPosition.y - playerPosition.y) <= range and centerPosition.z == playerPosition.z end function onStepIn(cid, item, position, fromPosition) if not isPlayer(cid) then return false end local vocation = getPlayerVocation(cid) if not config.skillsToTrain[vocation] then return false end for _, skillToTrain in ipairs(config.skillsToTrain[vocation]) do local skillLevel = getPlayerSkillLevel(cid, skillToTrain) if skillLevel < config.minSkill then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não tem a habilidade necessária para treinar aqui.") return true end local rightSlotItem = getPlayerSlotItem(cid, CONST_SLOT_RIGHT) if not rightSlotItem or rightSlotItem.itemid ~= config.requiredItemID then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você precisa estar equipado com o item necessário para treinar aqui.") return true end if skillEvents[cid] then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você já está em treinamento.") return true end skillEvents[cid] = addEvent(function() if not isPlayer(cid) then skillEvents[cid] = nil return end local currentPlayerPosition = getCreaturePosition(cid) if not isInRange(currentPlayerPosition, position, 1) then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não está mais na posição correta para treinar.") stopEvent(skillEvents[cid]) skillEvents[cid] = nil return end if math.random(100) <= config.gainChance then doPlayerAddSkillTry(cid, skillToTrain) doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você ganhou experiência em " .. getSkillName(skillToTrain) .. ".") else doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não ganhou experiência em " .. getSkillName(skillToTrain) .. ".") end end, config.trainInterval) doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Iniciando treinamento em " .. getSkillName(skillToTrain) .. "...") end return true end function onLogout(cid) if skillEvents[cid] then stopEvent(skillEvents[cid]) skillEvents[cid] = nil end return true end não aponta nenhum erro na distro, mas também não upa a skill. Não sei se é pq meu servidor possui muitas voc (800+), já que é uma variação de nto Editado Abril 8, 2024 1 ano por HexusAlphos (veja o histórico de edições)
Postado Abril 9, 2024 1 ano Adicionei o comando "print" para imprimir no console e saber o que aconteceu, etc. Isso vai ajudar bastante. local config = { minSkill = 10, -- Valor mínimo da habilidade para começar a treinar gainChance = 50, -- Chance de ganhar skill, em porcentagem requiredItemID = 2140, -- ID do item necessário para treinar trainInterval = 3000, -- Intervalo de tempo para tentar ganhar skill (em milissegundos) skillsToTrain = { -- Habilidades correspondentes para cada vocação [0] = {1, 2}, -- Vocação sem classe [1] = {1, 2}, -- Knight [2] = {3}, -- Paladin [3] = {4}, -- Sorcerer [4] = {4}, -- Druid [5] = {4}, -- Master Sorcerer [6] = {4} -- Elder Druid } } local skillEvents = {} -- Tabela para armazenar os eventos de treino function isInRange(playerPosition, centerPosition, range) return math.abs(centerPosition.x - playerPosition.x) <= range and math.abs(centerPosition.y - playerPosition.y) <= range and centerPosition.z == playerPosition.z end function onStepIn(cid, item, position, fromPosition) print("Entrou na função onStepIn") if not isPlayer(cid) then print("O personagem não é um jogador") return false end local vocation = getPlayerVocation(cid) print("Vocação do jogador: " .. vocation) if not config.skillsToTrain[vocation] then print("Vocação não encontrada na configuração de treino") return false end for _, skillToTrain in ipairs(config.skillsToTrain[vocation]) do local skillLevel = getPlayerSkillLevel(cid, skillToTrain) print("Nível da habilidade " .. skillToTrain .. ": " .. skillLevel) if skillLevel < config.minSkill then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não tem a habilidade necessária para treinar aqui.") return true end local rightSlotItem = getPlayerSlotItem(cid, CONST_SLOT_RIGHT) if not rightSlotItem or rightSlotItem.itemid ~= config.requiredItemID then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você precisa estar equipado com o item necessário para treinar aqui.") return true end if skillEvents[cid] then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você já está em treinamento.") return true end skillEvents[cid] = addEvent(function() print("Iniciando evento de treinamento") if not isPlayer(cid) then skillEvents[cid] = nil return end local currentPlayerPosition = getCreaturePosition(cid) if not isInRange(currentPlayerPosition, position, 1) then doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não está mais na posição correta para treinar.") stopEvent(skillEvents[cid]) skillEvents[cid] = nil return end if math.random(100) <= config.gainChance then doPlayerAddSkillTry(cid, skillToTrain) doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você ganhou experiência em " .. getSkillName(skillToTrain) .. ".") else doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Você não ganhou experiência em " .. getSkillName(skillToTrain) .. ".") end end, config.trainInterval) doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Iniciando treinamento em " .. getSkillName(skillToTrain) .. "...") end return true end function onLogout(cid) if skillEvents[cid] then stopEvent(skillEvents[cid]) skillEvents[cid] = nil end return true end
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.