Ir para conteúdo
  • Cadastre-se

(Resolvido)GetGainedExperience, como usar a função?


Ir para solução Resolvido por Vodkart,

Posts Recomendados

.Qual servidor ou website você utiliza como base? 

OTX 2

 

Qual o motivo deste tópico? 

Estou adaptando um script que encontrei aqui no forum de Daily Boosted Monster, porém meu server é por rates, e para add a Exp bonus eu vou usar a função ( doPlayerAddExpEx ) , porém, pra eu fazer como eu quero eu preciso que independente do level que está ou qual estage, eu quero uma função que me retorne quanto o monstro deu de EXP quando matei ele, para que eu poder usar mais ou menos da seguinte forma doPlayerAddExpEx(cid, XP QUE GANHEI/100*0.30) , a questão é, QUAL FUNÇÃO USO PARA ME RETORNAR O VALOR QUE GANHEI?

 

 

Link para o post
Compartilhar em outros sites
local exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
local amount = math.floor(getMonsterInfo(string.lower(getCreatureName(target))).experience*exp)
doPlayerAddExperience(cid, amount)

 

se quer adicionar em porcentagem, pode ser assim:

 

local percent = 0.25 -- 25%
local exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
local amount = math.floor(((getMonsterInfo(string.lower(getCreatureName(target))).experience*exp)*percent))
doPlayerAddExperience(cid, amount)

 

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Link para o post
Compartilhar em outros sites

testando nesse momento, dei reload e vou ver o que da, e ja retorno. Caso não de vou lhe mostrar qual script usei aqui, para facilitar o entendimento.

17 minutos atrás, Vodkart disse:

local exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
local amount = math.floor(getMonsterInfo(string.lower(getCreatureName(target))).experience*exp)
doPlayerAddExperience(cid, amount)

 

se quer adicionar em porcentagem, pode ser assim:

 


local percent = 0.25 -- 25%
local exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
local amount = math.floor(((getMonsterInfo(string.lower(getCreatureName(target))).experience*exp)*percent))
doPlayerAddExperience(cid, amount)

 

o primeiro testei o em porcentagem, o monster do dia acaba a vida e não morre, fica de pé ali, e os demais, morrem, dão loot, mas não dão exp alguma. Agora to reiniciando pra testar o de cima.

Em 29/04/2020 em 23:36, MatteusDeli disse:

@bellatrikz Boa noite, veja se é isso que voce quer 

 

data/lib crie um arquivo chamado boostedMonster.lua e cole isto dentro:


monster_name_backup = 74812 -- nao mexer
monster_exp_backup = 74813 -- nao mexer
monster_loot_backup = 74814 -- nao mexer

config_boosted = {

    ["00:00:00"] = { -- Horario de cada dia que irá ocorrer a troca dos monstros
        pos_monster = {x=161,y=58,z=7, stackpos = 253}, -- a posição aonde ficara o monstro informando a quantidade de exp e loot
        time_effects = 2 -- tempo em segundos que ficará saindo os efeitos
    }
    
}

monsters_boosteds = { -- Configuracao dos monstros que irão ter exp e loot aumentados
	[1] = {monster_name = "Dwarf", exp = 5, loot = 7},
	[2] = {monster_name = "Goblin", exp = 15, loot = 5},
	[3] = {monster_name = "Orc", exp = 25, loot = 15},
    [4] = {monster_name = "Dwarf Soldier", exp = 35, loot = 10},
    --[5] = {monster_name = "NOME DO MONSTRO", exp = "PORCENTAGEM DE EXP", loot = "PORCENTAGEM DO LOOT"},
}

 

agora em data/globalevents/scripts crie um arquivo chamado boosted.lua e cole isto dentro:



