Ir para conteúdo
  • Cadastre-se

(Resolvido)[ADAPTAÇÃO] Potion por %porcentagem


Ir para solução Resolvido por Crypter,

Posts Recomendados

Gostaria de colocar as potions de usar nos pokemons para curar em porcentagem, ao longo de 10 segundos.

function doHealOverTime(cid, heal, turn, effect)                     --alterado v1.6 peguem o script todo!!
if not isCreature(cid) then return true end

if turn <= 0 or (getCreatureHealth(cid) == getCreatureMaxHealth(cid)) or getPlayerStorageValue(cid, 173) <= 0 then
   setPlayerStorageValue(cid, 173, -1)
   return 
elseif getCreatureHealth(cid) + heal/10 >= getCreatureMaxHealth(cid) then
   doSendAnimatedText(getThingPos(cid), "+"..getCreatureMaxHealth(cid) - getCreatureHealth(cid), 65)
   doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
   doSendMagicEffect(getThingPos(cid), 12)
   return 
end

doSendAnimatedText(getThingPos(cid), "+"..heal/10, 65)
doCreatureAddHealth(cid, heal/10)
doSendMagicEffect(getThingPos(cid), 12)
addEvent(doHealOverTime, 1000, cid, heal, turn - 1, effect)
addEvent(doUpdateStatusPoke, 1100, getCreatureMaster(cid))
end

local potions = {
[2273] = {health = 400, animate = "SMALL POT", collor = 140},
[2272] = {health = 1500, animate = "GREAT POT", collor = 140},
[2271] = {health = 4000, animate = "MEGA POT", collor = 140},
[2275] = {health = 10000, animate = "HYPER POT", collor = 140},
[2274] = {health = 30000, animate = "SUPER POT", collor = 140},
}

function onUse(cid, item, frompos, item2, topos)

local pid = getThingFromPosWithProtect(topos)
local pokeballInfo = getPokeballInfo(getPlayerSlotItem(cid, 8).uid)

if not isCreature(pid) or not isSummon(pid) then
return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
end

if getCreatureMaster(pid) ~= cid then
return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
end

if getCreatureHealth(pid) == getCreatureMaxHealth(pid) then
return doPlayerSendCancel(cid, "This pokemon is already at full health.")
end

if getPlayerStorageValue(pid, 173) >= 1 then
return doPlayerSendCancel(cid, "This pokemon is already under effects of potions.")
end

if getPlayerStorageValue(cid, 52481) >= 1 then
return doPlayerSendCancel(cid, "You can't do that while a duel.")
end

doCreatureSay(cid, "".. pokeballInfo.nick..", take this potion!", TALKTYPE_SAY)
doSendAnimatedText(getThingPos(pid), potions[item.itemid].animate, potions[item.itemid].collor)
setPlayerStorageValue(pid, 173, 1)
doRemoveItem(item.uid, 1)

doHealOverTime(pid, potions[item.itemid].health, 10, 12)

return true
end

 

Link para o post
Compartilhar em outros sites
function doHealOverTime(cid, heal, turn, effect)                     --alterado v1.6 peguem o script todo!!
	if not isCreature(cid) then return true end
	local regen = (heal*getCreatureMaxHealth(cid)/100)
	
	if turn <= 0 or (getCreatureHealth(cid) == getCreatureMaxHealth(cid)) or getPlayerStorageValue(cid, 173) <= 0 then
	   setPlayerStorageValue(cid, 173, -1)
	   return
	elseif (getCreatureHealth*getCreatureMaxHealth(cid)/100) + regen >= getCreatureMaxHealth(cid) then
	   doSendAnimatedText(getThingPos(cid), "+".. math.ceil(100 - getCreatureHealth/getCreatureMaxHealth*100) .."%", 65)
	   doCreatureAddHealth(cid, regen)
	   doSendMagicEffect(getThingPos(cid), effect)
	   return 
	end


	doSendAnimatedText(getThingPos(cid), "+ "..heal.."%")
	doCreatureAddHealth(cid, regen )
	doSendMagicEffect(getThingPos(cid), effect)
	addEvent(doHealOverTime, 1000, cid, heal, turn - 1, effect)
	addEvent(doUpdateStatusPoke, 1005, getCreatureMaster(cid))
end

local potions = {
	[2273] = {health = 5, duration=10,effect= 12, animate = "SMALL POT", collor = 140},
	[2272] = {health = 10, duration=10,effect= 12, animate = "GREAT POT", collor = 140},
	[2271] = {health = 25, duration=10,effect= 12, animate = "MEGA POT", collor = 140},
	[2275] = {health = 40,duration=10, effect= 12, animate = "HYPER POT", collor = 140},
	[2274] = {health = 60, duration=10,effect= 12, animate = "SUPER POT", collor = 140},
}

