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

Lua onUseWeapon()

natanal99

New Member
Joined
May 31, 2011
Messages
67
Reaction score
3
i have this in weapons.xml

Code:
    <melee id="7390" level="2000" enabled="1" event="script" value="melee.lua">
        <vocation id="1"/>
    </melee>
    <melee id="8209" level="2000" enabled="1" event="script" value="melee.lua">
        <vocation id="1"/>
    </melee>

is there a way i can i know in the "melee.lua" script wich weapon id casted the onUseWeapon()?
 
i have this in weapons.xml

Code:
    <melee id="7390" level="2000" enabled="1" event="script" value="melee.lua">
        <vocation id="1"/>
    </melee>
    <melee id="8209" level="2000" enabled="1" event="script" value="melee.lua">
        <vocation id="1"/>
    </melee>

is there a way i can i know in the "melee.lua" script wich weapon id casted the onUseWeapon()?
Post the melee.lua
 
i want to set a different combat effect for different weapons, but without copy and paste hundreds of scripts, just coding a table where i set a different effect for every weapons id

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 98)

function onGetFormulaValues(cid, level, skill, attack, factor)
   
    local mindmg = attack*skill/20
    local maxdmg = attack*skill/20
   
    return -mindmg, -maxdmg
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
    return doCombat(cid, combat, var)
end
 
Try this
Code:
local weapons = {
    [7390] = {effect = CONST_ME_MORTAREA, does = COMBAT_PARAM_BLOCKARMOR, value = 1, type_ = COMBAT_PHYSICALDAMAGE},
    [8209] = {effect = CONST_ME_TELEPORT, does = COMBAT_PARAM_BLOCKSHIELD, value = 1, type_ = COMBAT_ENERGYDAMAGE}
}

local combat = {}

function onGetFormulaValues(cid, level, skill, attack, factor)
 
    local mindmg = attack*skill/20
    local maxdmg = attack*skill/20
 
    return -mindmg, -maxdmg
end

for i in pairs(weapons) do
    combat[i] = createCombatObject()
    setCombatParam(combat[i], weapons[i].does, weapons[i].value)
    setCombatParam(combat[i], COMBAT_PARAM_TYPE, weapons[i].type_)
    setCombatParam(combat[i], COMBAT_PARAM_EFFECT, weapons[i].effect)
  
    setCombatCallback(combat[i], CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
end


function onUseWeapon(cid, var)
    local slot = {5, 6}
    for i = 1, #slot do
        weaponItemId = getPlayerSlotItem(cid, slot[i]).itemid
        if weapons[weaponItemId] then
            return doCombat(cid, combat[weaponItemId], var)
        end
    end
    return true
end

Please learn lua so you can construct scripts too :)
http://tutorialspoint.com/lua/
Whether they work or not that is another story :p
 
Last edited:
i got this:

[26/01/2016 00:36:53] [Error - Weapon Interface]
[26/01/2016 00:36:53] data/weapons/scripts/melee.lua
[26/01/2016 00:36:53] Description:
[26/01/2016 00:36:53] (luaSetCombatCallBack) Cannot load callback
[26/01/2016 00:36:53] Warning: [CallBack::loadCallBack] Event onGetFormulaValues not found.

repeatedly many times on initiates the server :/
 
Code:
local weapons = {
    [7390] = {effect = CONST_ME_MORTAREA, does = COMBAT_PARAM_BLOCKARMOR, value = 1, type_ = COMBAT_PHYSICALDAMAGE},
    [8209] = {effect = CONST_ME_TELEPORT, does = COMBAT_PARAM_BLOCKSHIELD, value = 1, type_ = COMBAT_ENERGYDAMAGE}
}

local combat = {}

for i in pairs(weapons) do
    combat[i] = createCombatObject()
    setCombatParam(combat[i], weapons[i].does, weapons[i].value)
    setCombatParam(combat[i], COMBAT_PARAM_TYPE, weapons[i].type_)
    setCombatParam(combat[i], COMBAT_PARAM_EFFECT, weapons[i].effect)
end

function onGetFormulaValues(cid, level, skill, attack, factor)
    local mindmg = attack*skill/20
    local maxdmg = attack*skill/20
    return -mindmg, -maxdmg
end

for x in pairs(weapons) do
    setCombatCallback(combat[x], CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
end

function onUseWeapon(cid, var)
    local slot = {5, 6}
    for i = 1, #slot do
        weaponItemId = getPlayerSlotItem(cid, slot[i]).itemid
        if weapons[weaponItemId] then
            return doCombat(cid, combat[weaponItemId], var)
        end
    end
    return true
end
 
Back
Top