• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

potion of the gods

Shoorkill

Member
Joined
Dec 17, 2018
Messages
126
Reaction score
21
PI need it to work as follows:
When using the potion, the character receives charges of 20% of mana and total life, every 5 seconds for 1 minute
When using the potion it must be removed and 50 souls will be needed to use the potion, which will also be removed when used
The potion cannot be used again while it is still in effect.
 
This should work.

data/scripts/filename.lua
Lua:
local config = {
    itemId = 1111,
    removeItem = true,
    soulAmount = 50,
    duration = 60, -- in seconds
    ticks = 5000, -- milliseconds (how often it heals)
    healhPercent = 20,
    manaPercent = 20
}

local potionUsers = {} -- don't touch

local function potion(playerId)
    local player = Player(playerId)
    if not player then
        potionUsers[playerId] = nil
        return
    end
    
    local maxHealth = player:getMaxHealth()
    local currentHealth = player:getHealth()
    
    if currentHealth < maxHealth then
        local healthToAdd = math.min(maxHealth - currentHealth, math.floor((maxHealth * config.healhPercent) / 100))
        player:addHealth(healthToAdd)
    end
    
    local maxMana = player:getMaxMana()
    local currentMana = player:getMana()
    
    if currentMana < maxMana then
        local manaToAdd = math.min(maxMana - currentMana, math.floor((maxMana * config.manaPercent) / 100))
        player:addMana(manaToAdd)
    end    
    
    if potionUsers[playerId] > 0 then
        potionUsers[playerId] = potionUsers[playerId] - config.ticks
        addEvent(potion, config.ticks, playerId)
        return
    end
    
    player:say("Potion deactivated!", TALKTYPE_MONSTER_SAY)
    potionUsers[playerId] = nil
end

local potionOfTheGods = Action()

function potionOfTheGods.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerId = player:getId()
    if potionUsers[playerId] then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Potion is still active.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF, player) -- shows only for this player
        return false
    end
    
    if player:getSoul() < config.soulAmount then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Insufficient soul.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF, player)
        return false
    end
    
    potionUsers[playerId] = config.duration * 1000
    player:addSoul(-config.soulAmount)
    
    if config.removeItem then
        item:remove(1)
    end

    potion(playerId)
    player:say("Potion activated!", TALKTYPE_MONSTER_SAY)
    return true
end

potionOfTheGods:id(config.itemId)
potionOfTheGods:register()
 
Last edited:
This should work.

data/scripts/filename.lua
Lua:
local config = {
    itemId = 1111,
    removeItem = true,
    soulAmount = 50,
    duration = 60, -- in seconds
    ticks = 5000, -- milliseconds (how often it heals)
    healhPercent = 20,
    manaPercent = 20
}

local potionUsers = {} -- don't touch

local function potion(playerId)
    local player = Player(playerId)
    if not player then
        potionUsers[playerId] = nil
        return
    end
   
    local maxHealth = player:getMaxHealth()
    local currentHealth = player:getHealth()
   
    if currentHealth < maxHealth then
        local healthToAdd = math.min(maxHealth - currentHealth, math.floor((maxHealth * config.healhPercent) / 100))
        player:addHealth(healthToAdd)
    end
   
    local maxMana = player:getMaxMana()
    local currentMana = player:getMana()
   
    if currentMana < maxMana then
        local manaToAdd = math.min(maxMana - currentMana, math.floor((maxMana * config.manaPercent) / 100))
        player:addMana(manaToAdd)
    end   
   
    if potionUsers[playerId] > 0 then
        potionUsers[playerId] = potionUsers[playerId] - config.ticks
        addEvent(potion, config.ticks, playerId)
        return
    end
   
    player:say("Potion deactivated!", TALKTYPE_MONSTER_SAY)
    potionUsers[playerId] = nil
end

local potionOfTheGods = Action()

function potionOfTheGods.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerId = player:getId()
    if potionUsers[playerId] then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Potion is still active.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF, player) -- shows only for this player
        return false
    end
   
    if player:getSoul() < config.soulAmount then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Insufficient soul.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF, player)
        return false
    end
   
    potionUsers[playerId] = config.duration * 1000
    player:addSoul(-config.soulAmount)
   
    if config.removeItem then
        item:remove(1)
    end

    potion(playerId)
    player:say("Potion activated!", TALKTYPE_MONSTER_SAY)
    return true
end

potionOfTheGods:id(config.itemId)
potionOfTheGods:register()
it would be nice to put effect and animation during regeneration? if yes, how do you place it?
 
it would be nice to put effect and animation during regeneration? if yes, how do you place it?
Try this. (and if it works, can you post a short video? xD)

Lua:
local config = {
    itemId = 1111,
    removeItem = true,
    soulAmount = 50,
    duration = 60, -- in seconds
    ticks = 5000, -- milliseconds (how often it heals)
    healhPercent = 20,
    manaPercent = 20,
    regenerationEffect = CONST_ME_MAGIC_GREEN,
    buffActiveEffect = CONST_ME_MAGIC_RED,
    buffActiveEffectTicks = 1500
}

local potionUsers = {} -- don't touch

