• 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!

Lua Don't waste potions and runes on area (frompos topos)

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,492
Solutions
27
Reaction score
857
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi! I wonder if someone could help me with the following script. Using TFS 1.5 nekiro downgrade 8.60. I have seen this script to make a PVP Arena CreatureEvent - Pvp Arena TFS 1.x (https://otland.net/threads/pvp-arena-tfs-1-x.234688/), and I think that would be great if players just don't spend potions and runes inside it, so they can freely pvp for endless time.

The fastest possible way I thought is to add a frompos-topos to every rune and potion script that prevent item from dissapearing if the player is inside the area. Not sure if this is the best idea, I will test any attempt, I'll will reallly appreciate any attempt to do this.

Regards!
 
Last edited:
Solution
Alright, this is the base system. It will handle teleporting the players in and out, handle when they die, teleport players out when the server shuts down, and gives you a way to stop removal of items/exp.

data/global.lua - Anywhere in the file
Lua:
PVP_ARENA_PLAYERS = {}

for runes/potions replace all
Code:
item:remove(1)

with
Lua:
if not PVP_ARENA_PLAYERS[player:getName()] then
     item:remove(1)
end

data/events/scripts/player.lua add this right under:
Code:
function Player:onGainSkillTries(skill, tries)
Lua:
if PVP_ARENA_PLAYERS[self:getName()] then
        return 0
end

data/scripts -- Add it anywhere name it anything
Lua:
local config = {
-- TownID    Pos enter arena              pos exit arena
    [1] =...
Depends. If you can make sure they don't log out inside the area or stay in the area when the server shuts down you can just store the player in memory and decide it that way. It would be more efficient. Otherwise yeah just add something like:
Lua:
-- Add this in global.lua
function isInArea(pos, area)
    if pos.x >= area.min.x and pos.x <= area.max.x then
        if pos.y >= area.min.y and pos.y <= area.max.y then
            if pos.z >= area.min.z and pos.z <= area.max.z then
                return true
            end
        end
    end
return false
end

-- Add at top before onUse --
local area = {
    min = Position(1, 1, 1),
    max = Position(1, 1, 1)
}

-- Replace the item:remove(1) with this --
if isInArea(player:getPosition(), area) then
    item:remove(1)
end
 
Amazing, thanks @Itutorial !!
That was exactly what I needed
Depends. If you can make sure they don't log out inside the area or stay in the area when the server shuts down you can just store the player in memory and decide it that way. It would be more efficient. Otherwise yeah just add something like:
What is the difference on the efficiency of the both methods? I really would like to have the lightest scripts running on the server. Because optimized performance is something that really helps a lot, and players appreciate that. For this I can suggest some ideas...

When a player stands a teleport that make him access to the pvp arena, make the teleport check the hour, so if player try to enter after 5:50 a.m he will be kicked back with the message "arena is closed". This is considering that a server save must happen on 6:00 a.m. Also use a globalevent that checks if player is inside area exactly at 5:50 a.m, before the server save.

I'm surely open to more ideas, want to achieve the best possible result on this
Thanks a lot for the answer, regards!
Post automatically merged:

Also I forgot something very important, it is possible that the players don't gain skills inside the area? This might be abused as manasit place...
 
Yeah I would do something like this...
global.lua
Lua:
PVP_ARENA_PLAYERS = {}

Add this anywhere in data/scripts
Lua:
local teleportIn = Position(1, 1, 1) -- Set this
local teleportOut = Position(1, 1, 1) -- Set this

local globalPvPArena = GlobalEvent("Remove_Arena_Players")
function globalPvPArena.onShutdown()
    for i, v in pairs(PVP_ARENA_PLAYERS) do
        local player = Player(v)
        if player then
            player:teleportTo(teleportOut)
        end
    end
    return true
end
globalPvPArena:register()


local movementPvPArena = MoveEvent()
movementPvPArena:type("stepin")

function movementPvPArena.onStepIn(player, item, position, fromPosition)
    if not player then return true end
 
    if not PVP_ARENA_PLAYERS[player:getName()] then
        player:teleportTo(teleportIn)
        teleportIn:sendMagicEffect(CONST_ME_TELEPORT)
        PVP_ARENA_PLAYERS[player:getName()] = player:getName()
    else
        player:teleportTo(teleportOut)
        teleportOut:sendMagicEffect(CONST_ME_TELEPORT)
        PVP_ARENA_PLAYERS[player:getName()] = nil
    end
    return true
end

movementPvPArena:id(1111) -- Set this
movementPvPArena:actionid(1111) -- Set this
movementPvPArena:register()

in potions/runes
Lua:
if not PVP_ARENA_PLAYERS[player:getName()] then
       item:remove(1)
end

in data/events/scripts/player.lua
Lua:
function Player:onGainSkillTries(skill, tries)
    if PVP_ARENA_PLAYERS[self:getName()] then
        return 0
    end

    if APPLY_SKILL_MULTIPLIER == false then
        return hasEventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES) and EventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES, self, skill, tries) or tries
    end

    if skill == SKILL_MAGLEVEL then
        tries = tries * configManager.getNumber(configKeys.RATE_MAGIC)
        return hasEventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES) and EventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES, self, skill, tries) or tries
    end
    tries = tries * configManager.getNumber(configKeys.RATE_SKILL)
    return hasEventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES) and EventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES, self, skill, tries) or tries
end
 
Last edited:
@Itutorial I started to read the script, I have some doubts about it. What would happen if the player gets out of the arena by using a teleport? Because if no one is on the arena probably the player will never be able to exit. Also, it doesn't check any area, is necessary to add something else here? PVP_ARENA_PLAYERS = {}

Another thing, potions.lua finish with
Lua:
    if not configManager.getBoolean(configKeys.REMOVE_POTION_CHARGES) then
        return true
    end

    item:remove(1)
    return true
end

I have to replace item:remove(1) return true end, with this right?
Lua:
if not PVP_ARENA_PLAYERS[player:getName()] then
       item:remove(1)
end

Or I have to place it just before item:remove(1)? Just wanted to check this few things before merging the script.

***** Another possible question is, what will happen if player kills himself by using a field? Also I don't see any onHealthChange event, hows the dying inside arena managed?

~ I need to request a little thing more 🤭

My server has 2 main cities, is there a chance to force a player from hometown (1) enters to position (1) and players from hometown (2) enter to position (2)? Also, there's a possibility than an exit teleport, where you just step in (inside the arena) makes player get back to hometown position and make he return to thier normal conditions?

I prepared a little map for the arena, so you can make an idea of it :)
 

Attachments

Last edited:
You didn’t really request a whole system here lol. You just asked about ways to do it. I gave you a pretty decent base to go off of.

If you want to request a full system you should make a list of what you are needing the code to do so I am not just creating random code wasting my time helping you.

So go ahead and make a list and I’ll go from there.
 
For example

1) Teleport that places players in PVP arena
- Teleport is based of townID
- Different locations based on townID when they exit.
- Randomize where they teleport inside arena?

2) Inside the arena players don’t use supplies (runes,potions)

3) inside the arena players do not gain skill levels

4) When players “die” in the arena
- teleport outside?
- teleport to random enter position?
- if they teleport outside remove supply remove block and let them gain skill?

5) script to remove players from arena before server shuts down

You should have the arena as no logout unless they lose anything when they die (blessings, whatever) if you don’t want to use nologout tiles then I will have to make a code that uses the database when the server starts up to remove players from the arena.

Players that are in the arena is stored in memory. So, whenever the server shuts down it will make them able to lose items and gain exp again.

As for the previous code questions.

You should only replace
Lua:
item:remove(1)

With the
Lua:
if PVP_ARENA_PLAYERS[player:getName()] then
     item:remove(1)
end

Do not replace any (return trues, ends or anything else)

And no the other code doesn’t handle players dying in the arena at all. They will remain not using items and not gaining skill if they are teleported outside the arena.
 
@Itutorial I totally understand your reply, I thought that this would be more simple just by setting a few things.
How you describe the whole system in the last post is exactly how I imagined it. For example, I was thinking on covering point 1) by using a script similar to this adventurer stone:


But I won't add more stuff, how you explained it is exactly how it should be. So in resume:

1) Teleport that places players in PVP arena
- Teleport is based of townID
YES, it should have 2 avaible towns that leads to the two different starting points of the arena, one for city 1, one for city 2.

- Different locations based on townID when they exit.
YES

- Randomize where they teleport inside arena?
Would be a good implementation, based on the map I did this shouldn't happen, because the exit teleport are a side from the players starting position (when they enter). So you decide, I can test both cases and adapt the map to it in case of.

2) Inside the arena players don’t use supplies (runes,potions)
Yes exactly, this is the principal thing that must work, so players will be able to PVP with infinite resources on this area

3) inside the arena players do not gain skill levels
Yes, the players shouldn't be able to take adventage from this area in any way. This is just for having fun doing PVP.

4) When players “die” in the arena
- teleport outside?
Yes

- teleport to random enter position?
No, players should return to temple position or to an sqm that is nearby to arena entrance. The important thing is, that if player enters from town (1), they return to town (1), and if they enter from town (2), they return to town (2).

- if they teleport outside remove supply remove block and let them gain skill?
Yes! This is very important, so players will return to their normal journey on the server. This will be only having fun doing PVP.

5) script to remove players from arena before server shuts down
Yes! As long this don't affect server perfomance or cause any bug to players, surely this will be great!! I guess that the logic of the system is pretty explained with all this answers.

Itutorial said:
You should have the arena as no logout unless they lose anything when they die (blessings, whatever) if you don’t want to use nologout tiles then I will have to make a code that uses the database when the server starts up to remove players from the arena.

I understand, is very important that players don't loose bless, aols, etc. when they die inside the arena. I am very beginner on .lua, so this things are totally on your decision, I can only give the idea of how everything should work but I have no skills to traduce it on .lua scripting.

I have to thank you a lot! Guess I have make you spend some unnecessary time, it's just that the 50% of times I request I use other scripts to adapt the whole system I have on mind; this, to don't abuse and ask a whole system like it's done in this case.

Again, I appreciate your help! Anything just hit me with a post or pm, i'll be answering as soon I get in the PC
Regards!! :)
Post automatically merged:

PS. If you wish to add any global score parameter, for the kills of each city, or any other system that could make the system more fun, do whatever you consider a good implementation to this. Now it's your system, i'll be in charge of testing it and giving all the feedback that is necessary :D
 
Last edited:
Alright, this is the base system. It will handle teleporting the players in and out, handle when they die, teleport players out when the server shuts down, and gives you a way to stop removal of items/exp.

data/global.lua - Anywhere in the file
Lua:
PVP_ARENA_PLAYERS = {}

for runes/potions replace all
Code:
item:remove(1)

with
Lua:
if not PVP_ARENA_PLAYERS[player:getName()] then
     item:remove(1)
end

data/events/scripts/player.lua add this right under:
Code:
function Player:onGainSkillTries(skill, tries)
Lua:
if PVP_ARENA_PLAYERS[self:getName()] then
        return 0
end

data/scripts -- Add it anywhere name it anything
Lua:
local config = {
-- TownID    Pos enter arena              pos exit arena
    [1] = {enterPos = Position(1, 1, 1), exitPos = Position(1, 1, 1)},
    [2] = {enterPos = Position(1, 1, 1), exitPos = Position(1, 1, 1)}
}

-- Globalevent used to teleport players out of arena when server shuts down --
local globaleventPvPArena = GlobalEvent("PvP_Arena_Global")
function globaleventPvPArena.onShutdown()
    for i, v in pairs(PVP_ARENA_PLAYERS) do
        local player = Player(v)
        if player then
            local town = config[player:getTown():getId()]
            if town then
                player:teleportTo(town.exitPos)
            end
        end
    end
    return true
end
globaleventPvPArena:register()

-- Prepare death. Handles players dying in arena. --
local creatureeventPvPArena = CreatureEvent("PvP_Arena_PrepareDeath")
function creatureeventPvPArena.onPrepareDeath(creature, killer)
    if not creature:isPlayer() then return true end
 
    if PVP_ARENA_PLAYERS[creature:getName()] then
        local town = config[creature:getTown():getId()]
        if town then
            creature:teleportTo(town.exitPos)
            creature:addHealth(creature:getMaxHealth())
            creature:addMana(creature:getMaxMana())
            PVP_ARENA_PLAYERS[creature:getName()] = nil
            return false
        end
    end
    return true
