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

i am trying to put the creaturescript or revscript TFS 1.5 8.0

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,337
Solutions
71
Reaction score
697
Location
ლ(ಠ益ಠლ)
Look, I made a script, but I know it doesn't work. Does anyone know if it's possible to put a script via CreatureScript, for example, on an item when using it and gain a magic damage bonus in percentage?

code for example
Lua:
function onCreatureAttack(creature, target, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    local attackerPlayer = creature:getPlayer()

    for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        if attackerPlayer:isItemAbilityEnabled(slot) then
            local item = attackerPlayer:getInventoryItem(slot)
            if item then
                local boostPercent = item:getBoostPercent(primaryType)
                if boostPercent ~= 0 then
                    primaryDamage = primaryDamage + math.round(primaryDamage * (boostPercent / 100))
                end
            end
        end
    end

    if primaryDamage <= 0 then
        primaryDamage = 0
        secondaryType = BLOCK_ARMOR
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Does anyone have any ideas about this? I urgently need my server, because I'm almost finishing my project. It was the last detail, please. I already tried using magicpointsPercepent and BossPercent, but neither worked

Lua:
local creatureEvent = CreatureEvent("MagicDamageBoost")

function creatureEvent.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player:isPlayer() then
        return false
    end

    local boostPercent = 0
    local itemID = item:getId()

    local itemNode = ItemType(itemID)
    if itemNode:isStackable() or itemNode:isMultiType() then
        itemNode = ItemType(itemID, item:getType())
    end

    if itemNode then
        boostPercent = itemNode:getMagicDamagePercent()
    end

    if boostPercent > 0 then
        local magicDamageBoost = player:getBaseMagicDamage() * boostPercent / 100
        player:setBaseMagicDamage(player:getBaseMagicDamage() + magicDamageBoost)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel an increase in your magical power.")
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        item:remove(1)
    else
        player:sendCancelMessage("This item doesn't provide any magical damage boost.")
    end

    return true
end

creatureEvent:register()



can be creaturescript or Revscript.. Thank you
 
Last edited:
Can do something similar to this damage buff potions I made.


Just change the function damageCalculator to check for the items the player is wearing.

Lua:
local buff_items = {
    --[itemid] = {damageType, damagePercentage}
    [1111] = {damageType = COMBAT_PHYSICALDAMAGE, damagePercentage = 0.5}, -- 50% extra damage
    [2222] = {damageType = COMBAT_ENERGYDAMAGE,   damagePercentage = 1}, -- 100% extra damage
    [3333] = {damageType = COMBAT_EARTHDAMAGE,    damagePercentage = 1},
    [4444] = {damageType = COMBAT_FIREDAMAGE,     damagePercentage = 1},
    [5555] = {damageType = COMBAT_ICEDAMAGE,      damagePercentage = 1},
    [6666] = {damageType = COMBAT_HOLYDAMAGE,     damagePercentage = 1},
    [7777] = {damageType = COMBAT_DEATHDAMAGE,    damagePercentage = 1},
}

local function damageCalculator(primaryDamage, primaryType, secondaryDamage, secondaryType, playerid)
    local player = Player(playerid)
   
    for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        local slotItem = player:getSlotItem(slot)
        if slotItem then
            local slotItemId = slotItem:getId()
            local index = buff_items[slotItemId]
            if index then
                if index.damageType == primaryType then
                    primaryDamage = primaryDamage * (index.damagePercentage + 1)
                end
                if index.damageType == secondaryType then
                    secondaryDamage = secondaryDamage * (index.damagePercentage + 1)
                end
            end
        end
    end
   
    return primaryDamage, secondaryDamage
end
 
Last edited:
It is possible to add all elements of damage when using an item, dealing damage from all elements simultaneously instead of one element at a time?

correct?
[8888] = {damageType = COMBAT_ALLDAMAGE, damagePercentage = 1.5}, -- 150% extra damage for all elements

where i can add in the folder? data/script or data/creaturescript?
 
Last edited:
It is possible to add all elements of damage when using an item, dealing damage from all elements simultaneously instead of one element at a time?

correct?


where i can add in the folder? data/script or data/creaturescript?
If using the same style as the buff potion, data/scripts

And yes, the code can be modified to trigger on all elements.

Lua:
local COMBAT_ELEMENTAL = 10000
local COMBAT_ALL = 10001

local elementalDamageTypes = {
    COMBAT_ENERGYDAMAGE,
    COMBAT_EARTHDAMAGE,
    COMBAT_FIREDAMAGE,
    COMBAT_ICEDAMAGE,
    COMBAT_HOLYDAMAGE,
    COMBAT_DEATHDAMAGE
}

local buff_items = {
    --[itemid] = {damageType, damagePercentage}
    [1111] = {damageType = COMBAT_PHYSICALDAMAGE, damagePercentage = 0.5}, -- 50% extra damage
    [2222] = {damageType = COMBAT_ENERGYDAMAGE,   damagePercentage = 1}, -- 100% extra damage
    [3333] = {damageType = COMBAT_EARTHDAMAGE,    damagePercentage = 1},
    [4444] = {damageType = COMBAT_FIREDAMAGE,     damagePercentage = 1},
    [5555] = {damageType = COMBAT_ICEDAMAGE,      damagePercentage = 1},
    [6666] = {damageType = COMBAT_HOLYDAMAGE,     damagePercentage = 1},
    [7777] = {damageType = COMBAT_DEATHDAMAGE,    damagePercentage = 1},
    [8888] = {damageType = COMBAT_ELEMENTAL,      damagePercentage = 1}, -- elemental types
    [9999] = {damageType = COMBAT_ALL,            damagePercentage = 1}  -- all damage types
}



local function damageCalculator(primaryDamage, primaryType, secondaryDamage, secondaryType, playerid)
    local player = Player(playerid)
 
    for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        local slotItem = player:getSlotItem(slot)
        if slotItem then
            local slotItemId = slotItem:getId()
            local index = buff_items[slotItemId]
            if index then
                local primaryIncrease = false
                local secondaryIncrease = false
             
                -- primary damage checks
                if index.damageType == COMBAT_ALL and (primaryType == COMBAT_PHYSICALDAMAGE or table.contains(elementalDamageTypes, primaryType)) then
                    primaryIncrease = true
                end
                if index.damageType == COMBAT_ELEMENTAL and table.contains(elementalDamageTypes, primaryType) then
                    primaryIncrease = true
                end
                if index.damageType == primaryType then
                    primaryIncrease = true
                end
             
                -- secondary damage checks
                if index.damageType == COMBAT_ALL and (secondaryType == COMBAT_PHYSICALDAMAGE or table.contains(elementalDamageTypes, secondaryType)) then
                    secondaryIncrease = true
                end
                if index.damageType == COMBAT_ELEMENTAL and table.contains(elementalDamageTypes, secondaryType) then
                    secondaryIncrease = true
                end
                if index.damageType == secondaryType then
                    secondaryIncrease = true
                end
             
                -- damage calculation
                if primaryIncrease then
                    primaryDamage = primaryDamage * (index.damagePercentage + 1)
                end
                if secondaryIncrease then
                    secondaryDamage = secondaryDamage * (index.damagePercentage + 1)
                end
            end
        end
    end
 
    return primaryDamage, secondaryDamage
end
 
If using the same style as the buff potion, data/scripts

And yes, the code can be modified to trigger on all elements.

Lua:
local COMBAT_ELEMENTAL = 10000
local COMBAT_ALL = 10001

local elementalDamageTypes = {
    COMBAT_ENERGYDAMAGE,
    COMBAT_EARTHDAMAGE,
    COMBAT_FIREDAMAGE,
    COMBAT_ICEDAMAGE,
    COMBAT_HOLYDAMAGE,
    COMBAT_DEATHDAMAGE
}

local buff_items = {
    --[itemid] = {damageType, damagePercentage}
    [1111] = {damageType = COMBAT_PHYSICALDAMAGE, damagePercentage = 0.5}, -- 50% extra damage
    [2222] = {damageType = COMBAT_ENERGYDAMAGE,   damagePercentage = 1}, -- 100% extra damage
    [3333] = {damageType = COMBAT_EARTHDAMAGE,    damagePercentage = 1},
    [4444] = {damageType = COMBAT_FIREDAMAGE,     damagePercentage = 1},
    [5555] = {damageType = COMBAT_ICEDAMAGE,      damagePercentage = 1},
    [6666] = {damageType = COMBAT_HOLYDAMAGE,     damagePercentage = 1},
    [7777] = {damageType = COMBAT_DEATHDAMAGE,    damagePercentage = 1},
    [8888] = {damageType = COMBAT_ELEMENTAL,      damagePercentage = 1}, -- elemental types
    [9999] = {damageType = COMBAT_ALL,            damagePercentage = 1}  -- all damage types
}



local function damageCalculator(primaryDamage, primaryType, secondaryDamage, secondaryType, playerid)
    local player = Player(playerid)
 
    for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        local slotItem = player:getSlotItem(slot)
        if slotItem then
            local slotItemId = slotItem:getId()
            local index = buff_items[slotItemId]
            if index then
                local primaryIncrease = false
                local secondaryIncrease = false
            
                -- primary damage checks
                if index.damageType == COMBAT_ALL and (primaryType == COMBAT_PHYSICALDAMAGE or table.contains(elementalDamageTypes, primaryType)) then
                    primaryIncrease = true
                end
                if index.damageType == COMBAT_ELEMENTAL and table.contains(elementalDamageTypes, primaryType) then
                    primaryIncrease = true
                end
                if index.damageType == primaryType then
                    primaryIncrease = true
                end
            
                -- secondary damage checks
                if index.damageType == COMBAT_ALL and (secondaryType == COMBAT_PHYSICALDAMAGE or table.contains(elementalDamageTypes, secondaryType)) then
                    secondaryIncrease = true
                end
                if index.damageType == COMBAT_ELEMENTAL and table.contains(elementalDamageTypes, secondaryType) then
                    secondaryIncrease = true
                end
                if index.damageType == secondaryType then
                    secondaryIncrease = true
                end
            
                -- damage calculation
                if primaryIncrease then
                    primaryDamage = primaryDamage * (index.damagePercentage + 1)
                end
                if secondaryIncrease then
                    secondaryDamage = secondaryDamage * (index.damagePercentage + 1)
                end
            end
        end
    end
 
    return primaryDamage, secondaryDamage
end
I put it on my server/data/script/creaturscript, and I tested it and nothing happened,,, the spells or the runes to takar
explain to me how this code works? when using item and gain in % damage?
 
I put it on my server/data/script/creaturscript, and I tested it and nothing happened,,, the spells or the runes to takar
explain to me how this code works? when using item and gain in % damage?
If it's not working, add some prints.

I'd suggest putting it into every part to see where it's failing.

onLogin, onSpawn, onHealthChange, onManaChange, and also in the damageCalculator function.
 
So what happened after you added the prints?
Where was the issue?
 
There is no error in the console, I already tried to change it as you said
Post automatically merged:

Have you tested this code in game? it worked for you?
 
Last edited:
There is no error in the console, I already tried to change it as you said
Post automatically merged:

Have you tested this code in game? it worked for you?
I have no way to test the code.

Can you tell me what prints you added, and what they printed to the console?

I can't help if you don't provide any information.

--
I'd suggest also pasting all of your current code in your following reply, along with the prints to console.
 
onLogin, onSpawn, onHealthChange, onManaChange, and also in the damageCalculator function.
I already tried to change some things as you said, no errors appeared on the console and I tested it in the game... But there was no difference in the damage. For example, when I use an item that is supposed to increase magic damage by 20%, the damage remains the same. For example, if the initial damage is 1000, when using the item, it is still 1000, when the expected increase would be 1200, which would be a 20% increase
 
I already tried to change some things as you said, no errors appeared on the console and I tested it in the game... But there was no difference in the damage. For example, when I use an item that is supposed to increase magic damage by 20%, the damage remains the same. For example, if the initial damage is 1000, when using the item, it is still 1000, when the expected increase would be 1200, which would be a 20% increase
I have no way to test the code.

Can you tell me what prints you added, and what they printed to the console?

I can't help if you don't provide any information.

I'd suggest also pasting all of your current code in your following reply, along with the prints to console.
 
Look, I made a script, but I know it doesn't work. Does anyone know if it's possible to put a script via CreatureScript, for example, on an item when using it and gain a magic damage bonus in percentage?

code for example
Lua:
function onCreatureAttack(creature, target, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    local attackerPlayer = creature:getPlayer()

    for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        if attackerPlayer:isItemAbilityEnabled(slot) then
            local item = attackerPlayer:getInventoryItem(slot)
            if item then
                local boostPercent = item:getBoostPercent(primaryType)
                if boostPercent ~= 0 then
                    primaryDamage = primaryDamage + math.round(primaryDamage * (boostPercent / 100))
                end
            end
        end
    end

    if primaryDamage <= 0 then
        primaryDamage = 0
        secondaryType = BLOCK_ARMOR
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Does anyone have any ideas about this? I urgently need my server, because I'm almost finishing my project. It was the last detail, please. I already tried using magicpointsPercepent and BossPercent, but neither worked

Lua:
local creatureEvent = CreatureEvent("MagicDamageBoost")

function creatureEvent.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player:isPlayer() then
        return false
    end

    local boostPercent = 0
    local itemID = item:getId()

    local itemNode = ItemType(itemID)
    if itemNode:isStackable() or itemNode:isMultiType() then
        itemNode = ItemType(itemID, item:getType())
    end

    if itemNode then
        boostPercent = itemNode:getMagicDamagePercent()
    end

    if boostPercent > 0 then
        local magicDamageBoost = player:getBaseMagicDamage() * boostPercent / 100
        player:setBaseMagicDamage(player:getBaseMagicDamage() + magicDamageBoost)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel an increase in your magical power.")
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        item:remove(1)
    else
        player:sendCancelMessage("This item doesn't provide any magical damage boost.")
    end

    return true
end

creatureEvent:register()



can be creaturescript or Revscript.. Thank you
data/scripts/file.lua
Lua:
local items = {
    [itemId] = 200, -- 200% more damage
}

local function onDamage(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    local boostPercent = 0
    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        local slotItem = attacker:getSlotItem(slot)
        if slotItem then
            local percent = items[slotItem:getId()]
            if percent then
                boostPercent = boostPercent + percent
            end
        end
    end

    if boostPercent > 0 then
        primaryDamage = primaryDamage * (1 + (boostPercent / 100))
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

local hp = CreatureEvent("DamageBoostHP")
hp.onHealthChange = onDamage
hp:register()

local mp = CreatureEvent("DamageBoostMP")
mp.onManaChange = onDamage
mp:register()

local event = EventCallback

function event.onTargetCombat(creature, target)
    if creature and target then
        if creature:isPlayer() then
            target:registerEvent("DamageBoostHP")
            target:registerEvent("DamageBoostMP")
        end
    end
    return RETURNVALUE_NOERROR
end

event:register()

If you do not have EventCallback you must place this code in the event onTargetCombat on data/events/scripts/creature.lua
Lua:
if creature and target then
    if creature:isPlayer() then
        target:registerEvent("DamageBoostHP")
        target:registerEvent("DamageBoostMP")
    end
end
 
@Sarah Wesker
Does it need to be in onTargetCombat?
I'd try with onLogin so registerEvent is called once only*
*it won't change much as registerCreatureEvent anyway checks whether such event is on list but it's more about case when there's no EventCallback


Lua:
local loginEvent = CreatureEvent('registerDamageBoost')
loginEvent:type('login')

function loginEvent.onLogin(player)
    player:registerEvent('DamageBoostHP')
    player:registerEvent('DamageBoostHP')
    return true
end

loginEvent:register()
 
@Sarah Wesker
Does it need to be in onTargetCombat?
I'd try with onLogin so registerEvent is called once only*
*it won't change much as registerCreatureEvent anyway checks whether such event is on list but it's more about case when there's no EventCallback


Lua:
local loginEvent = CreatureEvent('registerDamageBoost')
loginEvent:type('login')

function loginEvent.onLogin(player)
    player:registerEvent('DamageBoostHP')
    player:registerEvent('DamageBoostHP')
    return true
end

loginEvent:register()
If you only want to affect players yes, login is fine.
 
Hello goodnight! I finally managed to add increaseMagicPercent in TFS 1.5 source. The magic damage percentage is working perfectly, no errors. I know there are people interested in this role. I'm going to talk to the person who gave me all the codes to see if he authorizes me to share them with you. :)


It's already over, thank God!!🤩🤩
 
Back
Top