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

RevScripts reduce player damage

alcapone

Member
Joined
Jan 13, 2021
Messages
246
Reaction score
19
Lua:
local creatureEvent = CreatureEvent("creatureEventTest2")

function creatureEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  if not creature or not attacker or creature == attacker then
    return primaryDamage, primaryType, secondaryDamage, secondaryType
  end
 
                primaryDamage = primaryDamage + (primaryDamage  * 4 / 100)
                secondaryDamage = secondaryDamage + (secondaryDamage  * 4 / 100)
 
  
 
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

creatureEvent:type("healthchange")
creatureEvent:register()


the above script is increasing mob damage that's right.

I would like a script to the contract that will reduce all player damage to the monster by 4% for example
 
Solution
Must be registered on the monster itself
Lua:
local reduction = 4 -- %
local sources = {
    ORIGIN_SPELL,
    ORIGIN_MELEE,
    ORIGIN_RANGED,
    ORIGIN_CONDITION,
    ORIGIN_WAND, -- TFS 1.5
}

local creatureEvent = CreatureEvent("ReducePlayerDamage")
function creatureEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if attacker and attacker:isPlayer() then
        if table.contains(sources, origin) then
            primaryDamage = math.floor(primaryDamage * (1.0 - (reduction / 100)))

            if secondaryDamage > 0 then
                secondaryDamage = math.floor(secondaryDamage * (1.0 - (reduction / 100)))
            end

            if (primaryDamage == 0 and...
Lua:
local creatureEvent = CreatureEvent("player_vs_mob")

function creatureEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature:isMonster() or not attacker:isPlayer() or creature == attacker then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    primaryDamage = (primaryDamage - (primaryDamage * 4 / 100))
    secondaryDamage = (secondaryDamage - (secondaryDamage * 4 / 100))
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

creatureEvent:type("healthchange")
creatureEvent:register()
 
Lua:
local creatureEvent = CreatureEvent("player_vs_mob")

function creatureEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature:isMonster() or not attacker:isPlayer() or creature == attacker then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    primaryDamage = (primaryDamage - (primaryDamage * 4 / 100))
    secondaryDamage = (secondaryDamage - (secondaryDamage * 4 / 100))
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

creatureEvent:type("healthchange")
creatureEvent:register()
I tried it, I didn't notice a difference

obs: I registered the event
 
Last edited:
Must be registered on the monster itself
Lua:
local reduction = 4 -- %
local sources = {
    ORIGIN_SPELL,
    ORIGIN_MELEE,
    ORIGIN_RANGED,
    ORIGIN_CONDITION,
    ORIGIN_WAND, -- TFS 1.5
}

local creatureEvent = CreatureEvent("ReducePlayerDamage")
function creatureEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if attacker and attacker:isPlayer() then
        if table.contains(sources, origin) then
            primaryDamage = math.floor(primaryDamage * (1.0 - (reduction / 100)))

            if secondaryDamage > 0 then
                secondaryDamage = math.floor(secondaryDamage * (1.0 - (reduction / 100)))
            end

            if (primaryDamage == 0 and secondaryDamage == 0) then
                creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
creatureEvent:register()
 
Solution
Must be registered on the monster itself
Lua:
local reduction = 4 -- %
local sources = {
    ORIGIN_SPELL,
    ORIGIN_MELEE,
    ORIGIN_RANGED,
    ORIGIN_CONDITION,
    ORIGIN_WAND, -- TFS 1.5
}

local creatureEvent = CreatureEvent("ReducePlayerDamage")
function creatureEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if attacker and attacker:isPlayer() then
        if table.contains(sources, origin) then
            primaryDamage = math.floor(primaryDamage * (1.0 - (reduction / 100)))

            if secondaryDamage > 0 then
                secondaryDamage = math.floor(secondaryDamage * (1.0 - (reduction / 100)))
            end

            if (primaryDamage == 0 and secondaryDamage == 0) then
                creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
creatureEvent:register()
I tested it with no result and zero errors in the log I put print above the primary and secondary damage and did not perform the print with both spell and physical weapons
 
data/events/scripts/monster.lua

Lua:
function Monster:onSpawn(position, startup, artificial)

    self:registerEvent("ReducePlayerDamage")
    
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        return true
    end
end

make sure you have selected onSpawn to "1" in data/events/events.xml
 
Back
Top