end
creatureeventPvPArena:register()

-- Moveevent used to teleport players in and out of the arena --
local movementPvPArena = MoveEvent()
movementPvPArena:type("stepin")

function movementPvPArena.onStepIn(player, item, position, fromPosition)
    if not player then return true end
 
    if not PVP_ARENA_PLAYERS[player:getName()] then
        local town = config[player:getTown():getId()]
        if town then
            player:teleportTo(town.enterPos)
            town.enterPos:sendMagicEffect(CONST_ME_TELEPORT)
            PVP_ARENA_PLAYERS[player:getName()] = player:getName()
        end
    else
        local town = config[player:getTown():getId()]
        if town then
            player:teleportTo(town.exitPos)
            town.exitPos:sendMagicEffect(CONST_ME_TELEPORT)
            PVP_ARENA_PLAYERS[player:getName()] = nil
        end
    end
    return true
end

movementPvPArena:id(1111) -- Set this
movementPvPArena:aid(1111) -- Set this
movementPvPArena:register()

Make sure the tiles in the pvp arena are also no logout. If the server crashes and players are in the event it will reset them so they will use items,runes, and gain experience again. It will also follow the default way death is handled which is teleport the player back to their temple positions for their town.

Also make sure there is a portal to leave the arena somewhere.
 
Last edited:
Solution
Looking great :D

I have a little question before merging, is this:
Itutorial said:
Also make sure there is a portal to leave the arena somewhere.

This portal to exit, must have the registered aid and is going to be handled as a moveevent? Or I have to place xyz coordinates on it? I'm just not sure how the server will recognize if a player is no longer part of PVP_ARENA_PLAYERS when they enter to an exit teleport.

Also, if I place no-pvp tiles they will work fine? Or this must have only no-logout tiles? Sorry for bothering with theese questions, just prefered to ask before making something wrong. I will answer again with local server test results, going to try a few things with multi-clients before adding to the main server.

It's kinda late on Chile gotta sleep a few hours :p (4 a.m here). I'll keep you posted tomorrow, saying this before keeping you waiting for results.

Thanks for everything, brb!
 
Last edited:
Looking great :D

I have a little question before merging, is this:


This portal to exit, must have the registered aid and is going to be handled as a moveevent? Or I have to place xyz coordinates on it? I'm just not sure how the server will recognize if a player is no longer part of PVP_ARENA_PLAYERS when they enter to an exit teleport.

Also, if I place no-pvp tiles they will work fine? Or this must have only no-logout tiles? Sorry for bothering with theese questions, just prefered to ask before making something wrong. I will answer again with local server test results, going to try a few things with multi-clients before adding to the main server.

It's kinda late on Chile gotta sleep a few hours :p (4 a.m here).
I'll keep you posted tomorrow, saying this before keeping you waiting for results.

Thanks for everything, brb!
NoPvP and Nologout tiles

Yes both portals just need the same AID and its good to go. No need for xyz pos.
 
@Itutorial Tested and for the moment is working perfectly! There's only one thing. It creates empty vials when I use potions inside the arena, any chance to prevent that? Here's my potions.lua

