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

TFS 1.X+ Wand Element

jel

Member
Joined
Mar 22, 2014
Messages
302
Reaction score
12
how can i put it to use in two types of wand, i tried but it didn't work, it works only one instead of both.
tfs 1.3

 
it was pretty rough to do with the original as it was, so I rewrote it a bit.
lib-weapon_damage.lua:
Lua:
-- Modal window config and storage id
local config = {
    storage = 90000,
    titleMsg = "Change Weapon Damage Type",
    mainMsg = "Choose a damage type from the list",
-- End Config

    damage = {-- Damage Table
        [1] = {element = "Holy"},
        [2] = {element = "Fire"},
        [3] = {element = "Death"},
        [4] = {element = "Poison"},
        [5] = {element = "Energy"},
        [6] = {element = "Earth"},
        [7] = {element = "Ice"},
    },

-- Set wand how the wand deals damage
    DamageTypeWand = {
        values = false, -- If this is set to true then it will use the min and max values. If set to false the wand will use the formula
        
        -- Damage Values min/max
        wandMinDam = 20,
        wandMaxDam = 50,
        
        -- Damage Formula
        formula = {
            wandMinDam = function(level, maglevel) return -((level / 5) + (maglevel * 1.4) + 8) end,
            wandMaxDam = function(level, maglevel) return -((level / 5) + (maglevel * 2.2) + 14) end,
        }
    }
}
function getWandConfig()
    return config
end
function Player:sendDamageWindow(config, id)
    local function buttonCallback(button, choice)
    -- Modal window functionallity
        if button.text == "Confirm" then
            self:setStorageValue(config.storage + id, choice.id)
        end
    end
    
-- Modal window design
    local window = ModalWindow {
        title = config.titleMsg, -- Title of the modal window
        message = config.mainMsg, -- The message to be displayed on the modal window
    }

    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Confirm", buttonCallback)
    window:addButton("Cancel")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Confirm")
    window:setDefaultEscapeButton("Cancel")

    -- Add choices from the action script
    for i = 1, #config.damage do
        local o = config.damage[i].element
        window:addChoice(o)
    end

    -- Send the window to player
    window:sendToPlayer(self)
end
actions-weapon_damage.lua:

Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:sendDamageWindow(wandDamageSystem:getConfig(), item:getId())
    return true
end

weapons-weapon_damage.lua:

Lua:
local DamageTypes = {
    [1] = {DamageType = COMBAT_HOLYDAMAGE, DamageEffect = CONST_ANI_HOLY},
    [2] = {DamageType = COMBAT_FIREDAMAGE, DamageEffect = CONST_ANI_FIRE},
    [3] = {DamageType = COMBAT_DEATHDAMAGE, DamageEffect = CONST_ANI_DEATH},
    [4] = {DamageType = COMBAT_POISONDAMAGE, DamageEffect = CONST_ANI_POISON},
    [5] = {DamageType = COMBAT_ENERGYDAMAGE, DamageEffect = CONST_ANI_ENERGY},
    [6] = {DamageType = COMBAT_EARTHDAMAGE, DamageEffect = CONST_ANI_EARTH},
    [7] = {DamageType = COMBAT_ICEDAMAGE, DamageEffect = CONST_ANI_ICE}
}
local config = getWandConfig()
function onGetFormulaValues(player, level, maglevel)
    if config.DamageTypeWand.values then
        min = -(config.DamageTypeWand.wandMinDam)
        max = -(config.DamageTypeWand.wandMaxDam)
    else
        min = config.DamageTypeWand.formula.wandMinDam(level, maglevel)
        max = config.DamageTypeWand.formula.wandMaxDam(level, maglevel)
    end
    return min, max
end
 
local combat = {}
for k, dam_Table in pairs(DamageTypes) do
    combat[k] = Combat()
    combat[k]:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
    combat[k]:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
    combat[k]:setParameter(COMBAT_PARAM_TYPE, dam_Table.DamageType)
    combat[k]:setParameter(COMBAT_PARAM_DISTANCEEFFECT, dam_Table.DamageEffect)   
    
    -- _G Is used to manually define 'onGetFormulaValues' in this loop in doesnt seem to be able to find the function.
    _G['onGetFormulaValues' .. k] = onGetFormulaValues
    combat[k]:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues" .. k)
end
 
function onUseWeapon(player, var)
    local value = player:getStorageValue(config.storage + player:getSlotItem(CONST_SLOT_LEFT):getId())
    local combatUse = combat[value]
    if not combatUse then
        return true
    end
    return combatUse:execute(player, var)
end
I didn't test it so let me know if there's any issues.
just follow the installation instructions from the original post, as the file names I chose are the same as his.
 