function onThink(interval, lastExecution)
	local current_hour = os.date("%X")
	if config_boosted[current_hour] then
		local time = config_boosted[current_hour]
		
		local monster = getTopCreature(time.pos_monster).uid
		local random_monster = monsters_boosteds[math.random(1, #monsters_boosteds)]
		if (monster >= 1) then
			doRemoveCreature(monster)
		end
		SummonMonster(time, random_monster)
		setGlobalStorageValue(monster_name_backup, random_monster.monster_name)
		setGlobalStorageValue(monster_exp_backup, random_monster.exp)
		setGlobalStorageValue(monster_loot_backup, random_monster.loot)
	end
	return true
end 	


function SummonMonster(time, monster)
	doCreateMonster(monster.monster_name, time.pos_monster)
	effectsMonster(time, monster)
end

function effectsMonster(time, monster)

	effectLoot(time.pos_monster, monster)
	effectExp(time.pos_monster, monster)
	doSendMagicEffect(time.pos_monster, 30)
	doSendAnimatedText(time.pos_monster, "Boosted", COLOR_DARKYELLOW)

	addEvent(function()
		effectsMonster(time, monster)
	end, time.time_effects * 1000)
end

function effectLoot(pos, monster)
	local pos_effect = {x=pos.x, y=pos.y-1, z=pos.z}
	doSendMagicEffect(pos_effect, 29)
	doSendAnimatedText(pos_effect, "Loot +"..monster.loot.."%", COLOR_DARKYELLOW)
end

function effectExp(pos, monster)
	local pos_effect = {x=pos.x, y=pos.y+1, z=pos.z}
	doSendMagicEffect(pos_effect, 29)
	doSendAnimatedText(pos_effect, "EXP +"..monster.exp.."%", COLOR_DARKYELLOW)
end

Em globalevents.xml registre esta tag:


<globalevent name="boosted" interval="1000" event="script" value="boosted.lua"/>

 

Agora em data/creatureevents/scripts crie um arquivo chamado boosted.lua e cole isto dentro:



function onKill(cid, target, damage, flags)
	
	if not (isMonster(target)) then
		return true
	end

	if (string.lower(getCreatureName(target)) == string.lower(getGlobalStorageValue(monster_name_backup))) then
		local exp = tonumber(getGlobalStorageValue(74813))
		doPlayerSetRate(cid, SKILL__LEVEL, getExperienceStage(getPlayerLevel(cid))*(getGlobalStorageValue(monster_exp_backup) / 1000))
		addLoot(getCreaturePosition(target), getCreatureName(target), {})
	else
		doPlayerSetRate(cid, SKILL__LEVEL, 1)
	end

	return true
end

function addLoot(position, name, ignoredList)
    local check = false
    for i = 0, 255 do
        position.stackpos = i
        corpse = getTileThingByPos(position)
        if corpse.uid > 0 and isCorpse(corpse.uid) then
            check = true 
            break
        end
    end
	if check == true then
        local newRate = (1 + (getGlobalStorageValue(monster_loot_backup)/100)) * getConfigValue("rateLoot")
        local mainbp = doCreateItemEx(1987, 1)
        local monsterLoot = getMonsterLootList(name)
        for i, loot in pairs(monsterLoot) do
            if math.random(1, 100000) <= newRate * loot.chance then 
                if #ignoredList > 0 then
                    if (not isInArray(ignoredList, loot.id)) then
                        doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                    end
                else
                    doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                end
            end
        end
        doAddContainerItemEx(corpse.uid, mainbp)  
    end
end

 

Em creatureevent.xml registre esta tag:


<event type="kill" name="BoostedMonster" event="script" value="boosted.lua"/>

 

Por ultimo abra o arquivo login.lua na mesma pasta (creatureevents/scripts) e cole esta linha antes do ultimo return true:


registerCreatureEvent(cid, "BoostedMonster")

 

OBS: A explicação de como adicionar os monstros etc.. Esta no arquivo boostedMonster.lua em data/lib.

o script que estou usando é este, porém ele não estava dando exp alguma... Ai fui modificando até que consegui fazer ele diferenciar os outros monstros do que esta de boost... Mas nao consegui add o bonus até agora. @Vodkart

Link para o post
Compartilhar em outros sites
  • Solução

na lib tenta deixar assim:

 

monsters_boosteds = { -- Configuracao dos monstros que irão ter exp e loot aumentados
	[1] = {monster_name = "Dwarf", exp = 0.05, loot = 7},
	[2] = {monster_name = "Goblin", exp = 0.05, loot = 5},
	[3] = {monster_name = "Orc", exp = 0.25, loot = 15},
    [4] = {monster_name = "Dwarf Soldier", exp = 0.35, loot = 10},
    --[5] = {monster_name = "NOME DO MONSTRO", exp = "PORCENTAGEM DE EXP", loot = "PORCENTAGEM DO LOOT"},
}

 

 

o onKill

 

function onKill(cid, target, damage, flags)
	if not (isMonster(target)) then
		return true
	end
	if (string.lower(getCreatureName(target)) == string.lower(getGlobalStorageValue(monster_name_backup))) then
	local percent = tonumber(getGlobalStorageValue(74813))
	local exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
	local amount = math.floor(((getMonsterInfo(string.lower(getCreatureName(target))).experience*exp)*percent))
	doPlayerAddExperience(cid, amount)
	addLoot(getCreaturePosition(target), getCreatureName(target), {})
	end
	return true
end
function addLoot(position, name, ignoredList)
    local check = false
    for i = 0, 255 do
        position.stackpos = i
        corpse = getTileThingByPos(position)
        if corpse.uid > 0 and isCorpse(corpse.uid) then
            check = true 
            break
        end
    end
	if check == true then
        local newRate = (1 + (getGlobalStorageValue(monster_loot_backup)/100)) * getConfigValue("rateLoot")
        local mainbp = doCreateItemEx(1987, 1)
        local monsterLoot = getMonsterLootList(name)
        for i, loot in pairs(monsterLoot) do
            if math.random(1, 100000) <= newRate * loot.chance then 
                if #ignoredList > 0 then
                    if (not isInArray(ignoredList, loot.id)) then
                        doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                    end
                else
                    doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                end
            end
        end
        doAddContainerItemEx(corpse.uid, mainbp)  
    end
end

 

 

OBS: O EVENTO TEM QUE SER COMEÇADO DE NOVO PARA ATUALIZAR A EXP NA STORAGE, ou seja, testa só depois que dar o boost exp

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Link para o post
Compartilhar em outros sites
1 hora atrás, Vodkart disse:

na lib tenta deixar assim:

 


monsters_boosteds = { -- Configuracao dos monstros que irão ter exp e loot aumentados
	[1] = {monster_name = "Dwarf", exp = 0.05, loot = 7},
	[2] = {monster_name = "Goblin", exp = 0.05, loot = 5},
	[3] = {monster_name = "Orc", exp = 0.25, loot = 15},
    [4] = {monster_name = "Dwarf Soldier", exp = 0.35, loot = 10},
    --[5] = {monster_name = "NOME DO MONSTRO", exp = "PORCENTAGEM DE EXP", loot = "PORCENTAGEM DO LOOT"},
}

 

 

o onKill

 


function onKill(cid, target, damage, flags)
	if not (isMonster(target)) then
		return true
	end
	if (string.lower(getCreatureName(target)) == string.lower(getGlobalStorageValue(monster_name_backup))) then
	local percent = tonumber(getGlobalStorageValue(74813))
	local exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
	local amount = math.floor(((getMonsterInfo(string.lower(getCreatureName(target))).experience*exp)*percent))
	doPlayerAddExperience(cid, amount)
	addLoot(getCreaturePosition(target), getCreatureName(target), {})
	end
	return true
end
function addLoot(position, name, ignoredList)
    local check = false
    for i = 0, 255 do
        position.stackpos = i
        corpse = getTileThingByPos(position)
        if corpse.uid > 0 and isCorpse(corpse.uid) then
            check = true 
            break
        end
    end
	if check == true then
        local newRate = (1 + (getGlobalStorageValue(monster_loot_backup)/100)) * getConfigValue("rateLoot")
        local mainbp = doCreateItemEx(1987, 1)
        local monsterLoot = getMonsterLootList(name)
        for i, loot in pairs(monsterLoot) do
            if math.random(1, 100000) <= newRate * loot.chance then 
                if #ignoredList > 0 then
                    if (not isInArray(ignoredList, loot.id)) then
                        doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                    end
                else
                    doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                end
            end
        end
        doAddContainerItemEx(corpse.uid, mainbp)  
    end
end

 

 

OBS: O EVENTO TEM QUE SER COMEÇADO DE NOVO PARA ATUALIZAR A EXP NA STORAGE, ou seja, testa só depois que dar o boost exp

A última ali eu testei e deu mais ou menos certo, só que alguma parte do cálculo ela tá fazendo errado, vou alterar agora as partes que me mandou e ver o que sai… mas já me resolveu parcialmente o problema… acredito que agora vai, vou testar e retorno aqui. 

Link para o post
Compartilhar em outros sites
17 horas atrás, Vodkart disse:

na lib tenta deixar assim:

 


monsters_boosteds = { -- Configuracao dos monstros que irão ter exp e loot aumentados
	[1] = {monster_name = "Dwarf", exp = 0.05, loot = 7},
	[2] = {monster_name = "Goblin", exp = 0.05, loot = 5},
	[3] = {monster_name = "Orc", exp = 0.25, loot = 15},
    [4] = {monster_name = "Dwarf Soldier", exp = 0.35, loot = 10},
    --[5] = {monster_name = "NOME DO MONSTRO", exp = "PORCENTAGEM DE EXP", loot = "PORCENTAGEM DO LOOT"},
}

 

 

o onKill

 


function onKill(cid, target, damage, flags)
	if not (isMonster(target)) then
		return true
	end
	if (string.lower(getCreatureName(target)) == string.lower(getGlobalStorageValue(monster_name_backup))) then
	local percent = tonumber(getGlobalStorageValue(74813))
	local exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
	local amount = math.floor(((getMonsterInfo(string.lower(getCreatureName(target))).experience*exp)*percent))
	doPlayerAddExperience(cid, amount)
	addLoot(getCreaturePosition(target), getCreatureName(target), {})
	end
	return true
end
function addLoot(position, name, ignoredList)
    local check = false
    for i = 0, 255 do
        position.stackpos = i
        corpse = getTileThingByPos(position)
        if corpse.uid > 0 and isCorpse(corpse.uid) then
            check = true 
            break
        end
    end
	if check == true then
        local newRate = (1 + (getGlobalStorageValue(monster_loot_backup)/100)) * getConfigValue("rateLoot")
        local mainbp = doCreateItemEx(1987, 1)
        local monsterLoot = getMonsterLootList(name)
        for i, loot in pairs(monsterLoot) do
            if math.random(1, 100000) <= newRate * loot.chance then 
                if #ignoredList > 0 then
                    if (not isInArray(ignoredList, loot.id)) then
                        doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                    end
                else
                    doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                end
            end
        end
        doAddContainerItemEx(corpse.uid, mainbp)  
    end
end

 

 

OBS: O EVENTO TEM QUE SER COMEÇADO DE NOVO PARA ATUALIZAR A EXP NA STORAGE, ou seja, testa só depois que dar o boost exp

cara, em partes, deu certo... porém, ta me dando o bonus conforme o valor total de exp do monstro, que é o que ta me retornando, porém meu server é por rates... Então o valor do bonus ta me dando muito além do que o valor que eu realmente estou ganhando... Ali onde retorna o valor de exp que o monstro deu, tem algum meio de retornar não o valor total de exp que ele da, e sim o valor que o player está ganhando conforme os rates dele?

@Vodkart

Retornando para dizer como foi resolvido... Usei as funções que voce ensinou, e fiz algumas config locais a mais para eu conseguir chegar no resultado que eu queria, que era apenas o bonus de 30% em cima do valor de EXP que o monstro me daria sem rate extra algum, nem o bonus stamina, nem bonus vip, nem bonus castle... Apenas o valor ganho conforme o rate do player, somando 30% a mais... Provavelmente você saberia fazer de uma forma mais simples mas fiz assim alterando as informações que você me deu...

function onKill(cid, target, damage, flags)
	if not (isMonster(target)) then
		return true
	end
	if (string.lower(getCreatureName(target)) == string.lower(getGlobalStorageValue(monster_name_backup))) then
	local percent = tonumber(getGlobalStorageValue(74813))
	local rate = tonumber(getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier))
	local amount = math.floor((getMonsterInfo(string.lower(getCreatureName(target))).experience))
	local bonus = tonumber((amount / 100 * rate)*100)
	local final = math.floor(bonus / 100 * percent)
	
	doPlayerAddExpEx(cid, final)
	addLoot(getCreaturePosition(target), getCreatureName(target), {})
	end
	return true
	
end

PS: Usando a função doPlayerAddExperience não estava recebendo nada de bonus, mas como a função que eu queria usar ja era a AddExpEx, assim fiz, e então ficou como eu queria, só o que vou tentar agora, mas vou tentar estudar para fazer solo e assim aprender, é colocar para que todos os monstros da mesma raça dêem o Bonus, ( Frost Dragon, Castle Frost Dragon, Donate Frost, etc.. ), inclusive vou usar as informações do seu mod Simple Task, que eu tambem uso, para pegar as funções e configs necessárias... Por hora me ajudou 500% ! Tu é o melhor cara, rep+ e topico encerrado já com a solução que eu usei somada a sua ajuda.

Link para o post
Compartilhar em outros sites

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.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo