• 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 Spell Problem

Karofel

New Member
Joined
Apr 12, 2017
Messages
10
Solutions
1
Reaction score
2
Hello, i have a small problem there:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_DRAWBLOOD)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
local Crossbows = {2455, 5803, 8849, 8850, 8851, 8852, 8853, 18453, 16111, 22419, 22420, 22421}
local Bows = {2456, 7438, 8854, 8855, 8856, 8857, 8858, 10295, 13873, 15643, 15644, 18454, 22416, 22417, 22418}
local Arrows = {2544, 2545, 2546, 7365, 7364, 7838, 7840, 7839, 7850, 15648, 18437, 18304}
local Bolts = {2543, 2547, 6529, 7363, 15649, 18435, 18436}
local Throwables = {2111, 2389, 3965, 7367, 7378, 2399, 7368, 7366, 2410}
local animation = {
[2543] = CONST_ANI_BOLT,
[2547] = CONST_ANI_POWERBOLT,
[6529] = CONST_ANI_INFERNALBOLT,
[7363] = CONST_ANI_PIERCINGBOLT,
[15649] = CONST_ANI_VORTEXBOLT,
[18435] = CONST_ANI_PRISMATICBOLT,
[18436] = CONST_ANI_DRILLBOLT,
[2544] = CONST_ANI_ARROW,
[2545] = CONST_ANI_POISONARROW,
[2546] = CONST_ANI_BURSTARROW,
[7365] = CONST_ANI_ONYXARROW,
[7364] = CONST_ANI_SNIPERARROW,
[7838] = CONST_ANI_FLASHARROW,
[7840] = CONST_ANI_FLAMMINGARROW,
[7839] = CONST_ANI_SHIVERARROW,
[7850] = CONST_ANI_EARTHARROW,
[15648] = CONST_ANI_TARSALARROW,
[18437] = CONST_ANI_ENVENOMEDARROW,
[18304] = CONST_ANI_CRYSTALLINEARROW,
[2111] = CONST_ANI_SNOWBALL,
[2389] = CONST_ANI_SPEAR,
[3965] = CONST_ANI_HUNTINGSPEAR,
[7367] = CONST_ANI_ENCHANTEDSPEAR,
[7378] = CONST_ANI_ROYALSPEAR,
[2399] = CONST_ANI_THROWINGSTAR,
[7368] = CONST_ANI_REDSTAR,
[7366] = CONST_ANI_GREENSTAR,
[2410] = CONST_ANI_THROWINGKNIFE
}
local damageType = {
[2544] = COMBAT_PHYSICALDAMAGE,
[2545] = COMBAT_PHYSICALDAMAGE,
[2546] = COMBAT_FIREDAMAGE,
[7365] = COMBAT_PHYSICALDAMAGE,
[7364] = COMBAT_PHYSICALDAMAGE,
[7838] = COMBAT_ENERGYDAMAGE,
[7840] = COMBAT_FIREDAMAGE,
[7839] = COMBAT_ICEDAMAGE,
[7850] = COMBAT_EARTHDAMAGE,
[15648] = COMBAT_EARTHDAMAGE,
[18437] = COMBAT_EARTHDAMAGE,
[18304] = COMBAT_EARTHDAMAGE,
[2111] = COMBAT_PHYSICALDAMAGE,
[2389] = COMBAT_PHYSICALDAMAGE,
[3965] = COMBAT_PHYSICALDAMAGE,
[7367] = COMBAT_PHYSICALDAMAGE,
[7378] = COMBAT_PHYSICALDAMAGE,
[2399] = COMBAT_PHYSICALDAMAGE,
[7368] = COMBAT_PHYSICALDAMAGE,
[7366] = COMBAT_PHYSICALDAMAGE,
[2410] = COMBAT_PHYSICALDAMAGE,
[2543] = COMBAT_PHYSICALDAMAGE,
[2547] = COMBAT_PHYSICALDAMAGE,
[6529] = COMBAT_PHYSICALDAMAGE,
[7363] = COMBAT_PHYSICALDAMAGE,
[15649] = COMBAT_PHYSICALDAMAGE,
[18435] = COMBAT_PHYSICALDAMAGE,
[18436] = COMBAT_PHYSICALDAMAGE,
[2111] = COMBAT_PHYSICALDAMAGE,
[2389] = COMBAT_PHYSICALDAMAGE,
[3965] = COMBAT_PHYSICALDAMAGE,
[7367] = COMBAT_PHYSICALDAMAGE,
[7378] = COMBAT_PHYSICALDAMAGE,
[2399] = COMBAT_PHYSICALDAMAGE,
[7368] = COMBAT_PHYSICALDAMAGE,
[7366] = COMBAT_PHYSICALDAMAGE,
[2410] = COMBAT_PHYSICALDAMAGE,
[1294] = COMBAT_PHYSICALDAMAGE
}
local magicEffect = 0
local dmgType = 0
local function doDoubleShotCombat(player, var)
    function getDistanceDamage(player, skill, attackValue, attackFactor)
    local skill = player:getEffectiveSkillLevel(SKILL_DISTANCE)
        local level = player:getLevel()
            min = -(5*level^(1/1.5)+skill*1.5+25*2*skill/40-30)
            max = -(5*level^(1/1.5)+skill*1.5+25*2*skill/40-30)
        return min, max
    end
    local item = player:getSlotItem(CONST_SLOT_AMMO) or player:getSlotItem(CONST_SLOT_LEFT) or player:getSlotItem(CONST_SLOT_RIGHT)
    combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "getDistanceDamage")
    combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, magicEffect)
    combat:setParameter(COMBAT_PARAM_TYPE, dmgType)
    combat:execute(player, var)
    item:remove(0)
    return true
end
local function doDoubleShot(player, var)
local leftHand = pushThing(player:getSlotItem(CONST_SLOT_LEFT)).itemid
local rightHand = pushThing(player:getSlotItem(CONST_SLOT_RIGHT)).itemid
local ammoSlot = pushThing(player:getSlotItem(CONST_SLOT_AMMO)).itemid
    dmgType = damageType[ammoSlot] or damageType[leftHand] or damageType[rightHand]
    if(isInArray(Crossbows, leftHand) or isInArray(Crossbows, rightHand)) then
        if(isInArray(Bolts, ammoSlot)) then
            magicEffect = animation[ammoSlot]
            return doDoubleShotCombat(player, var)
        else
            return player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You need bolts")
        end
    elseif(isInArray(Bows, leftHand) or isInArray(Bows, rightHand)) then
        if(isInArray(Arrows, ammoSlot)) then
            magicEffect = animation[ammoSlot]
            return doDoubleShotCombat(player, var)
        else
            return player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You need arrows")
        end
    elseif(isInArray(Throwables, leftHand) or isInArray(Throwables, rightHand)) then
        if(isInArray(Throwables, leftHand)) then
            magicEffect = animation[leftHand]
        else
            magicEffect = animation[rightHand]
        end
        return doDoubleShotCombat(player, var)
    end
    return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need a distance weapon")
end
local function RunPart(c,cid,var,dirList,dirEmitPos) -- Part
    if (isCreature(cid)) then
        doCombat(cid, c, var)
        if (dirList ~= nil) then -- Emit distance effects
            local i = 2;
            while (i < #dirList) do
                doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x-dirList[i],y=dirEmitPos.y-dirList[i+1],z=dirEmitPos.z},dirList[1])
                i = i + 2
            end     
        end
    end
end
--doDoubleShot(player, var),
function onCastSpell(player, var, cid)
    local startPos = getCreaturePosition(cid)
addEvent(RunPart,800,doDoubleShot(player, var),cid,startPos)
addEvent(RunPart,600,doDoubleShot(player, var),cid,startPos)
addEvent(RunPart,400,doDoubleShot(player, var),cid,startPos)
addEvent(RunPart,200,doDoubleShot(player, var),cid,startPos)
addEvent(RunPart,0,doDoubleShot(player, var),cid,startPos)
    return true
end

This is spell what i find on OTLand, and i want to add 5 repeats of them.
But addEvent don't add delay :S i have no idea what to do...
Mby someone have an idea how to repair them?

TFS 1.2
 
addevent should look like this:
Lua:
addEvent(callback, delay)
instead you seem to have
Lua:
addEvent(func1, delay, func2(arg1, arg2), cid, startPos)
 
Actually addEvent works like this
Lua:
    addEvent(callback, delay, arguments)
So its ok to use a function as an argument as long as the function returns a value.
 
If i reduce onSpellCast to this:
Lua:
function onCastSpell(player, var)
addEvent(doDoubleShot(player, var),800)
addEvent(doDoubleShot(player, var),600)
addEvent(doDoubleShot(player, var),400)
addEvent(doDoubleShot(player, var),200)
addEvent(doDoubleShot(player, var),0)
return true

Thats work same as before, but this time console give feedback: callback parameter should be a function :S
 
Last edited:
Actually addEvent works like this
Lua:
    addEvent(callback, delay, arguments)
So its ok to use a function as an argument as long as the function returns a value.
I knew that but after a brief glance at the script I suspected that was where the issue was raised and I thought the explanation was sufficient
I am not sure what the problem is currently though
I do not know why you have
Lua:
function onCastSpell(player, var, cid)
instead of just
Lua:
function onCastSpell(player, var)
 
I knew that but after a brief glance at the script I suspected that was where the issue was raised and I thought the explanation was sufficient
I am not sure what the problem is currently though
I do not know why you have
Lua:
function onCastSpell(player, var, cid)
instead of just
Lua:
function onCastSpell(player, var)
I went through the script myself and it looks like they threw this code together like they were building a house out of legos :p
 
I knew that but after a brief glance at the script I suspected that was where the issue was raised and I thought the explanation was sufficient
I am not sure what the problem is currently though
I do not know why you have
Lua:
function onCastSpell(player, var, cid)
instead of just
Lua:
function onCastSpell(player, var)
Yep, but it doesn't matter when i delete CID there is no resoult
 
I went through the script myself and it looks like they threw this code together like they were building a house out of legos :p
Hahaha
I would do it myself but I am just doing something else at the moment
Karofel, what exactly do you want the spell to do? I could make it from scratch
 
Hahaha
I would do it myself but I am just doing something else at the moment
Karofel, what exactly do you want the spell to do? I could make it from scratch
I want spell what get u more attack speed per 1 sec (much more attack speed), or spell what will shot creature where magic effect will be the same as used arrows or throwable weapon, and when u dont use any weapon then spell dont work.

And LEGO is funny idea :D

@ Nevermind, problem solved, change function doDoubleShotCombat
to normal combat and add "addEvent" on every return in doDoubleShot function where this func want run combat. Now thats work fine without errors :) Im pretty sure, there is better way to do this, but its working... So no problem xD if something is stupid, but working, then its not stupid xD
 
Last edited:
Back
Top