function onUse(cid, item, frompos, item2, topos)

	local pid = getThingFromPosWithProtect(topos)
	local pokeballInfo = getPokeballInfo(getPlayerSlotItem(cid, 8).uid)

	if not isCreature(pid) or not isSummon(pid) then
		return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
	end

	if getCreatureMaster(pid) ~= cid then
		return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
	end

	if getCreatureHealth(pid) == getCreatureMaxHealth(pid) then
		return doPlayerSendCancel(cid, "This pokemon is already at full health.")
	end

	if getPlayerStorageValue(pid, 173) >= 1 then
		return doPlayerSendCancel(cid, "This pokemon is already under effects of potions.")
	end

	if getPlayerStorageValue(cid, 52481) >= 1 then
		return doPlayerSendCancel(cid, "You can't do that while a duel.")
	end

	doCreatureSay(cid, "".. pokeballInfo.nick..", take this potion!", TALKTYPE_SAY)
	doSendAnimatedText(getThingPos(pid), potions[item.itemid].animate, potions[item.itemid].collor)
	setPlayerStorageValue(pid, 173, 1)
	doRemoveItem(item.uid, 1)
	doHealOverTime(pid, potions[item.itemid].health, potions[item.itemid].duration, potions[item.itemid].effect)

	return true
end

 

Editado por DboExplorer (veja o histórico de edições)

 

Te ajudei ?? Que tal fazer uma contribuição ?

Doar

Link para o post
Compartilhar em outros sites

Deu errado amigão, acusou erro :(

[06/02/2018 18:20:29] [Error - LuaScriptInterface::loadFile] data/actions/scripts/potion.lua:9: unexpected symbol near '*'
[06/02/2018 18:20:29] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/potion.lua)
[06/02/2018 18:20:29] data/actions/scripts/potion.lua:9: unexpected symbol near '*'

 

Link para o post
Compartilhar em outros sites
function doHealOverTime(cid, heal, turn, effect)                     --alterado v1.6 peguem o script todo!!
	if not isCreature(cid) then return true end
	local regen = (heal*getCreatureMaxHealth(cid)/100)
	
	if turn <= 0 or (getCreatureHealth(cid) == getCreatureMaxHealth(cid)) or getPlayerStorageValue(cid, 173) <= 0 then
	   setPlayerStorageValue(cid, 173, -1)
	   return
	elseif (getCreatureHealth(cid)*getCreatureMaxHealth(cid)/100) + regen >= getCreatureMaxHealth(cid) then
	   doSendAnimatedText(getThingPos(cid), "+".. math.ceil(100 - getCreatureHealth(cid)/getCreatureMaxHealth(cid)*100) .."%", 65)
	   doCreatureAddHealth(cid, regen)
	   doSendMagicEffect(getThingPos(cid), effect)
	   return 
	end


	doSendAnimatedText(getThingPos(cid), "+ "..heal.."%")
	doCreatureAddHealth(cid, regen )
	doSendMagicEffect(getThingPos(cid), effect)
	addEvent(doHealOverTime, 1000, cid, heal, turn - 1, effect)
	addEvent(doUpdateStatusPoke, 1005, getCreatureMaster(cid))
end

local potions = {
	[2273] = {health = 5, duration=10,effect= 12, animate = "SMALL POT", collor = 140},
	[2272] = {health = 10, duration=10,effect= 12, animate = "GREAT POT", collor = 140},
	[2271] = {health = 25, duration=10,effect= 12, animate = "MEGA POT", collor = 140},
	[2275] = {health = 40,duration=10, effect= 12, animate = "HYPER POT", collor = 140},
	[2274] = {health = 60, duration=10,effect= 12, animate = "SUPER POT", collor = 140},
}

