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

Solved [Spell] Storm of the Century | attempt to index field '?' (a nil value)

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,791
Solutions
581
Reaction score
5,354
I've been trying to modify Storm of the Century to work with 0.3.7.. however a few errors keep popping up and I'm not sure how to fix them.
In the edited spell MindRage gave some advise to add some [i.] into the spell to fix the original error message, however the thread has gone dead since then.
My plan is to update the thread with a working 0.3.7 version of the script, however we just need to get it working first! :p

Code:
local config = {
minAttacks = 100, --Change the minimum number of attacks here
maxAttacks = 300, --Change the maximum number of attacks here
expansionInterval = 300, --Change here how many ms it takes at max between expansions(it can be a random value between 0 and this value)
spreadPercent = 20, --Change here the expansion %
combatType = COMBAT_ENERGYDAMAGE, --Change here the combat type
effectType = { {90, 10}, {CONST_ME_ENERGYHIT, CONST_ME_BIGCLOUDS} } --Change here the effect types, in the first table you set the chance of each effect to happen(must always sum to 100) and in the second table you set what effects appear
}


local function damageFormula(cid)
local minDmg = (getPlayerLevel(cid) / -5 + getPlayerMagLevel(cid) * 1) * -5 + -5
local maxDmg = (getPlayerLevel(cid) / -5 + getPlayerMagLevel(cid) * 1) * -5 + -12
return {min = minDmg, max = maxDmg}
end


local function stormSpreads(cid, pos, remainingArea)
if remainingArea[1] <= 0 or not isCreature(cid) then
return false
end
remainingArea[1] = remainingArea[1] - 1
local dmg = damageFormula(cid)
--Random effect calculation
local eff = config.effectType[2][1]
local efc = math.random(1, 100)
for i = 1, #config.effectType[1] do
if(efc < config.effectType[1]) then
eff = config.effectType[2]
break
else
efc = efc - config.effectType[1]
end
end
--/Random effect calculation
doCombatAreaHealth(cid, config.combatType, pos, nil, dmg.min, dmg.max, eff)
--Random area calculations
local posArray = {
[1] = {{x = pos.x, y = pos.y - 1, z = pos.z}, {2,4}}, --North
[2] = {{x = pos.x - 1, y = pos.y, z = pos.z}, {1,3}}, --East
[3] = {{x = pos.x, y = pos.y + 1, z = pos.z}, {2,4}}, --South
[4] = {{x = pos.x + 1, y = pos.y, z = pos.z}, {1,3}} --West
}
local i = math.random(1, 4)
addEvent(stormSpreads, config.expansionInterval, cid, posArray[1], remainingArea, i)
if math.random(1, 100) <= config.spreadPercent then
if isSightClear(pos, posArray[posArray[2][1]][1], true) then
addEvent(stormSpreads, math.random(0, config.expansionInterval), cid, posArray[posArray[2][1]][1], remainingArea, i)
end
end
if math.random(1, 100) <= config.spreadPercent then
if isSightClear(pos, posArray[posArray[2][2]][1], true) then
addEvent(stormSpreads, math.random(0, config.expansionInterval), cid, posArray[posArray[2][2]][1], remainingArea, i)
end
end
--/Random area calculations
return true
end


function onCastSpell(cid, var)
return stormSpreads(cid, getCreaturePosition(cid), {math.random(config.minAttacks, config.maxAttacks)})
end
Code:
local config = {
minAttacks = 200, --Change the minimum number of attacks here
maxAttacks = 300, --Change the maximum number of attacks here
expansionInterval = 150, --Change here how many ms it takes at max between expansions(it can be a random value between 0 and this value)
spreadPercent = 40, --Change here the expansion %
combatType = COMBAT_ENERGYDAMAGE, --Change here the combat type
effectType = { {90, 10}, {CONST_ME_ENERGYHIT, CONST_ME_BIGCLOUDS} } --Change here the effect types, in the first table you set the chance of each effect to happen(must always sum to 100) and in the second table you set what effects appear
}


local function damageFormula(cid)
local minDmg = (getPlayerLevel(cid) / -5 + getPlayerMagLevel(cid) * 1) * -5 + -5
local maxDmg = (getPlayerLevel(cid) / -5 + getPlayerMagLevel(cid) * 1) * -5 + -12
return {min = minDmg, max = maxDmg}
end


local function stormSpreads(cid, pos, remainingArea)
if remainingArea[1] <= 0 or not isCreature(cid) then
return false
end
remainingArea[1] = remainingArea[1] - 1
local dmg = damageFormula(cid)
--Random effect calculation
local eff = config.effectType[2][1]
local efc = math.random(1, 100)
for i = 1, #config.effectType[1] do
if(efc < config.effectType[1][i]) then
  eff = config.effectType[2][i]
  break
