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

Spell which damages only certain vocation

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
932
Solutions
10
Reaction score
295
Location
Poland
Hello, I need help in fixing my spell which should damage only certain vocation, for this example it is knight. Spell works but it still damages any other vocation. I hope someone will show me what I did wrong. I will add at the end I'm not good or even beginner at scripting, hehe.
Code:
local playerVoc = getPlayerVocation(cid)
if playerVoc == 4 or playerVoc == 8 then
return true
end
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

local area = createCombatArea(AREA_CIRCLE3X3)
    setCombatArea(combat, area)


function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
 
There is no (LUA logic) shorter way.

Code:
-- you have to edit min and max dmg in 38th line

local voc = {
    1, 2, 3, 5, 6, 7 -- the spell is dealing dmg to these voc ids
}

local area = createCombatArea({
    {0, 1, 1, 1, 0},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1, 1},
    {1, 1, 1, 1, 1},
    {0, 1, 1, 1, 0}
})

local combat = createCombatObject()
setCombatArea(combat, area)

function onTargetTile(cid, pos)
    local creatureTable = {}
    local n, i = getTileInfo({x=pos.x, y=pos.y, z=pos.z}).creatures, 1
    if n ~= 0 then
        local v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        while v ~= 0 do
            if isCreature(v) == true then
                table.insert(creatureTable, v)
                if n == #creatureTable then
                    break
                end
            end
            i = i + 1
            v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        end
    end
    if #creatureTable ~= nil and #creatureTable > 0 then
        for r = 1, #creatureTable do
            if creatureTable[r] ~= cid then
                local min = -(getPlayerMagLevel(cid) * 4) * 1.0
                local max = -(getPlayerMagLevel(cid) * 4) * 1.8
                if isPlayer(creatureTable[r]) == true and isInArray(voc, getPlayerVocation(cid)) == true then
                    doTargetCombatHealth(cid, creatureTable[r], COMBAT_FIREDAMAGE, min, max, CONST_ME_NONE)
                elseif isMonster(creatureTable[r]) == true then
                    doTargetCombatHealth(cid, creatureTable[r], COMBAT_FIREDAMAGE, min, max, CONST_ME_NONE)
                end
            end
        end
    end
    doSendMagicEffect(pos, CONST_ME_HITBYFIRE)
    return true
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    doCombat(cid, combat, var)
    return true
end
 
There is no (LUA logic) shorter way.

Code:
-- you have to edit min and max dmg in 38th line

local voc = {
    1, 2, 3, 5, 6, 7 -- the spell is dealing dmg to these voc ids
}

local area = createCombatArea({
    {0, 1, 1, 1, 0},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1, 1},
    {1, 1, 1, 1, 1},
    {0, 1, 1, 1, 0}
})

local combat = createCombatObject()
setCombatArea(combat, area)

function onTargetTile(cid, pos)
    local creatureTable = {}
    local n, i = getTileInfo({x=pos.x, y=pos.y, z=pos.z}).creatures, 1
    if n ~= 0 then
        local v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        while v ~= 0 do
            if isCreature(v) == true then
                table.insert(creatureTable, v)
                if n == #creatureTable then
                    break
                end
            end
            i = i + 1
            v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        end
    end
    if #creatureTable ~= nil and #creatureTable > 0 then
        for r = 1, #creatureTable do
            if creatureTable[r] ~= cid then
                local min = -(getPlayerMagLevel(cid) * 4) * 1.0
                local max = -(getPlayerMagLevel(cid) * 4) * 1.8
                if isPlayer(creatureTable[r]) == true and isInArray(voc, getPlayerVocation(cid)) == true then
                    doTargetCombatHealth(cid, creatureTable[r], COMBAT_FIREDAMAGE, min, max, CONST_ME_NONE)
                elseif isMonster(creatureTable[r]) == true then
                    doTargetCombatHealth(cid, creatureTable[r], COMBAT_FIREDAMAGE, min, max, CONST_ME_NONE)
                end
            end
        end
    end
    doSendMagicEffect(pos, CONST_ME_HITBYFIRE)
    return true
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    doCombat(cid, combat, var)
    return true
end
Thanks for the script, but it does damage only to monsters no matter if I put all vocations in table or not. I'm using theforgottenserver-v0.2.15-win32gui if it matters. I'm taking damage when I remove 'isInArray(voc, getPlayerVocation(cid))) == true' part.
 
What if I want to add a cooldown to cast spell for example:
I start to cast spell - 'text message appears' and after 4 sec the whole spell is executed? Is it possible?
 
It's possible. I did the Casting Time System (available to buy). It's sth like this:
Code:
doCastingtimeSpell(cid, combat, var, time)

Also it adds casting bar on the player's screen while he is casting a spell.
The System contains over 5 new functions. It is in LUA, you don't have to edit sources.
 
Code:
function onCreatureSay(cid, speak, talktype, text)
    local SpellText ="Works!"
    if (text == SpellText and talktype == 35) then
        addEvent(StartSpell, 10000, cid)
           
    end
    end

function StartSpell(cid)
local voc = {4, 8}

local area = createCombatArea(AREA_CIRCLE3X3)

local combat = createCombatObject()
setCombatArea(combat, area)

function onTargetTile(cid, pos)
    local creatureTable = {}
    local n, i = getTileInfo({x=pos.x, y=pos.y, z=pos.z}).creatures, 1
    if n ~= 0 then
        local v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        while v ~= 0 do
            if isCreature(v) == true then
                table.insert(creatureTable, v)
                if n == #creatureTable then
                    break
                end
            end
            i = i + 1
            v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        end
    end
    if #creatureTable ~= nil and #creatureTable > 0 then
        for r = 1, #creatureTable do
            if creatureTable[r] ~= cid then
                local min = 300
                local max = 500
                if isPlayer(creatureTable[r]) == true and isInArray(voc, getPlayerVocation(creatureTable[r])) == true then
                    doTargetCombatHealth(cid, creatureTable[r], COMBAT_FIREDAMAGE, -min, -max, CONST_ME_NONE)
                elseif isMonster(creatureTable[r]) == true then
                    doTargetCombatHealth(cid, creatureTable[r], COMBAT_FIREDAMAGE, -min, -max, CONST_ME_NONE)
                end
            end
        end
    end
    doSendMagicEffect(pos, CONST_ME_HITBYFIRE)
    return true
end
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    doCombat(cid, combat, var)
    return true
end

Made something like this, but it dont work.

That's the error.
Code:
[21/04/2014 19:29:26] Lua Script Error: [Spell Interface]
[21/04/2014 19:29:26] data/spells/scripts/monster/test spell.lua:onCastSpell
[21/04/2014 19:29:26] LuaScriptInterface::luaDoCombat(). Combat not found
[21/04/2014 19:29:26] stack traceback:
[21/04/2014 19:29:26]    [C]: in function 'doCombat'
[21/04/2014 19:29:26]    data/spells/scripts/monster/test spell.lua:54: in function <data/spells/scripts/monster/test spell.lua:53>
 
Without my casting system, but with normal addEvent

Code:
-- you have to edit min and max dmg in 38th line

local voc = {
    1, 2, 3, 5, 6, 7 -- the spell is dealing dmg to these voc ids
}

local area = createCombatArea({
    {0, 1, 1, 1, 0},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1, 1},
    {1, 1, 1, 1, 1},
    {0, 1, 1, 1, 0}
})

local combat = createCombatObject()
setCombatArea(combat, area)

function onTargetTile(cid, pos)
    local creatureTable = {}
    local n, i = getTileInfo({x=pos.x, y=pos.y, z=pos.z}).creatures, 1
    if n ~= 0 then
        local v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        while v ~= 0 do
            if isCreature(v) == true then
                table.insert(creatureTable, v)
                if n == #creatureTable then
                    break
                end
            end
            i = i + 1
            v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        end
    end
    if #creatureTable ~= nil and #creatureTable > 0 then
        for r = 1, #creatureTable do
            if creatureTable[r] ~= cid then
                local min = -(getPlayerMagLevel(cid) * 4) * 1.0
                local max = -(getPlayerMagLevel(cid) * 4) * 1.8
                if isPlayer(creatureTable[r]) == true and isInArray(voc, getPlayerVocation(cid)) == true then
                    doTargetCombatHealth(cid, creatureTable[r], COMBAT_FIREDAMAGE, min, max, CONST_ME_NONE)
                elseif isMonster(creatureTable[r]) == true then
                    doTargetCombatHealth(cid, creatureTable[r], COMBAT_FIREDAMAGE, min, max, CONST_ME_NONE)
                end
            end
        end
    end
    doSendMagicEffect(pos, CONST_ME_HITBYFIRE)
    return true
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

local function delayedCastSpell(cid, var)
    if isCreature(cid) == true then
        doCombat(cid, combat, var)
    end
end

function onCastSpell(cid, var)
    doCreatureSay(cid, "hEEEEYAAAA", TALKTYPE_MONSTER)
    --doSendAnimatedText(getCreaturePosition(cid), text, TEXTCOLOR_YELLOW)
    addEvent(delayedCastSpell, 4000, cid, var)
    return true
end
 
Back
Top