local function potion(playerId)
    local player = Player(playerId)
    if not player then
        potionUsers[playerId] = nil
        return
    end
    
    local sendEffect = false
    
    local maxHealth = player:getMaxHealth()
    local currentHealth = player:getHealth()
    
    if currentHealth < maxHealth then
        local healthToAdd = math.min(maxHealth - currentHealth, math.floor((maxHealth * config.healhPercent) / 100))
        player:addHealth(healthToAdd)
        sendEffect = true
    end
    
    local maxMana = player:getMaxMana()
    local currentMana = player:getMana()
    
    if currentMana < maxMana then
        local manaToAdd = math.min(maxMana - currentMana, math.floor((maxMana * config.manaPercent) / 100))
        player:addMana(manaToAdd)
        sendEffect = true
    end
    
    if sendEffect then
        player:getPosition():sendMagicEffect(config.regenerationEffect)
    end
    
    if potionUsers[playerId] > 0 then
        potionUsers[playerId] = potionUsers[playerId] - config.ticks
        addEvent(potion, config.ticks, playerId)
        return
    end
    
    player:say("Potion deactivated!", TALKTYPE_MONSTER_SAY)
    potionUsers[playerId] = nil
end

local function buffAnimation(playerId, lastKnownDuration)
    local player = Player(playerId)
    if not player then
        return
    end
    
    if not potionUsers[playerId] then
        return
    end
    
    if potionUsers[playerId] > lastKnownDuration then
        return
    end
    
    player:getPosition():sendMagicEffect(config.buffActiveEffect)
    addEvent(buffAnimation, config.buffActiveEffectTicks, playerId, potionUsers[playerId])
end

local potionOfTheGods = Action()

function potionOfTheGods.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerId = player:getId()
    if potionUsers[playerId] then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Potion is still active.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF, player) -- shows only for this player
        return false
    end
    
    if player:getSoul() < config.soulAmount then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Insufficient soul.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF, player)
        return false
    end
    
    potionUsers[playerId] = config.duration * 1000
    player:addSoul(-config.soulAmount)
    
    if config.removeItem then
        item:remove(1)
    end

    buffAnimation(playerId, potionUsers[playerId])
    potion(playerId)
    player:say("Potion activated!", TALKTYPE_MONSTER_SAY)
    return true
end

potionOfTheGods:id(config.itemId)
potionOfTheGods:register()
 
Last edited:
Try this. (and if it works, can you post a short video? xD)

Lua:
local config = {
    itemId = 1111,
    removeItem = true,
    soulAmount = 50,
    duration = 60, -- in seconds
    ticks = 5000, -- milliseconds (how often it heals)
    healhPercent = 20,
    manaPercent = 20,
    regenerationEffect = CONST_ME_MAGIC_GREEN,
    buffActiveEffect = CONST_ME_MAGIC_RED,
    buffActiveEffectTicks = 1500
}

local potionUsers = {} -- don't touch

local function potion(playerId)
    local player = Player(playerId)
    if not player then
        potionUsers[playerId] = nil
        return
    end
  
    local sendEffect = false
  
    local maxHealth = player:getMaxHealth()
    local currentHealth = player:getHealth()
  
    if currentHealth < maxHealth then
        local healthToAdd = math.min(maxHealth - currentHealth, math.floor((maxHealth * config.healhPercent) / 100))
        player:addHealth(healthToAdd)
        sendEffect = true
    end
  
    local maxMana = player:getMaxMana()
    local currentMana = player:getMana()
  
    if currentMana < maxMana then
        local manaToAdd = math.min(maxMana - currentMana, math.floor((maxMana * config.manaPercent) / 100))
        player:addMana(manaToAdd)
        sendEffect = true
    end
  
    if sendEffect then
        player:getPosition():sendMagicEffect(config.regenerationEffect)
    end
  
    if potionUsers[playerId] > 0 then
        potionUsers[playerId] = potionUsers[playerId] - config.ticks
        addEvent(potion, config.ticks, playerId)
        return
    end
  
    player:say("Potion deactivated!", TALKTYPE_MONSTER_SAY)
    potionUsers[playerId] = nil
end

local function buffAnimation(playerId, lastKnownDuration)
    local player = Player(playerId)
    if not player then
        return
    end
  
    if not potionUsers[playerId] then
        return
    end
  
    if potionUsers[playerId] > lastKnownDuration then
        return
    end
  
    player:getPosition():sendMagicEffect(config.buffActiveEffect)
    addEvent(buffAnimation, config.buffActiveEffectTicks, playerId, potionUsers[playerId])
end

local potionOfTheGods = Action()

function potionOfTheGods.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerId = player:getId()
    if potionUsers[playerId] then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Potion is still active.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF, player) -- shows only for this player
        return false
    end
  
    if player:getSoul() < config.soulAmount then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Insufficient soul.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF, player)
        return false
    end
  
    potionUsers[playerId] = config.duration * 1000
    player:addSoul(-config.soulAmount)
  
    if config.removeItem then
        item:remove(1)
    end

    buffAnimation(playerId, potionUsers[playerId])
    potion(playerId)
    player:say("Potion activated!", TALKTYPE_MONSTER_SAY)
    return true
end

potionOfTheGods:id(config.itemId)
potionOfTheGods:register()
follow the video/GIF above

Look what I added with animated text, the script is working well life and mana ok, thank you very much
 
Hi, good script, but in my otbr version 10.98 it doesn't work:
Lua:
Lua Script Error: [Test Interface]
data/actions/scripts/VIP/potek.lua
data/actions/scripts/VIP/potek.lua:75: attempt to call global 'Action' (a nil value)
stack traceback:
        [C]: in function 'Action'
        data/actions/scripts/VIP/potek.lua:75: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/VIP/potek.lua
 
Hi, good script, but in my otbr version 10.98 it doesn't work:
Lua:
Lua Script Error: [Test Interface]
data/actions/scripts/VIP/potek.lua
data/actions/scripts/VIP/potek.lua:75: attempt to call global 'Action' (a nil value)
stack traceback:
        [C]: in function 'Action'
        data/actions/scripts/VIP/potek.lua:75: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/VIP/potek.lua
did you read the title? it was revscript

data/scripts/filename.lua
 
Back
Top