Lua:
local berserk = Condition(CONDITION_ATTRIBUTES)
berserk:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
berserk:setParameter(CONDITION_PARAM_SKILL_MELEE, 5)
berserk:setParameter(CONDITION_PARAM_SKILL_SHIELD, -10)
berserk:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local mastermind = Condition(CONDITION_ATTRIBUTES)
mastermind:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
mastermind:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 3)
mastermind:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local bullseye = Condition(CONDITION_ATTRIBUTES)
bullseye:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
bullseye:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 5)
bullseye:setParameter(CONDITION_PARAM_SKILL_SHIELD, -10)
bullseye:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local potions = {
    [6558] = { -- concentrated demonic blood
        transform = {7588, 7589},
        effect = CONST_ME_DRAWBLOOD
    },
    [7439] = { -- berserk potion
        condition = berserk,
        vocations = {4, 8},
        effect = CONST_ME_MAGIC_RED,
        description = "Only knights may drink this potion.",
        text = "You feel stronger."
    },
    [7440] = { -- mastermind potion
        condition = mastermind,
        vocations = {1, 2, 5, 6},
        effect = CONST_ME_MAGIC_BLUE,
        description = "Only sorcerers and druids may drink this potion.",
        text = "You feel smarter."
        },
    [7443] = { -- bullseye potion
        condition = bullseye,
        vocations = {3, 7},
        effect = CONST_ME_MAGIC_GREEN,
        description = "Only paladins may drink this potion.",
        text = "You feel more accurate."
    },
    [7588] = { -- strong health potion
        health = {250, 350},
        vocations = {3, 4, 7, 8},
        level = 50,
        flask = 7634,
        description = "Only knights and paladins of level 50 or above may drink this fluid."
    },
    [7589] = { -- strong mana potion
        mana = {115, 185},
        vocations = {1, 2, 3, 4, 5, 6, 7, 8},
        level = 50,
        flask = 7634,
        description = "Only sorcerers, druids and paladins of level 50 or above may drink this fluid."
    },
    [7590] = { -- great mana potion
        mana = {150, 250},
        vocations = {1, 2, 3, 5, 6, 7},
        level = 80,
        flask = 7635,
        description = "Only druids and sorcerers of level 80 or above may drink this fluid."
    },
    [7591] = { -- great health potion
        health = {425, 575},
        vocations = {4, 8},
        level = 80,
        flask = 7635,
        description = "Only knights of level 80 or above may drink this fluid."
    },
    [7618] = { -- health potion
        health = {125, 175},
        flask = 7636
    },
    [7620] = { -- mana potion
        mana = {75, 125},
        flask = 7636
    },
    [8472] = { -- great spirit potion
        health = {250, 350},
        mana = {100, 200},
        vocations = {3, 7},
        level = 80,
        flask = 7635,
        description = "Only paladins of level 80 or above may drink this fluid."
    },
    [8473] = { -- ultimate health potion
        health = {650, 850},
        vocations = {4, 8},
        level = 130,
        flask = 7635,
        description = "Only knights of level 130 or above may drink this fluid."
    },
    [8474] = { -- antidote potion
        antidote = true,
        flask = 7636,
    },
    [8704] = { -- small health potion
        health = {60, 90},
        flask = 7636,
    },
    [12784] = { -- ultimate mana potion
        mana = {425, 575},
        vocations = {1, 2, 5, 6},
        level = 130,
        flask = 7635,
        description = "Only druids and sorcerers of level 130 or above may drink this fluid."
    },
    [12786] = { -- ultimate spirit potion
        health = {420, 580},
        mana = {200, 350},
        vocations = {3, 7},
        level = 130,
        flask = 7635,
        description = "Only paladins of level 130 or above may drink this fluid."
    },
    [12785] = { -- supreme health potion
        health = {875, 1125},
        vocations = {4, 8},
        level = 200,
        flask = 7635,
        description = "Only knights of level 200 or above may drink this fluid."
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if type(target) == "userdata" and not target:isPlayer() then
        return false
    end

    local potion = potions[item:getId()]
    if potion.level and player:getLevel() < potion.level or potion.vocations and not table.contains(potion.vocations, player:getVocation():getId()) then
        player:say(potion.description, TALKTYPE_MONSTER_SAY)
        return true
    end

    if potion.condition then
        player:addCondition(potion.condition)
        player:say(potion.text, TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(potion.effect)
    elseif potion.transform then
        local reward = potion.transform[math.random(#potion.transform)]
        if fromPosition.x == CONTAINER_POSITION then
            local targetContainer = Container(item:getParent().uid)
            targetContainer:addItem(reward, 1)
        else
            Game.createItem(reward, 1, fromPosition)
        end
        item:getPosition():sendMagicEffect(potion.effect)
        item:remove(1)
        return true
    else
        if potion.health then
            doTargetCombat(0, target, COMBAT_HEALING, potion.health[1], potion.health[2])
        end

        if potion.mana then
            doTargetCombat(0, target, COMBAT_MANADRAIN, potion.mana[1], potion.mana[2])
        end

        if potion.antidote then
            target:removeCondition(CONDITION_POISON)
        end

        ----player:addAchievementProgress("Potion Addict", 100000)
        player:addItem(potion.flask)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end

    if not configManager.getBoolean(configKeys.REMOVE_POTION_CHARGES) then
        return true
    end

    if not PVP_ARENA_PLAYERS[player:getName()] then
     item:remove(1)
    end
    return true
end

Thanks in advance! :D
Post automatically merged:

Also not sure how to prevent rune waste inside the arena, here's a rune sample
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYHIT)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGYBALL)
combat:setParameter(COMBAT_PARAM_CREATEITEM, ITEM_ENERGYFIELD_PVP)
combat:setArea(createCombatArea(AREA_SQUARE1X1))

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
 
Hit me up with pm's if you need help with specific codes.

Replace that with this
Lua:
local berserk = Condition(CONDITION_ATTRIBUTES)
berserk:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
berserk:setParameter(CONDITION_PARAM_SKILL_MELEE, 5)
berserk:setParameter(CONDITION_PARAM_SKILL_SHIELD, -10)
berserk:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local mastermind = Condition(CONDITION_ATTRIBUTES)
mastermind:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
mastermind:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 3)
mastermind:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local bullseye = Condition(CONDITION_ATTRIBUTES)
bullseye:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
bullseye:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 5)
bullseye:setParameter(CONDITION_PARAM_SKILL_SHIELD, -10)
bullseye:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local potions = {
    [6558] = { -- concentrated demonic blood
        transform = {7588, 7589},
        effect = CONST_ME_DRAWBLOOD
    },
    [7439] = { -- berserk potion
        condition = berserk,
        vocations = {4, 8},
        effect = CONST_ME_MAGIC_RED,
        description = "Only knights may drink this potion.",
        text = "You feel stronger."
    },
    [7440] = { -- mastermind potion
        condition = mastermind,
        vocations = {1, 2, 5, 6},
        effect = CONST_ME_MAGIC_BLUE,
        description = "Only sorcerers and druids may drink this potion.",
        text = "You feel smarter."
        },
    [7443] = { -- bullseye potion
        condition = bullseye,
        vocations = {3, 7},
        effect = CONST_ME_MAGIC_GREEN,
        description = "Only paladins may drink this potion.",
        text = "You feel more accurate."
    },
    [7588] = { -- strong health potion
        health = {250, 350},
        vocations = {3, 4, 7, 8},
        level = 50,
        flask = 7634,
        description = "Only knights and paladins of level 50 or above may drink this fluid."
    },
    [7589] = { -- strong mana potion
        mana = {115, 185},
        vocations = {1, 2, 3, 4, 5, 6, 7, 8},
        level = 50,
        flask = 7634,
        description = "Only sorcerers, druids and paladins of level 50 or above may drink this fluid."
    },
    [7590] = { -- great mana potion
        mana = {150, 250},
        vocations = {1, 2, 3, 5, 6, 7},
        level = 80,
        flask = 7635,
        description = "Only druids and sorcerers of level 80 or above may drink this fluid."
    },
    [7591] = { -- great health potion
        health = {425, 575},
        vocations = {4, 8},
        level = 80,
        flask = 7635,
        description = "Only knights of level 80 or above may drink this fluid."
    },
    [7618] = { -- health potion
        health = {125, 175},
        flask = 7636
    },
    [7620] = { -- mana potion
        mana = {75, 125},
        flask = 7636
    },
    [8472] = { -- great spirit potion
        health = {250, 350},
        mana = {100, 200},
        vocations = {3, 7},
        level = 80,
        flask = 7635,
        description = "Only paladins of level 80 or above may drink this fluid."
    },
    [8473] = { -- ultimate health potion
        health = {650, 850},
        vocations = {4, 8},
        level = 130,
        flask = 7635,
        description = "Only knights of level 130 or above may drink this fluid."
    },
    [8474] = { -- antidote potion
        antidote = true,
        flask = 7636,
    },
    [8704] = { -- small health potion
        health = {60, 90},
        flask = 7636,
    },
    [12784] = { -- ultimate mana potion
        mana = {425, 575},
        vocations = {1, 2, 5, 6},
        level = 130,
        flask = 7635,
        description = "Only druids and sorcerers of level 130 or above may drink this fluid."
    },
    [12786] = { -- ultimate spirit potion
        health = {420, 580},
        mana = {200, 350},
        vocations = {3, 7},
        level = 130,
        flask = 7635,
        description = "Only paladins of level 130 or above may drink this fluid."
    },
    [12785] = { -- supreme health potion
        health = {875, 1125},
        vocations = {4, 8},
        level = 200,
        flask = 7635,
        description = "Only knights of level 200 or above may drink this fluid."
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if type(target) == "userdata" and not target:isPlayer() then
        return false
    end

    local potion = potions[item:getId()]
    if potion.level and player:getLevel() < potion.level or potion.vocations and not table.contains(potion.vocations, player:getVocation():getId()) then
        player:say(potion.description, TALKTYPE_MONSTER_SAY)
        return true
    end
  
    local removeItem = true
    if not PVP_ARENA_PLAYERS[player:getName()] then
        removeItem = false
    end

    if potion.condition then
        player:addCondition(potion.condition)
        player:say(potion.text, TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(potion.effect)
    elseif potion.transform then
        local reward = potion.transform[math.random(#potion.transform)]
        if fromPosition.x == CONTAINER_POSITION then
            local targetContainer = Container(item:getParent().uid)
            targetContainer:addItem(reward, 1)
        else
            Game.createItem(reward, 1, fromPosition)
        end
        item:getPosition():sendMagicEffect(potion.effect)
        item:remove(1)
        return true
    else
        if potion.health then
            doTargetCombat(0, target, COMBAT_HEALING, potion.health[1], potion.health[2])
        end

        if potion.mana then
            doTargetCombat(0, target, COMBAT_MANADRAIN, potion.mana[1], potion.mana[2])
        end

        if potion.antidote then
            target:removeCondition(CONDITION_POISON)
        end

        ----player:addAchievementProgress("Potion Addict", 100000)
        if removeItem then
            player:addItem(potion.flask)
        end
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end

    if not configManager.getBoolean(configKeys.REMOVE_POTION_CHARGES) then
        return true
    end

    if removeItem then
     item:remove(1)
    end
    return true
end
 
For those who's intrested, here's the finished potion script.
Lua:
local berserk = Condition(CONDITION_ATTRIBUTES)
berserk:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
berserk:setParameter(CONDITION_PARAM_SKILL_MELEE, 5)
berserk:setParameter(CONDITION_PARAM_SKILL_SHIELD, -10)
berserk:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local mastermind = Condition(CONDITION_ATTRIBUTES)
mastermind:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
mastermind:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 3)
mastermind:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local bullseye = Condition(CONDITION_ATTRIBUTES)
bullseye:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
bullseye:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 5)
bullseye:setParameter(CONDITION_PARAM_SKILL_SHIELD, -10)
bullseye:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local potions = {
    [6558] = { -- concentrated demonic blood
        transform = {7588, 7589},
        effect = CONST_ME_DRAWBLOOD
    },
    [7439] = { -- berserk potion
        condition = berserk,
        vocations = {4, 8},
        effect = CONST_ME_MAGIC_RED,
        description = "Only knights may drink this potion.",
        text = "You feel stronger."
    },
    [7440] = { -- mastermind potion
        condition = mastermind,
        vocations = {1, 2, 5, 6},
        effect = CONST_ME_MAGIC_BLUE,
        description = "Only sorcerers and druids may drink this potion.",
        text = "You feel smarter."
        },
    [7443] = { -- bullseye potion
        condition = bullseye,
        vocations = {3, 7},
        effect = CONST_ME_MAGIC_GREEN,
        description = "Only paladins may drink this potion.",
        text = "You feel more accurate."
    },
    [7588] = { -- strong health potion
        health = {250, 350},
        vocations = {3, 4, 7, 8},
        level = 50,
        flask = 7634,
        description = "Only knights and paladins of level 50 or above may drink this fluid."
    },
    [7589] = { -- strong mana potion
        mana = {115, 185},
        vocations = {1, 2, 3, 4, 5, 6, 7, 8},
        level = 50,
        flask = 7634,
        description = "Only sorcerers, druids and paladins of level 50 or above may drink this fluid."
    },
    [7590] = { -- great mana potion
        mana = {150, 250},
        vocations = {1, 2, 3, 5, 6, 7},
        level = 80,
        flask = 7635,
        description = "Only druids and sorcerers of level 80 or above may drink this fluid."
    },
    [7591] = { -- great health potion
        health = {425, 575},
        vocations = {4, 8},
        level = 80,
        flask = 7635,
        description = "Only knights of level 80 or above may drink this fluid."
    },
    [7618] = { -- health potion
        health = {125, 175},
        flask = 7636
    },
    [7620] = { -- mana potion
        mana = {75, 125},
        flask = 7636
    },
    [8472] = { -- great spirit potion
        health = {250, 350},
        mana = {100, 200},
        vocations = {3, 7},
        level = 80,
        flask = 7635,
        description = "Only paladins of level 80 or above may drink this fluid."
    },
    [8473] = { -- ultimate health potion
        health = {650, 850},
        vocations = {4, 8},
        level = 130,
        flask = 7635,
        description = "Only knights of level 130 or above may drink this fluid."
    },
    [8474] = { -- antidote potion
        antidote = true,
        flask = 7636,
    },
    [8704] = { -- small health potion
        health = {60, 90},
        flask = 7636,
    },
    [12784] = { -- ultimate mana potion
        mana = {425, 575},
        vocations = {1, 2, 5, 6},
        level = 130,
        flask = 7635,
        description = "Only druids and sorcerers of level 130 or above may drink this fluid."
    },
    [12786] = { -- ultimate spirit potion
        health = {420, 580},
        mana = {200, 350},
        vocations = {3, 7},
        level = 130,
        flask = 7635,
        description = "Only paladins of level 130 or above may drink this fluid."
    },
    [12785] = { -- supreme health potion
        health = {875, 1125},
        vocations = {4, 8},
        level = 200,
        flask = 7635,
        description = "Only knights of level 200 or above may drink this fluid."
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if type(target) == "userdata" and not target:isPlayer() then
        return false
    end

    local potion = potions[item:getId()]
    if potion.level and player:getLevel() < potion.level or potion.vocations and not table.contains(potion.vocations, player:getVocation():getId()) then
        player:say(potion.description, TALKTYPE_MONSTER_SAY)
        return true
    end
 
    if potion.condition then
        player:addCondition(potion.condition)
        player:say(potion.text, TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(potion.effect)
    elseif potion.transform then
        local reward = potion.transform[math.random(#potion.transform)]
        if fromPosition.x == CONTAINER_POSITION then
            local targetContainer = Container(item:getParent().uid)
            targetContainer:addItem(reward, 1)
        else
            Game.createItem(reward, 1, fromPosition)
        end
        item:getPosition():sendMagicEffect(potion.effect)
        item:remove(1)
        return true
    else
        if potion.health then
            doTargetCombat(0, target, COMBAT_HEALING, potion.health[1], potion.health[2])
        end

        if potion.mana then
            doTargetCombat(0, target, COMBAT_MANADRAIN, potion.mana[1], potion.mana[2])
        end

        if potion.antidote then
            target:removeCondition(CONDITION_POISON)
        end

        ----player:addAchievementProgress("Potion Addict", 100000)
        if not player:isPvPArenaPlayer() then
            player:addItem(potion.flask)
        end
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end

    if not configManager.getBoolean(configKeys.REMOVE_POTION_CHARGES) then
        return true
    end

    if not player:isPvPArenaPlayer() then
        item:remove(1)
    end
    return true
end

We had some pm's with @Itutorial and he did the whole system again via C++. I'm infinitely gratefull for the system, because it is working so well :D I will share it in a new post, with the map and the configuration that is needed.

This thread is now solved! Infinite thanks, the result is so good man, this is truly amazing ^^
Regards!
 
Back
Top