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

New project - questions about programming C++ & Lua

Nowix93

New Member
Joined
Feb 25, 2017
Messages
32
Reaction score
0
[TFS 1.3]
Hello OTpeople,
I start my ot projekt and i will have probably a lot of questions.
Ofc i will use before ask "search" but when it doesnt help i will ask in this topic :)
i learning form 2 month c++ for this and now i start with lua too, i know its nothing but step by step so
i start learnig TFS source how its work, there is a lot of everything ;x
ok, lets go to the firsts questions
1)
Code:
COMBAT_PHYSICALDAMAGE = 1 << 0, COMBAT_ENERGYDAMAGE = 1 << 1, COMBAT_EARTHDAMAGE = 1 << 2, COMBAT_FIREDAMAGE = 1 << 3, COMBAT_UNDEFINEDDAMAGE = 1 << 4, COMBAT_LIFEDRAIN = 1 << 5, COMBAT_MANADRAIN = 1 << 6, COMBAT_HEALING = 1 << 7, COMBAT_DROWNDAMAGE = 1 << 8, COMBAT_ICEDAMAGE = 1 << 9, COMBAT_HOLYDAMAGE = 1 << 10, COMBAT_DEATHDAMAGE = 1 << 11,
in enums there are a lot of (example)1 << 11
that mean something? highter priority dmg In this case ? its probably not necessary but i'm curious ;x
2)
i want create simple spell with funcion (creature:getDirection) to check where the player is looking and set area dmg for that but i stuck , and i want to get 2 more options before cast, first dont atack just stay in 500ms i create for it CONDITION_CAST and second for cast animatin on me best option is the character was invisible first what functions should I use for this?
My simple ofc dont working spell
Code:
-- Delay between animations.
local animationDelay = 200
local combat = {}

local north = 0
local east = 1
local south = 2
local west = 3

-- Frames (1 = Area, 2 = Player, 3 = Player + Self Damaging)
local area0 = {
    {
        {1, 0, 0},
        {0, 2, 0},
        {0, 0, 0}
    },
    {
        {0, 1, 0},
        {0, 2, 0},
        {0, 0, 0}
    },
    {
        {0, 0, 1},
        {0, 2, 0},
        {0, 0, 0}
    }
}

local area1 = {
    {
        {0, 0, 1},
        {0, 2, 0},
        {0, 0, 0}
    },
    {
        {0, 0, 0},
        {0, 2, 1},
        {0, 0, 0}
    },
    {
        {0, 0, 0},
        {0, 2, 0},
        {0, 0, 1}
    }
}

local area2 = {
    {
        {0, 0, 0},
        {0, 2, 0},
        {0, 0, 1}
    },
    {
        {0, 0, 0},
        {0, 2, 0},
        {0, 1, 0}
    },
    {
        {0, 0, 0},
        {0, 2, 0},
        {1, 0, 0}
    }
}

local area3 = {
    {
        {0, 0, 0},
        {0, 2, 0},
        {1, 0, 0}
    },
    {
        {0, 0, 0},
        {1, 2, 0},
        {0, 0, 0}
    },
    {
        {1, 0, 0},
        {0, 2, 0},
        {0, 0, 0}
    }
}
    local x
    local cDir = creature:getDirection()
    if     cDir == north then
    x = area0
   
    elseif cDir == east then
    x = area1
   
    elseif cDir == south then
    x = area2
   
    elseif cDir == west then
    x = area3
    end

    local area = x

for i = 1, #area do
    combat[i] = Combat()
    combat[i]:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
    combat[i]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
end

for x, _ in ipairs(area) do
    combat[x]:setArea(createCombatArea(area[x]))
end

function executeCombat(p, i)
    if not p.player then
        return false
    end
    if not p.player:isPlayer() then
            return false
    end
    p.combat[i]:execute(p.player, p.var)
end

function onCastSpell(player, var)

    local p = {player = player, var = var, combat = combat}

    -- Damage formula
    local level = player:getLevel()
    local maglevel = player:getMagicLevel()
    local min = (level / 5) + (maglevel * 1.4) + 8
    local max = (level / 5) + (maglevel * 2.2) + 14

    for i = 1, #area do
        combat[i]:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, -min, 0, -max)
        if i == 1 then
            combat[i]:execute(player, var)
        else
            addEvent(executeCombat, (animationDelay * i) - animationDelay, p, i)
        end
    end

    return true
end

I will have many questions so I do not know if setting up a topic in good place if not please transfer :)
 
Last edited:
@Delusion thx i read a little about bitwise shift but its to early for me to know how to use it.
so to the second question
i want this little wave(animation and dmg) be in the front from player, i mean when im turn north dmg is from above player
\/ this is first version before i try use more area
GIF.gif

how to write this part
local x
local cDir = creature:getDirection()
if cDir == north then
x = area0

elseif cDir == east then
x = area1

elseif cDir == south then
x = area2

elseif cDir == west then
x = area3
end

local area = x
but i have this in consol
Code:
data/spells/scripts/custom/qwe.lua
data/spells/scripts/custom/qwe.lua:83: attempt to index global 'creature' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/custom/qwe.lua:83: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/custom/qwe.lua

and i have one more question about how use two effect on me i mean first is to get invisible for a second, getmagiceffect() is currect function?
and the same time when im disappeared i wanton on me one more effect (i mean any animation) for maybe one second.
 
Last edited:
someone know how to set up this direction?
i try many options like

Code:
local cDir = {
    [DIRECTION_NORTH] = area0,
    [DIRECTION_EAST] = area1,
    [DIRECTION_SOUTH] = area2,
    [DIRECTION_WEST] = area3
}

creature:getPosition():combat():setArea(cDir[creature:getDirection()])
in consol

Code:
data/spells/scripts/custom/qwe.lua:108: attempt to index global 'creature' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/custom/qwe.lua:108: in main chunk
and

Code:
local cDir = {
    [DIRECTION_NORTH] = combat:setArea(area0),
    [DIRECTION_EAST] = combat:setArea(area1),
    [DIRECTION_SOUTH] = combat:setArea(area2),
    [DIRECTION_WEST] = combat:setArea(area3)
}

local area = creature:getDirection()
consol
Code:
data/spells/scripts/custom/qwe.lua:102: attempt to call method 'setArea' (a nil value)
stack traceback:
        [C]: in function 'setArea'
        data/spells/scripts/custom/qwe.lua:102: in main chunk
else
Code:
for i = 1, #area0 do
    combat[i] = Combat()
    combat[i]:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
    combat[i]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)

for j = 1, #area1 do
    combat[j] = Combat()
    combat[j]:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
    combat[j]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
for k = 1, #area2 do
    combat[k] = Combat()
    combat[k]:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
    combat[k]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
for l = 1, #area3 do
    combat[l] = Combat()
    combat[l]:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
    combat[l]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)


   
    local cDir = {
    [DIRECTION_NORTH] = combat:setArea(area0),
    [DIRECTION_EAST] = combat:setArea(area1),
    [DIRECTION_SOUTH] = combat:setArea(area2),
    [DIRECTION_WEST] = combat:setArea(area3)
}
end
end
end
end
local area = creature:getDirection()
--creature:getPosition():combat:setArea(cDir[creature:getDirection()])
but still
Lua Script Error: [Test Interface]
data/spells/scripts/custom/qwe.lua
data/spells/scripts/custom/qwe.lua:122: attempt to call method 'setArea' (a nil value)

What i need to send in (combat) here [DIRECTION_NORTH] = combat:setArea(area0)
nothing work ;/
 
Last edited:
i understand some of my mistake and try a lot other option but nothing work.
i finish today with this part, it's probably closest think what i want

Code:
local north = 0
    local east = 1
    local south = 2
    local west = 3
    --local creature = creature:getid()
   
    function gd()
   
    --local creature = player(cid)
    local creature = creature:getid()
    local cDir = creature:getDirection()
    local cPos = creature:getPosition ()
    local pos = (Position(0,0,0))
    if     cDir == north then
        if not getTileInfo(cPos).house and not getTilePzInfo(cPos) then
        for i, _ in ipairs(area0) do
            area[i] = area0[i]
        end  
        end
    elseif cDir == east then
        if not getTileInfo(cPos).house and not getTilePzInfo(cPos) then
            for i, _ in ipairs(area1) do
            area[i] = area1[i]
        end
        end
    elseif cDir == south then
        if not getTileInfo(cPos).house and not getTilePzInfo(cPos) then
            for i, _ in ipairs(area2) do
            area[i] = area2[i]
        end
        end
    elseif cDir == west then
        if not getTileInfo(cPos).house and not getTilePzInfo(cPos) then
        for i, _ in ipairs(area3) do
            area[i] = area3[i]
        end
        end
        end
        return area
        end
       
        local area = gd()
in consol attempt to index global 'creature' (a nil value)
so someone can tell me how i can get it?
i try many think and what you can see in code like (creature:getid()) but i dont know how this engine work ;x
what function can work well here?
 
Hello everyone today i have two questions about ~my spell
Lua:
-- Delay between animations.
local animationDelay = 200
local stunDuration = 2000
local invANDcastDuration = 400
local combat = {}

-- cast
local     cast = Condition(CONDITION_CAST)
        cast:setParameter(CONDITION_PARAM_TICKS, invANDcastDuration)
        cast:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_NONE)

-- invisible
local     invisible = Condition(CONDITION_INVISIBLE)
        invisible:setParameter(CONDITION_PARAM_TICKS, invANDcastDuration)
        --invisible:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
        --invisible:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

-- bleeding
local     bleeding = Condition(CONDITION_BLEEDING)
        bleeding:setParameter(CONDITION_PARAM_DELAYED, 5)
        bleeding:addDamage(5, 1000, 10)

-- stun
local     stun = Condition(CONDITION_STUN)
        stun:setParameter(CONDITION_PARAM_TICKS, stunDuration)
        stun:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_BUBBLES)


-- Frames (1 = Area, 2 = Player, 3 = Player + Self Damaging)
local area = {
     {
        {0, 0, 0},
        {0, 2, 0},
        {0, 0, 0}
    },
    {
        {0, 0, 0},
        {0, 3, 0},
        {0, 0, 0}
    }
}

function bleedmath(p, i)
math.randomseed(os.time())
local bleed = math.random(100)
--print(bleed)
    if bleed < 30 then
    p.combat[I]:addCondition(bleeding)
end
end

-- if Player then /2
function stuns(p)
   for y, _ in ipairs(area) do
        p.combat[y]:addCondition(stun)
        --local creature = p.combat[y]:getCreatures()
        --local pla = area[y]:getPosition()
        if     area[y]:isPlayer() then
            stunDuration = 10000    
        end
    end
end

for i = 1, #area do
    combat[I] = Combat()
    combat[I]:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    combat[I]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
    --combat[I]:addCondition(stun)
end

for x, _ in ipairs(area) do
    combat[x]:setArea(createCombatArea(area[x]))
end

function executeCombat(p, i)
    if not p.player then
        return false
    end
    if not p.player:isPlayer() then
            return false
    end    
    p.combat[I]:execute(p.player, p.var)
end

function onCastSpell(player, var)

    
    local p = {player = player, var = var, combat = combat}    
    
    -- Damage formula
    local level = player:getLevel()
    local maglevel = player:getMagicLevel()
    local min = (level / 5) + (maglevel * 1.4) + 8
    local max = (level / 5) + (maglevel * 2.2) + 14
    
    doAddCondition(p.player, invisible)
    doAddCondition(p.player, cast)
    stuns(p)
    
    
    for i = 1, #area do
        combat[I]:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, -min, 0, -max)
        if i == 1 then
            combat[I]:execute(player, var)
        else
            --bleedmath(p, i)
            addEvent(executeCombat, (animationDelay * i) - animationDelay, p, i)
            end
    end

    return true
end
1) i have problem with hit position in area, when set like this
Code:
  {0, 1, 0}
  {0, 2, 0}
  {0, 0, 0}
so i want hit something in front of me but it's look like that
GIF.gif
i dont know why ;x ofc i can just use 3 in here but it doesnt solve my problem.

2) i want check area in funcion stuns for chenging stun duration but all time i got
attempt to call method 'isPlayer' (a nil value)
i traied somthing like this
Lua:
function stuns(p)
    for i, _ in ipairs(area) do
        p.combat[i]:addCondition(stun)
        --local creature = p.combat[i]:getCreatures()
        local pla = p.combat[i]:getPosition()
        if     pla:isPlayer() then
            stunDuration = 10000   
        end
    end
end
Lua:
-- if Player then /2
function stuns(p)
    for y, _ in ipairs(area) do
        p.combat[y]:addCondition(stun)
        
        local pos = getSpectators(p.combat[y])
        local creature = pos:getCreatures()
        local pla = creature:getPosition()
        if     pla:isPlayer() then
            stunDuration = 10000    
        end
    end
end
and nothing work, can someone explain this?
i check other spells but they use there just creature:isPlayer() and it work, in my spell i traied too use just p.player:isPlayer() and i dont have errors but that dont change stun duration ;/
 
Last edited:
what I have to do to make this fragment work?
Can someone help me with it i tried everything but i dont to how to do it ;/
Lua:
 -- if Player then /2
function stuns(p)
    for y, _ in ipairs(area) do
        p.combat[y]:addCondition(stun)        
        if     p.player:isPlayer() then
            stunDuration = 10000    
        end
    end
    end
 
up
another day next attempts but effect the same
Lua:
function stuns(p)
        
        local playerPos = p.player:getPosition()
        local getTargets = Game.getSpectators(playerPos, false, false, 1, 1, 1, 1)
        
    for _,target in pairs(getTargets) do
            if not target:isNpc() then
                if     target:isPlayer() then
                    local stunDuration = 10000
                        target:addCondition(stun)
                        print(stunDuration, '1')
                else
                        target:addCondition(stun)
                end
                print(stunDuration, '2')
            end       
    end
end
What i doing wrong, tell me pls ;x
 
Back
Top