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

centralize spell

RigBy

Member
Joined
Jun 9, 2015
Messages
44
Solutions
1
Reaction score
5
does anyone know how i can do to fix this spell?
Lua:
local combat = {}

local area = {
    {
        {1, 1, 1},
        {1, 3, 1},
        {1, 1, 1}
    },
    {
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 1, 0, 2, 0, 1, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 0, 0, 0, 0, 0, 0}
    },
    {
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {1, 0, 0, 0, 0, 0, 1},
        {1, 0, 0, 2, 0, 0, 1},
        {1, 0, 0, 0, 0, 0, 1},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 0, 1, 1, 1, 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, 1, 0, 0, 0, 0, 0, 1, 0, 0},
        {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
        {0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0},
        {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
        {0, 0, 1, 0, 0, 0, 0, 0, 1, 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}
    }
}


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)
    combat[i]:setArea(createCombatArea(area[i]))
end



function onCastSpell(creature, variant)
    local pos = creature:getPosition()
    Position(pos.x + 2, pos.y + 2, pos.z):sendDistanceEffect(pos, CONST_ANI_FIRE)
    Position(pos.x - 2, pos.y - 2, pos.z):sendDistanceEffect(pos, CONST_ANI_FIRE)
    Position(pos.x - 2, pos.y + 2, pos.z):sendDistanceEffect(pos, CONST_ANI_FIRE)
    Position(pos.x + 2, pos.y - 2, pos.z):sendDistanceEffect(pos, CONST_ANI_FIRE)
    
    addEvent(function()
        Position(pos.x, pos.y + 2, pos.z):sendDistanceEffect(pos, CONST_ANI_FIRE)
        Position(pos.x, pos.y - 2, pos.z):sendDistanceEffect(pos, CONST_ANI_FIRE)
        Position(pos.x + 2, pos.y, pos.z):sendDistanceEffect(pos, CONST_ANI_FIRE)
        Position(pos.x - 2, pos.y, pos.z):sendDistanceEffect(pos, CONST_ANI_FIRE)
    end, 200)
    
    
    for i = 1, #area do
        addEvent(function()
            combat[i]:execute(creature, variant)
        end, 200 * i)
    end
    
    

end
 

Attachments

OP
R

RigBy

Member
Joined
Jun 9, 2015
Messages
44
Solutions
1
Reaction score
5
@RigBy

I believe the issue is in your spells.xml.
You have it set as direction="1" and not selftarget="1"
I think I must have explained it wrong, when I use a spell and walk, as it is an event, the spell accompanied, I wanted it to cast in the same place I cast the spell first
 

Pox

Intermediate OT User
Joined
Apr 28, 2020
Messages
147
Solutions
8
Reaction score
123
I think I must have explained it wrong, when I use a spell and walk, as it is an event, the spell accompanied, I wanted it to cast in the same place I cast the spell first
Ok, so remove all selftarget, direction in spells.xml

Send the line here if you dont understand what I mean and I’ll help you edit it. ☺️
 

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,730
Solutions
17
Reaction score
405
Location
Poland
GitHub
FreshyPeshy
Here, fixed :
Lua:
local castedPlacePos = nil
local combat = {}
local area = {
    {
        {1, 1, 1},
        {1, 3, 1},
        {1, 1, 1}
    },
    {
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 1, 0, 2, 0, 1, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 0, 0, 0, 0, 0, 0}
    },
    {
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {1, 0, 0, 0, 0, 0, 1},
        {1, 0, 0, 2, 0, 0, 1},
        {1, 0, 0, 0, 0, 0, 1},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 0, 1, 1, 1, 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, 1, 0, 0, 0, 0, 0, 1, 0, 0},
        {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
        {0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0},
        {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
        {0, 0, 1, 0, 0, 0, 0, 0, 1, 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}
    }
}
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)
    combat[i]:setArea(createCombatArea(area[i]))
end
function onCastSpell(creature, variant)
    castedPlacePos = creature:getPosition()
    Position(castedPlacePos.x + 2, castedPlacePos.y + 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
    Position(castedPlacePos.x - 2, castedPlacePos.y - 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
    Position(castedPlacePos.x - 2, castedPlacePos.y + 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
    Position(castedPlacePos.x + 2, castedPlacePos.y - 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
 
    addEvent(function()
        Position(castedPlacePos.x, castedPlacePos.y + 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
        Position(castedPlacePos.x, castedPlacePos.y - 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
        Position(castedPlacePos.x + 2, castedPlacePos.y, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
        Position(castedPlacePos.x - 2, castedPlacePos.y, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
    end, 200)
 
 
    for i = 1, #area do
        addEvent(function()
            combat[i]:execute(creature, variant)
        end, 200 * i)
    end
end
Basically you need to save Position variable only one time while spell is casted so create an variable at the beginning of the file with "local" before it so it will not be using in other scripts (that things may happen if you not define variable as local).
Then, you just sign caster (creature) position to it in onCastSpell only once, then you can use it in addEvents (which are created extremely bad and may cause crashes).

But yeah, that's pretty much all.

Because of saving position like that you will have an static spell in place where you casted the spell.
 
Last edited:

Pox

Intermediate OT User
Joined
Apr 28, 2020
Messages
147
Solutions
8
Reaction score
123
Here, fixed :
Lua:
local castedPlacePos = nil
local combat = {}
local area = {
    {
        {1, 1, 1},
        {1, 3, 1},
        {1, 1, 1}
    },
    {
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 1, 0, 2, 0, 1, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 0, 0, 0, 0, 0, 0}
    },
    {
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {1, 0, 0, 0, 0, 0, 1},
        {1, 0, 0, 2, 0, 0, 1},
        {1, 0, 0, 0, 0, 0, 1},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 0, 1, 1, 1, 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, 1, 0, 0, 0, 0, 0, 1, 0, 0},
        {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
        {0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0},
        {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
        {0, 0, 1, 0, 0, 0, 0, 0, 1, 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}
    }
}
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)
    combat[i]:setArea(createCombatArea(area[i]))
end
function onCastSpell(creature, variant)
    castedPlacePos = creature:getPosition()
    Position(castedPlacePos.x + 2, castedPlacePos.y + 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
    Position(castedPlacePos.x - 2, castedPlacePos.y - 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
    Position(castedPlacePos.x - 2, castedPlacePos.y + 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
    Position(castedPlacePos.x + 2, castedPlacePos.y - 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
 
    addEvent(function()
        Position(castedPlacePos.x, castedPlacePos.y + 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
        Position(castedPlacePos.x, castedPlacePos.y - 2, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
        Position(castedPlacePos.x + 2, castedPlacePos.y, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
        Position(castedPlacePos.x - 2, castedPlacePos.y, castedPlacePos.z):sendDistanceEffect(castedPlacePos, CONST_ANI_FIRE)
    end, 200)
 
 
    for i = 1, #area do
        addEvent(function()
            combat[i]:execute(creature, variant)
        end, 200 * i)
    end
end
Basically you need to save Position variable only one time while spell is casted so create an variable at the beginning of the file with "local" before it so it will not be using in other scripts (that things may happen if you not define variable as local).
Then, you just sign caster (creature) position to it in onCastSpell only once, then you can use it in addEvents (which are created extremely bad and may cause crashes).

But yeah, that's pretty much all.

Because of saving position like that you will have an static spell in place where you casted the spell.

Using the original script and just doing this in xml
XML:
    <instant group="attack" spellid="50" name="Test Spell" words="test spell" level="80" mana="65" premium="0" aggressive="1" cooldown="4000" groupcooldown="2000" needlearn="1" script="test_spell.lua">
        <vocation name="Sorcerer" />
    </instant>

No selftarget, direction or casterTargetOrDirection set and it will stay on the casting spot, even if player move. So no need to save extra variables, just FYI
 

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,730
Solutions
17
Reaction score
405
Location
Poland
GitHub
FreshyPeshy
Using the original script and just doing this in xml
XML:
    <instant group="attack" spellid="50" name="Test Spell" words="test spell" level="80" mana="65" premium="0" aggressive="1" cooldown="4000" groupcooldown="2000" needlearn="1" script="test_spell.lua">
        <vocation name="Sorcerer" />
    </instant>

No selftarget, direction or casterTargetOrDirection set and it will stay on the casting spot, even if player move. So no need to save extra variables, just FYI

1627484547553.png

(...) and it will stay on the casting spot, even if player move. (...)

1627484567410.png

He wanted to works like I fixed - you cast the spell and the spell is going on in place where it was casted. So what's wrong because I don't understand?
 

Pox

Intermediate OT User
Joined
Apr 28, 2020
Messages
147
Solutions
8
Reaction score
123
View attachment 60687



View attachment 60688

He wanted to works like I fixed - you cast the spell and the spell is going on in place where it was casted. So what's wrong because I don't understand?

Yes and try what I wrote, original script and the xml snippet.
Works the same as saving the location without saving the location.

Nothing wrong with your script, just wrote an FYI(for your information) that it works the same if you didn’t know how spells work without selftarget or direction set.
 
OP
R

RigBy

Member
Joined
Jun 9, 2015
Messages
44
Solutions
1
Reaction score
5
sorry for the inconvenience, it's just that I don't speak English well and i ended up getting confused, but it worked the way Pox did.

thanks also Fresco, it helped me in another script kkkk

thank you all
 
Top