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

temporary debuff

czouski

Banned User
Joined
Nov 2, 2024
Messages
166
Solutions
1
Reaction score
64
I want to create event for players and I want their stats to be the same then i tought is there way to make a debuff or such condition that would set all skills to certain level temporarily? or how can i achieve it without storing it all in storages?
 
or how can i achieve it without storing it all in storages?
You would need to create separate condition for each player to decrease/increase his skills/HP/MP/magic level to make them same level.
Skills/magic level are adjusted based on real player skills/magic level (without EQ/boosts).
HP/MP base values are not available in Lua, so condition will adjust value with EQ and boosts enabled.

NOT TESTED:
LUA:
-- config
local conditionTimeSeconds = 2 * 60
local HP = 1000
local MP = 1000
local magLevel = 30
local skills = {
	fist = 51,
	club = 52,
	sword = 53,
	axe = 54,
	distance = 55,
	shield = 56,
}

local eventConditionSubId = 123

function addEventStatsCondition(player)
	-- first try to remove, make sure it's not added twice
	removeEventStatsCondition(player)

	local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT)
	-- unique subid for condition, to make it does not interact with other attributes conditions
	condition:setParameter(CONDITION_PARAM_SUBID, eventConditionSubId)
	condition:setParameter(CONDITION_PARAM_TICKS, conditionTimeSeconds * 1000)

	-- HP change
	condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, HP - player:getMaxHealth())
	-- mana change
	condition:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTS, MP - player:getMaxMana())
	-- mlvl change
	condition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, magLevel - player:getBaseMagicLevel())
	-- change skills
	condition:setParameter(CONDITION_PARAM_SKILL_FIST, skills.fist - player:getSkillLevel(SKILL_FIST))
	condition:setParameter(CONDITION_PARAM_SKILL_CLUB, skills.club - player:getSkillLevel(SKILL_CLUB))
	condition:setParameter(CONDITION_PARAM_SKILL_SWORD, skills.sword - player:getSkillLevel(SKILL_SWORD))
	condition:setParameter(CONDITION_PARAM_SKILL_AXE, skills.axe - player:getSkillLevel(SKILL_AXE))
	condition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, skills.distance - player:getSkillLevel(SKILL_DISTANCE))
	condition:setParameter(CONDITION_PARAM_SKILL_SHIELD, skills.shield - player:getSkillLevel(SKILL_SHIELD))

	condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

	player:addCondition(condition)
end

function removeEventStatsCondition(player)
	player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, eventConditionSubId)
end
It's possible that after player:addCondition(condition) you should call condition:delete(). I did not test it/review code of conditions in C++.
There are possible scenarios:
  • script above will create new condition for each player and this condition will stay in RAM until server restart, so you should delete condition after it's applied to player (as I remember addCondition does copy of condition)
  • script above is fine, TFS does not copy conditions in addCondition and adding condition:delete() will crash TFS, when condition ends, as it will be removed from RAM, but still point to that RAM address in C++ of Player
 
LUA:
-- config
local conditionTimeSeconds = 2 * 60
local HP = 1000
local MP = 1000
local magLevel = 30
local skills = {
    fist = 10,
    club = 10,
    sword = 10,
    axe = 10,
    distance = 10,
    shield = 10,
}

local eventConditionSubId = 123

function addEventStatsCondition(player)
    -- first try to remove, make sure it's not added twice
    removeEventStatsCondition(player)

    local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT)
    -- unique subid for condition, to make it does not interact with other attributes conditions
    condition:setParameter(CONDITION_PARAM_SUBID, eventConditionSubId)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)

    -- HP change
    condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, HP - player:getMaxHealth())
    -- mana change
    condition:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTS, MP - player:getMaxMana())
    -- mlvl change
    condition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, magLevel - player:getBaseMagicLevel())
    -- change skills
    condition:setParameter(CONDITION_PARAM_SKILL_FIST, skills.fist - player:getSkillLevel(SKILL_FIST))
    condition:setParameter(CONDITION_PARAM_SKILL_CLUB, skills.club - player:getSkillLevel(SKILL_CLUB))
    condition:setParameter(CONDITION_PARAM_SKILL_SWORD, skills.sword - player:getSkillLevel(SKILL_SWORD))
    condition:setParameter(CONDITION_PARAM_SKILL_AXE, skills.axe - player:getSkillLevel(SKILL_AXE))
    condition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, skills.distance - player:getSkillLevel(SKILL_DISTANCE))
    condition:setParameter(CONDITION_PARAM_SKILL_SHIELD, skills.shield - player:getSkillLevel(SKILL_SHIELD))

    condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

    player:addCondition(condition)
end

function removeEventStatsCondition(player)
    player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, eventConditionSubId)
end

-- Register action
local mirrorAction = Action()

-- Define what happens when the item is used
function mirrorAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Retrieve the current storage value for key 130
    local storageKey = 130
    local currentValue = player:getStorageValue(storageKey)

    if currentValue == -1 or currentValue == 0 then
        -- If storage value is -1 or 0, set it to 1 and add event stats
        player:setStorageValue(storageKey, 1)
        addEventStatsCondition(player)
    elseif currentValue == 1 then
        -- If storage value is 1, set it to -1 and remove event stats
        player:setStorageValue(storageKey, -1)
        removeEventStatsCondition(player)
    end

    return true
end
mirrorAction:id(2560)

mirrorAction:register()

confirmed working for testing before I have the event stuff ready.
also including example of onUse where we track for example players event and allow them to change their event status so they can participate or not there can be extra code added which teleports player then into the waiting room :) i guess and rest will be handled by globalevents!
Post automatically merged:

gladiator.webp
 
Last edited:
Back
Top