• 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 7.6 xml how to spell only cast if player is using item

vimpexx

New Member
Joined
Sep 16, 2012
Messages
16
Reaction score
4
Hi guys,

I would like to edit some spells on my server so that they are only cast when a player is using a specific item, for example:

The player can cast a XXX spell if he uses YYY on the item.
YYY item - item for each profession
can be used every X minutes (exhaust).
Can I do it in lua under 7.6 xml?
 
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_USECHARGES, 1)
combat:setArea(createCombatArea(AREA_SQUARE1X1))

function onGetFormulaValues(player, skill, attack, factor)
    local level = player:getLevel()
    local min = (level / 5) + (skill + attack) * 0.5
    local max = (level / 5) + (skill + attack) * 1.5
    return -min * 1.1, -max * 1.1 -- TODO : Use New Real Formula instead of an %
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    local weapons = {2321, 5342}
    local shields = {6391, 2523}

        local slotWeapon = CONST_SLOT_LEFT
        local slotShield = CONST_SLOT_RIGHT
        
        local playerWeapon = creature:getSlotItem(slotWeapon)
        local playerShield = creature:getSlotItem(slotShield)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
        if playerShield and table.contains(shields, playerShield:getId()) then
            return combat:execute(creature, var)
        end
    end

    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a special weapon to cast this spell.")
    return false
end

Probably won't work in your engine but you can check
 
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_USECHARGES, 1)
combat:setArea(createCombatArea(AREA_SQUARE1X1))

function onGetFormulaValues(player, skill, attack, factor)
    local level = player:getLevel()
    local min = (level / 5) + (skill + attack) * 0.5
    local max = (level / 5) + (skill + attack) * 1.5
    return -min * 1.1, -max * 1.1 -- TODO : Use New Real Formula instead of an %
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    local weapons = {2321, 5342}
    local shields = {6391, 2523}

        local slotWeapon = CONST_SLOT_LEFT
        local slotShield = CONST_SLOT_RIGHT
       
        local playerWeapon = creature:getSlotItem(slotWeapon)
        local playerShield = creature:getSlotItem(slotShield)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
        if playerShield and table.contains(shields, playerShield:getId()) then
            return combat:execute(creature, var)
        end
    end

    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a special weapon to cast this spell.")
    return false
end

Probably won't work in your engine but you can check
attempt to call global `Combat' (a nil value)
 
I don't understand exactly what you want
Do you want a spell that can only be used if you use a specific item?
What I don't understand is how it can be used more than once and why?
I can help you if it's like a quest whoever gets it can cast the spell
Whoever does not do the task cannot use the incantation
What do you think?
 
I just wanted to do so that after using the item it uses a XXX spell. If that can't be done in LUA, then there might be a mission after which we can use the XXX spell.
I don't understand exactly what you want
Do you want a spell that can only be used if you use a specific item?
What I don't understand is how it can be used more than once and why?
I can help you if it's like a quest whoever gets it can cast the spell
Whoever does not do the task cannot use the incantation
What do you think?
 
I just wanted to do so that after using the item it uses a XXX spell. If that can't be done in LUA, then there might be a mission after which we can use the XXX spell.
Well try this
Spells/script Create /Lua name >rattle
and put this text in it
Lua:
local acombat = createCombatObject()

local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat1, COMBAT_PARAM_EFFECT, 41)
setCombatFormula(combat1, COMBAT_FORMULA_LEVELMAGIC, -3.3, -90, -3.3, -90)

local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat2, COMBAT_PARAM_EFFECT, 54)
setCombatFormula(combat2, COMBAT_FORMULA_LEVELMAGIC, -3.3, -90, -3.3, -90)

local combat3 = createCombatObject()
setCombatParam(combat3, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat3, COMBAT_PARAM_EFFECT, 42)
setCombatFormula(combat3, COMBAT_FORMULA_LEVELMAGIC, -3.3, -90, -3.3, -90)

arr1 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 1, 0, 0, 2, 0, 0, 1, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}

arr2 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 2, 0, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}

arr3 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}

local area1 = createCombatArea(arr1)
local area2 = createCombatArea(arr2)
local area3 = createCombatArea(arr3)
setCombatArea(combat1, area1)
setCombatArea(combat2, area2)
setCombatArea(combat3, area3)
local function onCastSpell1(parameters)
doCombat(parameters.cid, parameters.combat1, parameters.var)
end

local function onCastSpell2(parameters)
doCombat(parameters.cid, parameters.combat2, parameters.var)
end

local function onCastSpell3(parameters)
doCombat(parameters.cid, parameters.combat3, parameters.var)
end



function onCastSpell(cid, var)
local parameters = {cid = cid, var = var, combat1 = combat1, combat2 = combat2, combat3 = combat3}
addEvent(onCastSpell1, 0, parameters)
addEvent(onCastSpell2, 200, parameters)
addEvent(onCastSpell3, 400, parameters)
end



function onCastSpell(cid, var)
if getPlayerStorageValue(cid, 90732) == 1 then
strg = getPlayerStorageValue(cid, 90732)
doCombat(cid, acombat, var)
local parameters = { cid = cid, var = var, combat1 = combat1, combat2 = combat2, combat3 = combat3,}
addEvent(onCastSpell1, 0, parameters)
addEvent(onCastSpell2, 0, parameters)
addEvent(onCastSpell3, 0, parameters)
else
doPlayerSendCancel(cid,"You Must Do The Q Before Casting This Spell.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
end
Goto spells xml
Code:
<instant name="exevo mega tera" words="rattle"  lvl="600" maglv="100" mana="4500" selftarget="1"  soul="0"  exhaustion="1" prem="0" enabled="1" script="New/rattle.lua"><vocation id="2"/><vocation id="6"/><vocation id="10"/><vocation id="14"/><vocation id="18"/></instant>
Don't forget to change the vocations id
Goto Actions xml put \/
Code:
<action actionid="2175" script="Q SPELLS.lua" />
go actions /scripts/make new lua name Q SPELLS
and put \/
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local name = getCreatureName(cid)
local level = getPlayerLevel(cid)
     if getPlayerStorageValue(cid,90732) < 1 then
        if getPlayerLevel(cid) > 1 then
           setPlayerStorageValue(cid,90732,1)
                  doPlayerSay(cid, "Felicity " ..  name .. " [" ..level.. "], Cast Your New Spell.", TALKTYPE_ORANGE_1)
        else
            doPlayerSendTextMessage(cid,19,"You " ..  name .. " [" ..level.. "], need to be Level 100 or More To Use It.")
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
        end
else
            doPlayerSendTextMessage(cid,19,"Sorry " ..  name .. " [" ..level.. "], You Have Done The Q Before.")
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end   
return TRUE
end
Goto rme and make like me
Explained in the picture






spells.png
 
Back
Top