Hello! I've been searching through the forums, asked AIs for help but to no avail, so here I am!
I have this issue: I've tried creating a script for a delayed spell by creating an addevent spell with multiple areas, where:
1st tick of the spell is just registering player position and sending effect 87 on the ground
After X miliseconds the registered area is struck by a second combat, now with damage applied.
Everything seems to be working, but every time the spell is cast i get this error in console:
LuaScriptInterface::luaAddEvent(). Argument #4 is unsafe
stack traceback:
[C]: in function 'addEvent'
The issue is also that this error appears even if the player position isn't registered - just a spell with delay works so. Really weird issue. :|
Argument 4 is unsafe spells:
Gyazo Screen Video (https://gyazo.com/1fe84fea36421951d17ef028646051b7) <- Spell that doens't track player position (not following player) - Script #1
Gyazo Screen Video (https://gyazo.com/74d01ee9faa2d1339f68c9e6b539d52d) <- Spell that ,,tracks" player position - Script #2
Script 1:
Script 2:
As far as i've managed to understand it is not save creature position in addevent because it's get forgotten after the 1st instance is cast, or something like that
Any ideas on fixing it? I'm assuming i gotta aproach the addevent part differently, but how? :O
Best regards and thanks in advance!
I have this issue: I've tried creating a script for a delayed spell by creating an addevent spell with multiple areas, where:
1st tick of the spell is just registering player position and sending effect 87 on the ground
After X miliseconds the registered area is struck by a second combat, now with damage applied.
Everything seems to be working, but every time the spell is cast i get this error in console:
LuaScriptInterface::luaAddEvent(). Argument #4 is unsafe
stack traceback:
[C]: in function 'addEvent'
The issue is also that this error appears even if the player position isn't registered - just a spell with delay works so. Really weird issue. :|
Argument 4 is unsafe spells:
Gyazo Screen Video (https://gyazo.com/1fe84fea36421951d17ef028646051b7) <- Spell that doens't track player position (not following player) - Script #1
Gyazo Screen Video (https://gyazo.com/74d01ee9faa2d1339f68c9e6b539d52d) <- Spell that ,,tracks" player position - Script #2
Script 1:
Lua:
-- Define the combat objects
local combat0_Brush = createCombatObject()
setCombatParam(combat0_Brush, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatArea(combat0_Brush, createCombatArea({
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}))
combat0_Brush:setParameter(COMBAT_PARAM_EFFECT, 87)
local combat1_Brush = createCombatObject()
setCombatParam(combat1_Brush, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatArea(combat1_Brush, createCombatArea({
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}))
combat1_Brush:setParameter(COMBAT_PARAM_EFFECT, 87)
local combat29_Brush = createCombatObject()
setCombatParam(combat29_Brush, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatArea(combat29_Brush, createCombatArea({
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}))
local combat30_Brush_2 = createCombatObject()
setCombatParam(combat30_Brush_2, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatArea(combat30_Brush_2, createCombatArea({
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}))
setCombatFormula(combat30_Brush_2, COMBAT_FORMULA_DAMAGE, -300, -360)
combat30_Brush_2:setParameter(COMBAT_PARAM_EFFECT, 10)
-- Define the RunPart function
local function RunPart(c, cid, var, dirList, dirEmitPos)
if (isCreature(cid)) then
doCombat(cid, c, var)
if (dirList ~= nil) then
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
-- Modify the onCastSpell function
function onCastSpell(creature, var)
RunPart(combat0_Brush, creature, var)
addEvent(RunPart, 0, combat1_Brush, creature, var)
addEvent(RunPart, 0, combat29_Brush, creature, var)
addEvent(RunPart, 1000, combat30_Brush_2, creature, var)
return false
end
Script 2:
Code:
-- Define the combat objects
local combat0_Brush = createCombatObject()
setCombatParam(combat0_Brush, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatArea(combat0_Brush, createCombatArea({
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}))
combat0_Brush:setParameter(COMBAT_PARAM_EFFECT, 87)
local combat1_Brush = createCombatObject()
setCombatParam(combat1_Brush, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatArea(combat1_Brush, createCombatArea({
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}))
combat1_Brush:setParameter(COMBAT_PARAM_EFFECT, 87)
local combat29_Brush = createCombatObject()
setCombatParam(combat29_Brush, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatArea(combat29_Brush, createCombatArea({
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}))
local combat30_Brush_2 = createCombatObject()
setCombatParam(combat30_Brush_2, COMBAT_PARAM_TYPE, COMBAT_EARTHDAMAGE)
setCombatArea(combat30_Brush_2, createCombatArea({
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}))
setCombatFormula(combat30_Brush_2, COMBAT_FORMULA_DAMAGE, -160, -240)
combat30_Brush_2:setParameter(COMBAT_PARAM_EFFECT, 84)
-- Define the RunPart function
local function RunPart(c, cid, var, dirList, dirEmitPos)
if (isCreature(cid)) then
doCombat(cid, c, var)
if (dirList ~= nil) then
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
-- Modify the onCastSpell function
function onCastSpell(cid, var)
local startPos = getCreaturePosition(cid)
local target = variantToNumber(var)
if isCreature(target) then
local pos = getCreaturePosition(target)
var = positionToVariant({x = pos.x, y = pos.y, z = pos.z})
end
RunPart(combat1_Brush, cid, var)
addEvent(RunPart, 1, combat29_Brush, cid, var)
addEvent(RunPart, 1000, combat30_Brush_2, cid, var)
return true
end
As far as i've managed to understand it is not save creature position in addevent because it's get forgotten after the 1st instance is cast, or something like that
Any ideas on fixing it? I'm assuming i gotta aproach the addevent part differently, but how? :O
Best regards and thanks in advance!