it was pretty rough to do with the original as it was, so I rewrote it a bit.
lib-weapon_damage.lua:
Lua:
-- Modal window config and storage id
local config = {
    storage = 90000,
    titleMsg = "Change Weapon Damage Type",
    mainMsg = "Choose a damage type from the list",
-- End Config

    damage = {-- Damage Table
        [1] = {element = "Holy"},
        [2] = {element = "Fire"},
        [3] = {element = "Death"},
        [4] = {element = "Poison"},
        [5] = {element = "Energy"},
        [6] = {element = "Earth"},
        [7] = {element = "Ice"},
    },

-- Set wand how the wand deals damage
    DamageTypeWand = {
        values = false, -- If this is set to true then it will use the min and max values. If set to false the wand will use the formula
       
        -- Damage Values min/max
        wandMinDam = 20,
        wandMaxDam = 50,
       
        -- Damage Formula
        formula = {
            wandMinDam = function(level, maglevel) return -((level / 5) + (maglevel * 1.4) + 8) end,
            wandMaxDam = function(level, maglevel) return -((level / 5) + (maglevel * 2.2) + 14) end,
        }
    }
}
function getWandConfig()
    return config
end
function Player:sendDamageWindow(config, id)
    local function buttonCallback(button, choice)
    -- Modal window functionallity
        if button.text == "Confirm" then
            self:setStorageValue(config.storage + id, choice.id)
        end
    end
   
-- Modal window design
    local window = ModalWindow {
        title = config.titleMsg, -- Title of the modal window
        message = config.mainMsg, -- The message to be displayed on the modal window
    }

    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Confirm", buttonCallback)
    window:addButton("Cancel")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Confirm")
    window:setDefaultEscapeButton("Cancel")

    -- Add choices from the action script
    for i = 1, #config.damage do
        local o = config.damage[i].element
        window:addChoice(o)
    end

    -- Send the window to player
    window:sendToPlayer(self)
end
actions-weapon_damage.lua:

Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:sendDamageWindow(wandDamageSystem:getConfig(), item:getId())
    return true
end

weapons-weapon_damage.lua:

Lua:
local DamageTypes = {
    [1] = {DamageType = COMBAT_HOLYDAMAGE, DamageEffect = CONST_ANI_HOLY},
    [2] = {DamageType = COMBAT_FIREDAMAGE, DamageEffect = CONST_ANI_FIRE},
    [3] = {DamageType = COMBAT_DEATHDAMAGE, DamageEffect = CONST_ANI_DEATH},
    [4] = {DamageType = COMBAT_POISONDAMAGE, DamageEffect = CONST_ANI_POISON},
    [5] = {DamageType = COMBAT_ENERGYDAMAGE, DamageEffect = CONST_ANI_ENERGY},
    [6] = {DamageType = COMBAT_EARTHDAMAGE, DamageEffect = CONST_ANI_EARTH},
    [7] = {DamageType = COMBAT_ICEDAMAGE, DamageEffect = CONST_ANI_ICE}
}
local config = getWandConfig()
function onGetFormulaValues(player, level, maglevel)
    if config.DamageTypeWand.values then
        min = -(config.DamageTypeWand.wandMinDam)
        max = -(config.DamageTypeWand.wandMaxDam)
    else
        min = config.DamageTypeWand.formula.wandMinDam(level, maglevel)
        max = config.DamageTypeWand.formula.wandMaxDam(level, maglevel)
    end
    return min, max
end

local combat = {}
for k, dam_Table in pairs(DamageTypes) do
    combat[k] = Combat()
    combat[k]:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
    combat[k]:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
    combat[k]:setParameter(COMBAT_PARAM_TYPE, dam_Table.DamageType)
    combat[k]:setParameter(COMBAT_PARAM_DISTANCEEFFECT, dam_Table.DamageEffect)  
   
    -- _G Is used to manually define 'onGetFormulaValues' in this loop in doesnt seem to be able to find the function.
    _G['onGetFormulaValues' .. k] = onGetFormulaValues
    combat[k]:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues" .. k)
end

function onUseWeapon(player, var)
    local value = player:getStorageValue(config.storage + player:getSlotItem(CONST_SLOT_LEFT):getId())
    local combatUse = combat[value]
    if not combatUse then
        return true
    end
    return combatUse:execute(player, var)
end
I didn't test it so let me know if there's any issues.
just follow the installation instructions from the original post, as the file names I chose are the same as his.
Lua Script Error: [Action Interface]
data/actions/scripts/aepic.lua:eek:nUse
data/lib/lib-weapon_damage.lua:59: attempt to get length of field 'damage' (a nil value)
stack traceback:
[C]: in function '__len'
data/lib/lib-weapon_damage.lua:59: in function 'sendDamageWindow'
data/actions/scripts/aepic.lua:36: in function <data/actions/scripts/aepic.lua:35>

conflict
 