else
  efc = efc - config.effectType[1][i]
end
end
--/Random effect calculation
doCombatAreaHealth(cid, config.combatType, pos, nil, dmg.min, dmg.max, eff)
--Random area calculations
local posArray = {
[1] = {{x = pos.x, y = pos.y - 1, z = pos.z}, {2,4}}, --North
[2] = {{x = pos.x - 1, y = pos.y, z = pos.z}, {1,3}}, --East
[3] = {{x = pos.x, y = pos.y + 1, z = pos.z}, {2,4}}, --South
[4] = {{x = pos.x + 1, y = pos.y, z = pos.z}, {1,3}} --West
}
local i = math.random(1, 4)
addEvent(stormSpreads, config.expansionInterval, cid, posArray[1], remainingArea, i)
if math.random(1, 100) <= config.spreadPercent then
if isSightClear(pos, posArray[posArray[2][1]][1], true) then
addEvent(stormSpreads, math.random(0, config.expansionInterval), cid, posArray[posArray[2][1]][1], remainingArea, i)
end
end
if math.random(1, 100) <= config.spreadPercent then
if isSightClear(pos, posArray[posArray[2][2]][1], true) then
addEvent(stormSpreads, math.random(0, config.expansionInterval), cid, posArray[posArray[2][2]][1], remainingArea, i)
end
end
--/Random area calculations
return true
end


function onCastSpell(cid, var)
return stormSpreads(cid, getCreaturePosition(cid), {math.random(config.minAttacks, config.maxAttacks)})
end
Code:
<instant name="storm of the century" words="lmaorofl" lvl="10" mana="45" prem="0" range="3" casterTargetOrDirection="1" blockwalls="1" exhaustion="3000" groups="1,1000" icon="89" needlearn="0" event="script" value="wizard skills/storm of the century.lua">
<vocation id="1"/>
<vocation id="9"/>
<vocation id="25"/>
<vocation id="26"/>
<vocation id="27"/>
</instant>
Code:
[6:11:43.653] [Error - Spell Interface]
[6:11:43.654] data/spells/scripts/wizard skills/storm of the century.lua:onCastSpell
[6:11:43.655] Description:
[6:11:43.656] ...pells/scripts/wizard skills/storm of the century.lua:52: attempt to index field '?' (a nil value)
[6:11:43.656] stack traceback:
[6:11:43.657] ...pells/scripts/wizard skills/storm of the century.lua:52: in function <...pells/scripts/wizard skills/storm of the century.lua:18>
[6:11:43.657] (tail call): ?
[6:11:43.803] [Error - Spell Interface]
[6:11:43.804] In a timer event called from:
[6:11:43.805] data/spells/scripts/wizard skills/storm of the century.lua:onCastSpell
[6:11:43.805] Description:
[6:11:43.806] ...pells/scripts/wizard skills/storm of the century.lua:39: attempt to perform arithmetic on field 'y' (a nil value)
[6:11:43.806] stack traceback:
[6:11:43.807] ...pells/scripts/wizard skills/storm of the century.lua:39: in function <...pells/scripts/wizard skills/storm of the century.lua:18>
As always,
I love you all and all comments/feedback/criticism will be taken gladly.

Xikini
 
Last edited:
Error on line 52 returns a table, you can't use a table as an index
Code:
posArray[ posArray[2][2] ][1] -- line 52

Even if you unpack the table's index value, you still have 2 numbers
Code:
local min, max = unpack(posArray[2][2]) -- returns 1 to min and 3 to max

Can't use a table or 2 numbers to index a table even if it wasn't packed you will still get an error because 1 is not a property of the table

Maybe you should rewrite it from scratch
 
The original supposedly worked on 0.4, and there is a youtube video link on the page that further suggests that it does in fact work.
I had just hoped that it might still work, and I'm still in the process of learning. (I read this sentence probably 50 times a day in this forum.)
I may partake in attempting to rewrite, or make my own variation on this script at a later date, however at this time I'm simply looking to know what is going wrong, and how it may be fixed.

In my limited studies, I've come to tables and loops, and happily enough I've been attempting to puzzle these out on my own.
I figure I might start looking into proper instruction, via webpage, or through a tutor *cough* @Limos , however I am not really sure what an arrays function is. It almost seems that a table is an elaborate array, or a variation of an array. As I've said I've had no literal training, and I honestly have not a clue what an array is.