function onUse(cid, item, frompos, item2, topos)

	local pid = getThingFromPosWithProtect(topos)
	local pokeballInfo = getPokeballInfo(getPlayerSlotItem(cid, 8).uid)

	if not isCreature(pid) or not isSummon(pid) then
		return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
	end

	if getCreatureMaster(pid) ~= cid then
		return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
	end

	if getCreatureHealth(pid) == getCreatureMaxHealth(pid) then
		return doPlayerSendCancel(cid, "This pokemon is already at full health.")
	end

	if getPlayerStorageValue(pid, 173) >= 1 then
		return doPlayerSendCancel(cid, "This pokemon is already under effects of potions.")
	end

	if getPlayerStorageValue(cid, 52481) >= 1 then
		return doPlayerSendCancel(cid, "You can't do that while a duel.")
	end

	doCreatureSay(cid, "".. pokeballInfo.nick..", take this potion!", TALKTYPE_SAY)
	doSendAnimatedText(getThingPos(pid), potions[item.itemid].animate, potions[item.itemid].collor)
	setPlayerStorageValue(pid, 173, 1)
	doRemoveItem(item.uid, 1)
	doHealOverTime(pid, potions[item.itemid].health, potions[item.itemid].duration, potions[item.itemid].effect)

	return true
end

 

 

Te ajudei ?? Que tal fazer uma contribuição ?

Doar

Link para o post
Compartilhar em outros sites

Funcionando! mas quando eu uso uma potion ela n dura os 10 segundos e fica dizendo "This pokemon is aready under effects of potions.". Se achar mais fácil, pode tirar os 10 segundos e colocar para ela healar de uma só vez

Link para o post
Compartilhar em outros sites
function doHealOverTime(cid, heal, turn, effect)       
	if not isCreature(cid) then return true end
	local regen = (heal*getCreatureMaxHealth(cid)/100)
	
	if turn <= 0 or (getCreatureHealth(cid) == getCreatureMaxHealth(cid)) or getPlayerStorageValue(cid, 173) <= 0 then
	   setPlayerStorageValue(cid, 173, -1)
	   return
	elseif getCreatureHealth(cid) + regen >= getCreatureMaxHealth(cid) then
	   doSendAnimatedText(getThingPos(cid), "+".. math.ceil(100 - getCreatureHealth(cid)/getCreatureMaxHealth(cid)*100) .."%", 65)
	   doCreatureAddHealth(cid, regen)
	   doSendMagicEffect(getThingPos(cid), effect)
	   return 
	end


	doSendAnimatedText(getThingPos(cid), "+ "..heal.."%")
	doCreatureAddHealth(cid, regen )
	doSendMagicEffect(getThingPos(cid), effect)
	addEvent(doHealOverTime, 1000, cid, heal, turn - 1, effect)
	addEvent(doUpdateStatusPoke, 1005, getCreatureMaster(cid))
end

local potions = {
	[2273] = {health = 5, duration=10,effect= 12, animate = "SMALL POT", collor = 140},
	[2272] = {health = 10, duration=10,effect= 12, animate = "GREAT POT", collor = 140},
	[2271] = {health = 25, duration=10,effect= 12, animate = "MEGA POT", collor = 140},
	[2275] = {health = 40,duration=10, effect= 12, animate = "HYPER POT", collor = 140},
	[2274] = {health = 60, duration=10,effect= 12, animate = "SUPER POT", collor = 140},
}

function onUse(cid, item, frompos, item2, topos)

	local pid = getThingFromPosWithProtect(topos)
	local pokeballInfo = getPokeballInfo(getPlayerSlotItem(cid, 8).uid)

	if not isCreature(pid) or not isSummon(pid) then
		return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
	end

	if getCreatureMaster(pid) ~= cid then
		return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
	end

	if getCreatureHealth(pid) == getCreatureMaxHealth(pid) then
		return doPlayerSendCancel(cid, "This pokemon is already at full health.")
	end

	if getPlayerStorageValue(pid, 173) >= 1 then
		return doPlayerSendCancel(cid, "This pokemon is already under effects of potions.")
	end

	if getPlayerStorageValue(cid, 52481) >= 1 then
		return doPlayerSendCancel(cid, "You can't do that while a duel.")
	end

	doCreatureSay(cid, "".. pokeballInfo.nick..", take this potion!", TALKTYPE_SAY)
	doSendAnimatedText(getThingPos(pid), potions[item.itemid].animate, potions[item.itemid].collor)
	setPlayerStorageValue(pid, 173, 1)
	doRemoveItem(item.uid, 1)
	doHealOverTime(pid, potions[item.itemid].health, potions[item.itemid].duration, potions[item.itemid].effect)

	return true
end

 

 

Te ajudei ?? Que tal fazer uma contribuição ?

Doar

Link para o post
Compartilhar em outros sites

Deu um probleminha

