• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

RevScripts [TFS1.4.2] XP Block - Monster Level

srunobantana

Active Member
Joined
Oct 24, 2021
Messages
55
Reaction score
34
By Google translation
My idea is that the player should not receive any XP if they do not meet the requirements defined in "MonsterRequirements" (exp_block.lua). This is already working properly when the player is alone.


However, when the player is in a party, the current system still allows everyone to gain XP. What I want is that if any member of the party fails to meet the requirements, then no one in the party should receive XP.


I also want the monster to drop no loot at all if it is killed by a player or a party that does not meet the "MonsterRequirements".


I would really appreciate if someone could help me with this or at least point me in the right direction to implement it properly, even if it’s just a guide on how to structure the logic within the scripts. I already have part of the system working, but I'm not sure how to apply this to party XP and loot behavior.

Code:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end

    local monsterName = source:getName()
    local requirements = MonsterRequirements[monsterName]
    
    if not requirements then
        return hasEventCallback(EVENT_CALLBACK_ONGAINEXPERIENCE) and EventCallback(EVENT_CALLBACK_ONGAINEXPERIENCE, self, source, exp, rawExp) or exp
    end

    if self:getLevel() < requirements.level then
        self:sendTextMessage(MESSAGE_STATUS_WARNING,
            string.format("Requisito: Level %d (seu: %d) para enfrentar %s.",
                         requirements.level, self:getLevel(), monsterName))
        return 0
    end

    if self:getRebirth() < requirements.rebirth then
        self:sendTextMessage(MESSAGE_STATUS_WARNING,
            string.format("Requisito: Rebirth %d (seu: %d) para enfrentar %s.",
                         requirements.rebirth, self:getRebirth(), monsterName))
        return 0
    end

    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    exp = exp * Game.getExperienceStage(self:getLevel())

    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)

        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end

    return hasEventCallback(EVENT_CALLBACK_ONGAINEXPERIENCE) and EventCallback(EVENT_CALLBACK_ONGAINEXPERIENCE, self, source, exp, rawExp) or exp
end

LUA:
MonsterRequirements = {
    ["Gang Member"] = {level = 50, rebirth = 0},
    ["Assassin"] = {level = 80, rebirth = 2},
}

local function printMonsterRequirements()
    print("\n=== MONSTER REQUIREMENTS ===")
    for monsterName, req in pairs(MonsterRequirements) do
        print(string.format("%s: Level %d, Rebirth %d", monsterName, req.level, req.rebirth))
    end
    print("==========================\n")
end

printMonsterRequirements()
 
Code:
-- scripts/monster_requirements.lua

local monsterReqEvent = CreatureEvent("MonsterRequirements")

function monsterReqEvent.onKill(creature, target)
    if not target:isMonster() then
        return true
    end

    local monsterName = target:getName()
    local requirements = MonsterRequirements[monsterName]
    if not requirements then
        return true
    end

    local killers = target:getDamageMap()
    for attacker, _ in pairs(killers) do
        local player = attacker:isPlayer() and attacker or attacker:getMaster()
        if player and player:isPlayer() then
            if player:getLevel() < requirements.level or player:getRebirth() < requirements.rebirth then
                -- Marca que este monstruo NO debe dar exp ni loot
                target:setStorageValue(99999, 1)
                break
            end
        end
    end
    return true
end

monsterReqEvent:register()

Code:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end

    local monsterName = source:getName()
    local requirements = MonsterRequirements[monsterName]

    -- Bloqueo por storage
    if source:getStorageValue(99999) == 1 then
        return 0
    end

    -- Lo demás igual que tienes...


Code:
local monsterLootBlock = CreatureEvent("MonsterLootBlock")

function monsterLootBlock.onDeath(creature, corpse)
    if creature:isMonster() and creature:getStorageValue(99999) == 1 then
        corpse:remove()
    end
    return true
end

monsterLootBlock:register()

Register in monster.xml example dragon.xml

monster:registerEvent("MonsterRequirements")
monster:registerEvent("MonsterLootBlock")
 
Back
Top