All in all, I have little interest in the actual function of the spell beyond fixing, or understanding why it doesn't work. :p
 
There is posArray[1] and posArray[posArray[2][1]][1], after posArray, before the first number with [], add this (so after the y).
Code:
[i]
The [ i ] got removed from the script because of missing code tags, it's to get the 1, 2, 3 and 4 in the table posArray.
 
There is posArray[1] and posArray[posArray[2][1]][1], after posArray, before the first number with [], add this (so after the y).
Code:
[i]
The [ i ] got removed from the script because of missing code tags, it's to get the 1, 2, 3 and 4 in the table posArray.
I noticed this myself when attempting to use [i.]'s further up this post. It was actually fairly annoying. :p
I've tried adding the i's a couple of different ways, however all come with the same error.
It is now mostly working, however I get only this error now.
The Error.console
Code:
[6:17:21.326] [Error - Spell Interface]
[6:17:21.326] In a timer event called from:
[6:17:21.327] data/spells/scripts/wizard skills/storm of the century.lua:onCastS
pell
[6:17:21.327] Description:
[6:17:21.327] ...pells/scripts/wizard skills/storm of the century.lua:39: attemp
t to perform arithmetic on field 'y' (a nil value)
[6:17:21.327] stack traceback:
[6:17:21.327]  ...pells/scripts/wizard skills/storm of the century.lua:39: in f
unction <...pells/scripts/wizard skills/storm of the century.lua:18>

[6:17:42.679] [Error - Spell Interface]
[6:17:42.680] In a timer event called from:
[6:17:42.680] data/spells/scripts/wizard skills/storm of the century.lua:onCastS
pell
[6:17:42.680] Description:
[6:17:42.681] ...pells/scripts/wizard skills/storm of the century.lua:39: attemp
t to perform arithmetic on field 'y' (a nil value)
[6:17:42.681] stack traceback:
[6:17:42.681]  ...pells/scripts/wizard skills/storm of the century.lua:39: in f
unction <...pells/scripts/wizard skills/storm of the century.lua:18>

[6:17:42.729] [Error - Spell Interface]
[6:17:42.730] In a timer event called from:
[6:17:42.730] data/spells/scripts/wizard skills/storm of the century.lua:onCastS
pell
[6:17:42.730] Description:
[6:17:42.731] ...pells/scripts/wizard skills/storm of the century.lua:39: attemp
t to perform arithmetic on field 'y' (a nil value)
[6:17:42.731] stack traceback:
[6:17:42.731]  ...pells/scripts/wizard skills/storm of the century.lua:39: in f
unction <...pells/scripts/wizard skills/storm of the century.lua:18>

[6:17:42.785] [Error - Spell Interface]
[6:17:42.786] In a timer event called from:
[6:17:42.786] data/spells/scripts/wizard skills/storm of the century.lua:onCastS
pell
[6:17:42.786] Description:
[6:17:42.786] ...pells/scripts/wizard skills/storm of the century.lua:39: attemp
t to perform arithmetic on field 'y' (a nil value)
[6:17:42.787] stack traceback:
[6:17:42.787]  ...pells/scripts/wizard skills/storm of the century.lua:39: in f
unction <...pells/scripts/wizard skills/storm of the century.lua:18>

[6:17:42.922] [Error - Spell Interface]
[6:17:42.922] In a timer event called from:
[6:17:42.923] data/spells/scripts/wizard skills/storm of the century.lua:onCastS
pell
[6:17:42.923] Description:
[6:17:42.923] ...pells/scripts/wizard skills/storm of the century.lua:39: attemp
t to perform arithmetic on field 'y' (a nil value)
[6:17:42.924] stack traceback:
[6:17:42.924]  ...pells/scripts/wizard skills/storm of the century.lua:39: in f
unction <...pells/scripts/wizard skills/storm of the century.lua:18>

[6:17:42.972] [Error - Spell Interface]
[6:17:42.972] In a timer event called from:
[6:17:42.972] data/spells/scripts/wizard skills/storm of the century.lua:onCastS
pell
[6:17:42.973] Description:
[6:17:42.973] ...pells/scripts/wizard skills/storm of the century.lua:39: attemp
t to perform arithmetic on field 'y' (a nil value)
[6:17:42.973] stack traceback:
[6:17:42.973]  ...pells/scripts/wizard skills/storm of the century.lua:39: in f
unction <...pells/scripts/wizard skills/storm of the century.lua:18>

[6:17:43.079] [Error - Spell Interface]
[6:17:43.080] In a timer event called from:
[6:17:43.080] data/spells/scripts/wizard skills/storm of the century.lua:onCastS
pell
[6:17:43.080] Description:
[6:17:43.080] ...pells/scripts/wizard skills/storm of the century.lua:39: attemp
t to perform arithmetic on field 'y' (a nil value)
[6:17:43.081] stack traceback:
[6:17:43.081]  ...pells/scripts/wizard skills/storm of the century.lua:39: in f
unction <...pells/scripts/wizard skills/storm of the century.lua:18>
Current spell.lua
Code:
local config = {
minAttacks = 200, --Change the minimum number of attacks here
maxAttacks = 300, --Change the maximum number of attacks here
expansionInterval = 150, --Change here how many ms it takes at max between expansions(it can be a random value between 0 and this value)
spreadPercent = 40, --Change here the expansion %
combatType = COMBAT_ENERGYDAMAGE, --Change here the combat type
effectType = { {90, 10}, {CONST_ME_ENERGYHIT, CONST_ME_BIGCLOUDS} } --Change here the effect types, in the first table you set the chance of each effect to happen(must always sum to 100) and in the second table you set what effects appear
}


local function damageFormula(cid)
local minDmg = (getPlayerLevel(cid) / -5 + getPlayerMagLevel(cid) * 1) * -5 + -5
local maxDmg = (getPlayerLevel(cid) / -5 + getPlayerMagLevel(cid) * 1) * -5 + -12
return {min = minDmg, max = maxDmg}
end


local function stormSpreads(cid, pos, remainingArea)
if remainingArea[1] <= 0 or not isCreature(cid) then
return false
end
remainingArea[1] = remainingArea[1] - 1
local dmg = damageFormula(cid)
--Random effect calculation
local eff = config.effectType[2][1]
local efc = math.random(1, 100)
for i = 1, #config.effectType[1] do
if(efc < config.effectType[1][i]) then
  eff = config.effectType[2][i]
  break
else
  efc = efc - config.effectType[1][i]
end
end
--/Random effect calculation
doCombatAreaHealth(cid, config.combatType, pos, nil, dmg.min, dmg.max, eff)
--Random area calculations
local posArray = {
[1] = {{x = pos.x, y = pos.y - 1, z = pos.z}, {2,4}}, --North
[2] = {{x = pos.x - 1, y = pos.y, z = pos.z}, {1,3}}, --East
[3] = {{x = pos.x, y = pos.y + 1, z = pos.z}, {2,4}}, --South
[4] = {{x = pos.x + 1, y = pos.y, z = pos.z}, {1,3}} --West
}
local i = math.random(1, 4)
addEvent(stormSpreads, config.expansionInterval, cid, posArray[1], remainingArea, i)
if math.random(1, 100) <= config.spreadPercent then
if isSightClear(pos, posArray[posArray[i][2][1]][1], true) then
addEvent(stormSpreads, math.random(0, config.expansionInterval), cid, posArray[posArray[i][2][1]][1], remainingArea, i)
end
end
if math.random(1, 100) <= config.spreadPercent then
if isSightClear(pos, posArray[posArray[i][2][2]][1], true) then
addEvent(stormSpreads, math.random(0, config.expansionInterval), cid, posArray[posArray[i][2][2]][1], remainingArea, i)
end
end
--/Random area calculations
return true
end


function onCastSpell(cid, var)
return stormSpreads(cid, getCreaturePosition(cid), {math.random(config.minAttacks, config.maxAttacks)})
end
 
The original supposedly worked on 0.4, and there is a youtube video link on the page that further suggests that it does in fact work.
I had just hoped that it might still work, and I'm still in the process of learning. (I read this sentence probably 50 times a day in this forum.)
I may partake in attempting to rewrite, or make my own variation on this script at a later date, however at this time I'm simply looking to know what is going wrong, and how it may be fixed.

In my limited studies, I've come to tables and loops, and happily enough I've been attempting to puzzle these out on my own.
I figure I might start looking into proper instruction, via webpage, or through a tutor *cough* @Limos , however I am not really sure what an arrays function is. It almost seems that a table is an elaborate array, or a variation of an array. As I've said I've had no literal training, and I honestly have not a clue what an array is.

All in all, I have little interest in the actual function of the spell beyond fixing, or understanding why it doesn't work. :p
Hey the best way to learn is read and apply what you learn, that is why I try my luck at updating or fixing and sometimes writing people scripts. Anyway the more you use what you know the more you learn what is possible.. rome wasn't built in a day.

About the script, break it apart, test pieces of it little by little this is how you will resolve the issue or just rewrite it completely.

Unless a solution is all your after then i'll see what i can do if someone doesn't beat me to it
 
Hey the best way to learn is read and apply what you learn, that is why I try my luck at updating or fixing and sometimes writing people scripts. Anyway the more you use what you know the more you learn what is possible.. rome wasn't built in a day.

About the script, break it apart, test pieces of it little by little this is how you will resolve the issue or just rewrite it completely.

Unless a solution is all your after then i'll see what i can do if someone doesn't beat me to it
You forgot the one here.
Code:
addEvent(stormSpreads, config.expansionInterval, cid, posArray[1], remainingArea, i)
Limos loves me too much. :p
the completed script is here below

As for learning how to script, we all go at our own pace, and really it doesn't matter how far that takes us, or how frequently we use our knowledge, as long as it is being used and not just forgotten.

I wish everyone would be willing to learn at all times, and be able to take the time to learn and adapt and try new things and keep motivation going, however when you look at it from that perspective it's hard to maintain that level of concentration, or lack thereof during the time that you are awake. As long as you are enjoying yourself I think that's all that really matters. We all know the mentality that is needed to learn new things. We all use it day to day, either at a new job, or at a new activity, or simply doing things that we have always done. As long as your happy, whether that be helping others to improve your own knowledge, or simply doing things to entertain yourself, that should be the goal. If your attempting to master any single craft there is a simple analogy that is used. If you can spend 10,000 hours doing any activity, whether that be physical or mental, or a combination of both, you will have mastered that activity. However be wary of that term.. once you have mastered an activity, you will still never be perfect at it. There is always new heights to obtain. :p

Code:
local config = {
minAttacks = 200, --Change the minimum number of attacks here
maxAttacks = 300, --Change the maximum number of attacks here
expansionInterval = 150, --Change here how many ms it takes at max between expansions(it can be a random value between 0 and this value)
spreadPercent = 40, --Change here the expansion %
combatType = COMBAT_ENERGYDAMAGE, --Change here the combat type
effectType = { {90, 10}, {CONST_ME_ENERGYHIT, CONST_ME_BIGCLOUDS} } --Change here the effect types, in the first table you set the chance of each effect to happen(must always sum to 100) and in the second table you set what effects appear
}


local function damageFormula(cid)
local minDmg = (getPlayerLevel(cid) / -5 + getPlayerMagLevel(cid) * 1) * -5 + -5
local maxDmg = (getPlayerLevel(cid) / -5 + getPlayerMagLevel(cid) * 1) * -5 + -12
return {min = minDmg, max = maxDmg}
end


local function stormSpreads(cid, pos, remainingArea)
if remainingArea[1] <= 0 or not isCreature(cid) then
return false
end
remainingArea[1] = remainingArea[1] - 1
local dmg = damageFormula(cid)
--Random effect calculation
local eff = config.effectType[2][1]
local efc = math.random(1, 100)
for i = 1, #config.effectType[1] do
 if(efc < config.effectType[1][i]) then
  eff = config.effectType[2][i]
  break
 else
  efc = efc - config.effectType[1][i]
 end
end
--/Random effect calculation
doCombatAreaHealth(cid, config.combatType, pos, nil, dmg.min, dmg.max, eff)
--Random area calculations
local posArray = {
[1] = {{x = pos.x, y = pos.y - 1, z = pos.z}, {2,4}}, --North
[2] = {{x = pos.x - 1, y = pos.y, z = pos.z}, {1,3}}, --East
[3] = {{x = pos.x, y = pos.y + 1, z = pos.z}, {2,4}}, --South
[4] = {{x = pos.x + 1, y = pos.y, z = pos.z}, {1,3}} --West
}
local i = math.random(1, 4)
addEvent(stormSpreads, config.expansionInterval, cid, posArray[i][1], remainingArea, i)
if math.random(1, 100) <= config.spreadPercent then
if isSightClear(pos, posArray[posArray[i][2][1]][1], true) then
addEvent(stormSpreads, math.random(0, config.expansionInterval), cid, posArray[posArray[i][2][1]][1], remainingArea, i)
end
end
if math.random(1, 100) <= config.spreadPercent then
if isSightClear(pos, posArray[posArray[i][2][2]][1], true) then
addEvent(stormSpreads, math.random(0, config.expansionInterval), cid, posArray[posArray[i][2][2]][1], remainingArea, i)
end
end
--/Random area calculations
return true
end


function onCastSpell(cid, var)
return stormSpreads(cid, getCreaturePosition(cid), {math.random(config.minAttacks, config.maxAttacks)})
end
 
Back
Top