Edit:
slight change to lib-weapon_damage.lua:
Lua:
-- Modal window config and storage id
local config = {
    storage = 90000,
    titleMsg = "Change Weapon Damage Type",
    mainMsg = "Choose a damage type from the list",
-- End Config

    damage = {-- Damage Table
        [1] = {element = "Holy"},
        [2] = {element = "Fire"},
        [3] = {element = "Death"},
        [4] = {element = "Poison"},
        [5] = {element = "Energy"},
        [6] = {element = "Earth"},
        [7] = {element = "Ice"},
    },

-- Set wand how the wand deals damage
    DamageTypeWand = {
        values = false, -- If this is set to true then it will use the min and max values. If set to false the wand will use the formula
        
        -- Damage Values min/max
        wandMinDam = 20,
        wandMaxDam = 50,
        
        -- Damage Formula
        formula = {
            wandMinDam = function(level, maglevel) return -((level / 5) + (maglevel * 1.4) + 8) end,
            wandMaxDam = function(level, maglevel) return -((level / 5) + (maglevel * 2.2) + 14) end,
        }
    }
}4
function getWandConfig()
    return config
end
function Player:sendDamageWindow(id)
    local function buttonCallback(button, choice)
    -- Modal window functionallity
        if button.text == "Confirm" then
            self:setStorageValue(config.storage + id, choice.id)
        end
    end
    
-- Modal window design
    local window = ModalWindow {
        title = config.titleMsg, -- Title of the modal window
        message = config.mainMsg, -- The message to be displayed on the modal window
    }

    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Confirm", buttonCallback)
    window:addButton("Cancel")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Confirm")
    window:setDefaultEscapeButton("Cancel")

    -- Add choices from the action script
    for i = 1, #config.damage do
        local o = config.damage[i].element
        window:addChoice(o)
    end

    -- Send the window to player
    window:sendToPlayer(self)
end
forgot to change an old piece of code after changing the lib. change actions-weapon_damage.lua to this:

Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:sendDamageWindow(item:getId())
    return true
end
pretty sure that should be fine.
 
Last edited:
Edit:
slight change to lib-weapon_damage.lua:
Lua:
-- Modal window config and storage id
local config = {
    storage = 90000,
    titleMsg = "Change Weapon Damage Type",
    mainMsg = "Choose a damage type from the list",
-- End Config

    damage = {-- Damage Table
        [1] = {element = "Holy"},
        [2] = {element = "Fire"},
        [3] = {element = "Death"},
        [4] = {element = "Poison"},
        [5] = {element = "Energy"},
        [6] = {element = "Earth"},
        [7] = {element = "Ice"},
    },

-- Set wand how the wand deals damage
    DamageTypeWand = {
        values = false, -- If this is set to true then it will use the min and max values. If set to false the wand will use the formula
       
        -- Damage Values min/max
        wandMinDam = 20,
        wandMaxDam = 50,
       
        -- Damage Formula
        formula = {
            wandMinDam = function(level, maglevel) return -((level / 5) + (maglevel * 1.4) + 8) end,
            wandMaxDam = function(level, maglevel) return -((level / 5) + (maglevel * 2.2) + 14) end,
        }
    }
}4
function getWandConfig()
    return config
end
function Player:sendDamageWindow(id)
    local function buttonCallback(button, choice)
    -- Modal window functionallity
        if button.text == "Confirm" then
            self:setStorageValue(config.storage + id, choice.id)
        end
    end
   
-- Modal window design
    local window = ModalWindow {
        title = config.titleMsg, -- Title of the modal window
        message = config.mainMsg, -- The message to be displayed on the modal window
    }

    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Confirm", buttonCallback)
    window:addButton("Cancel")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Confirm")
    window:setDefaultEscapeButton("Cancel")

    -- Add choices from the action script
    for i = 1, #config.damage do
        local o = config.damage[i].element
        window:addChoice(o)
    end

    -- Send the window to player
    window:sendToPlayer(self)
end
forgot to change an old piece of code after changing the lib. change actions-weapon_damage.lua to this:

Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:sendDamageWindow(item:getId())
    return true
end
pretty sure that should be fine.
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/modalwindowhelper.lua:eek:nModalWindow
data/lib/lib-weapon_damage.lua:40: attempt to perform arithmetic on upvalue 'id' (a table value)
stack traceback:
[C]: in function '__add'
data/lib/lib-weapon_damage.lua:40: in function 'callback'
data/creaturescripts/scripts/modalwindowhelper.lua:26: in function <data/creaturescripts/scripts/modalwindowhelper.lua:1>
 
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/modalwindowhelper.lua:eek:nModalWindow
data/lib/lib-weapon_damage.lua:40: attempt to perform arithmetic on upvalue 'id' (a table value)
stack traceback:
[C]: in function '__add'
data/lib/lib-weapon_damage.lua:40: in function 'callback'
data/creaturescripts/scripts/modalwindowhelper.lua:26: in function <data/creaturescripts/scripts/modalwindowhelper.lua:1>
Are you sure you updated both scripts with the code in my last post? There should be no circumstance where the function receives a table, all i’m passing to it is an item id, but it’s receiving a table for some reason
 
Back
Top