[06/02/2018 18:40:18] [Error - Action Interface] 
[06/02/2018 18:40:18] data/actions/scripts/potion.lua:onUse
[06/02/2018 18:40:18] Description: 
[06/02/2018 18:40:18] attempt to index a function value
[06/02/2018 18:40:18] stack traceback:
[06/02/2018 18:40:18] 	[C]: in function 'doSendAnimatedText'
[06/02/2018 18:40:18] 	data/actions/scripts/potion.lua:16: in function 'doHealOverTime'
[06/02/2018 18:40:18] 	data/actions/scripts/potion.lua:60: in function <data/actions/scripts/potion.lua:31>

 

Link para o post
Compartilhar em outros sites
  • Solução
function doHealOverTime(cid, heal, turn, effect)                     --alterado v1.6 peguem o script todo!!
	if not isCreature(cid) then return true end
	local regen = (heal*getCreatureMaxHealth(cid)/100)
	
	if turn <= 0 or (getCreatureHealth(cid) == getCreatureMaxHealth(cid)) or getPlayerStorageValue(cid, 173) <= 0 then
	   return setPlayerStorageValue(cid, 173, -1)
	elseif getCreatureHealth(cid) + regen >= getCreatureMaxHealth(cid) then
	   doSendAnimatedText(getThingPos(cid), "+".. regen .."%", 65)
	   doCreatureAddHealth(cid, regen)
	   doSendMagicEffect(getThingPos(cid), effect)
	   return setPlayerStorageValue(cid, 173, -1)
	end


	doSendAnimatedText(getThingPos(cid), "+ "..heal.."%", 65)
	doCreatureAddHealth(cid, regen )
	doSendMagicEffect(getThingPos(cid), effect)
	addEvent(doHealOverTime, 1000, cid, heal, turn - 1, effect)
	addEvent(doUpdateStatusPoke, 1005, getCreatureMaster(cid))
end

local potions = {
	[2273] = {health = 5, duration=10,effect= 12, animate = "SMALL POT", collor = 140},
	[2272] = {health = 10, duration=10,effect= 12, animate = "GREAT POT", collor = 140},
	[2271] = {health = 25, duration=10,effect= 12, animate = "MEGA POT", collor = 140},
	[2275] = {health = 40,duration=10, effect= 12, animate = "HYPER POT", collor = 140},
	[2274] = {health = 60, duration=10,effect= 12, animate = "SUPER POT", collor = 140},
}

function onUse(cid, item, frompos, item2, topos)

	local pid = getThingFromPosWithProtect(topos)
	local pokeballInfo = getPokeballInfo(getPlayerSlotItem(cid, 8).uid)

	if not isCreature(pid) or not isSummon(pid) then
		return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
	end

	if getCreatureMaster(pid) ~= cid then
		return doPlayerSendCancel(cid, "You can only use potions on your own Pokemons!")
	end

	if getCreatureHealth(pid) == getCreatureMaxHealth(pid) then
		return doPlayerSendCancel(cid, "This pokemon is already at full health.")
	end

	if getPlayerStorageValue(pid, 173) >= 1 then
		return doPlayerSendCancel(cid, "This pokemon is already under effects of potions.")
	end

	if getPlayerStorageValue(cid, 52481) >= 1 then
		return doPlayerSendCancel(cid, "You can't do that while a duel.")
	end

	doCreatureSay(cid, "".. pokeballInfo.nick..", take this potion!", TALKTYPE_SAY)
	doSendAnimatedText(getThingPos(pid), potions[item.itemid].animate, potions[item.itemid].collor)
	setPlayerStorageValue(pid, 173, 1)
	doRemoveItem(item.uid, 1)
	doHealOverTime(pid, potions[item.itemid].health, potions[item.itemid].duration, potions[item.itemid].effect)

	return true
end

 

Editado por DboExplorer (veja o histórico de edições)

 

Te ajudei ?? Que tal fazer uma contribuição ?

Doar

Link para o post
Compartilhar em outros sites

Ainda 

 

[06/02/2018 18:53:22] [Error - Action Interface] 
[06/02/2018 18:53:22] data/actions/scripts/potion.lua:onUse
[06/02/2018 18:53:22] Description: 
[06/02/2018 18:53:22] attempt to index a function value
[06/02/2018 18:53:22] stack traceback:
[06/02/2018 18:53:22] 	[C]: in function 'doSendAnimatedText'
[06/02/2018 18:53:22] 	data/actions/scripts/potion.lua:15: in function 'doHealOverTime'
[06/02/2018 18:53:22] 	data/actions/scripts/potion.lua:59: in function <data/actions/scripts/potion.lua:30>

 

Link para o post
Compartilhar em outros sites
15 minutos atrás, DboExplorer disse:

Editado o copia de cima, testa agora

Funcionando perfeitamente! Muito obrigado *-*

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.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo