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

Lua TFS 1.0 BAD ARGUEMENT SPELLS

Codinablack

Dreamer
Content Editor
Joined
Dec 26, 2013
Messages
1,662
Solutions
11
Reaction score
919
Greetings Otland!

Here I come to you today in ask of help with the latest TFS 1.0 server. Seems everything was fine with my spells until I updated the source to include some of the latest commits. Anyways, never had this error in my screen before, now it's there, and also my script stopped working on one of my spells (only the condition part) and as far as the rest goes the spells are still completely functional.

ok spell that stopped working(only condition stopped) armorbreak.lua

Code:
local areaCombat = Combat()
areaCombat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
areaCombat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_BLOCKHIT)

local areaCombat2 = Combat()
areaCombat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
areaCombat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_BLOCKHIT)

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_BLOCKHIT)

function onGetPlayerMinMaxValues(cid, attackSkill, attackValue, attackFactor)
    local player = Player(cid)
    local level = player:getLevel()
    local skill = player:getSkillLevel(0)
    local leftHand = pushThing(player:getSlotItem(CONST_SLOT_LEFT)).itemid
    local rightHand = pushThing(player:getSlotItem(CONST_SLOT_RIGHT)).itemid
    if(ItemType(leftHand):getWeaponType() == 1 or ItemType(rightHand):getWeaponType() == 1) then
        skill = player:getSkillLevel(2)
        end
    if(ItemType(leftHand):getWeaponType() == 2 or ItemType(rightHand):getWeaponType() == 2) then
        skill = player:getSkillLevel(1)
        end
    if(ItemType(leftHand):getWeaponType() == 3 or ItemType(rightHand):getWeaponType() == 3) then
        skill = player:getSkillLevel(3)
        end
    if(ItemType(leftHand):getWeaponType() == 5 or ItemType(rightHand):getWeaponType() == 5) then
        skill = player:getSkillLevel(4)
        end
min = -((level/2) + skill + attackValue)
max = -((level + skill + attackValue)*1.6)
return min, max
end
areaCombat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetPlayerMinMaxValues")
function onGetPlayerMinMaxValues2(cid, attackSkill, attackValue, attackFactor)
    local player = Player(cid)
    local level = player:getLevel()
    local skill = player:getSkillLevel(0)
    local leftHand = pushThing(player:getSlotItem(CONST_SLOT_LEFT)).itemid
    local rightHand = pushThing(player:getSlotItem(CONST_SLOT_RIGHT)).itemid
    if(ItemType(leftHand):getWeaponType() == 1 or ItemType(rightHand):getWeaponType() == 1) then
        skill = player:getSkillLevel(2)
        end
    if(ItemType(leftHand):getWeaponType() == 2 or ItemType(rightHand):getWeaponType() == 2) then
        skill = player:getSkillLevel(1)
        end
    if(ItemType(leftHand):getWeaponType() == 3 or ItemType(rightHand):getWeaponType() == 3) then
        skill = player:getSkillLevel(3)
        end
    if(ItemType(leftHand):getWeaponType() == 5 or ItemType(rightHand):getWeaponType() == 5) then
        skill = player:getSkillLevel(4)
        end
min = -((level/2) + skill + attackValue)
max = -((level + skill + attackValue)*1.6)
return min, max
end
areaCombat2:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetPlayerMinMaxValues2")

local condition = Condition(CONDITION_BLEEDING)
condition:setTicks(9000)
condition:setParameter(CONDITION_PARAM_DELAYED, 1)
condition:setParameter(CONDITION_PARAM_TICKINTERVAL, 3000)

local area = createCombatArea({{0, 1, 0},
{1, 2, 1},
{0, 1, 0}})
areaCombat:setArea(area)

local area2 = createCombatArea({{0, 0, 1, 0, 0},
{0, 1, 0, 1, 0},
{1, 0, 2, 0, 1},
{0, 1, 0, 1, 0},
{0, 0, 1, 0, 0}})
areaCombat2:setArea(area2)

function onTargetCreature(cid, target)
local dmg = 0
    local targetCreature = Creature(target)
    if not targetCreature then
        return true
    end

    if isPlayer(target) then
        local pl = Player(target)
            dmg = pl:getTotalArmor()
    elseif isMonster(target) then
        local monsterType = MonsterType(targetCreature:getName())
            dmg = monsterType:getArmor()
        end
    condition:setParameter(CONDITION_PARAM_PERIODICDAMAGE, -(dmg*2))
    combat:setCondition(condition)
    combat:execute(cid, positionToVariant(target))
    return true
end

areaCombat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
function onTargetCreature2(cid, target)
local dmg = 0
    local targetCreature = Creature(target)
    if not targetCreature then
        return true
    end

    if isPlayer(target) then
        local pl = Player(target)
            dmg = pl:getTotalArmor()
    elseif isMonster(target) then
        local monsterType = MonsterType(targetCreature:getName())
            dmg = monsterType:getArmor()
        end
    condition:setParameter(CONDITION_PARAM_PERIODICDAMAGE, -(dmg*2))
    combat:setCondition(condition)
    combat:execute(cid, positionToVariant(target))
    return true
end
areaCombat2:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature2")

local function RunPart(c,cid,var,dirList,dirEmitPos) -- Part
    if (isCreature(cid)) then
        c:execute(cid, var)
        if (dirList ~= nil) then -- Emit distance effects
            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

function onCastSpell(cid, var)
    local startPos = getCreaturePosition(cid)
    RunPart(areaCombat,cid,var)
    addEvent(RunPart,200,areaCombat2,cid,var)
    return true
end

Returns error in console


Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/attack/armorbreak.lua:onCastSpell
LuaScriptInterface::luaAddEvent(). Argument #4 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/spells/scripts/attack/armorbreak.lua:134: in function <data/spells/
scripts/attack/armorbreak.lua:131>

Like I said the spell still does everything except add the condition to the target, whereas before it worked perfectly fine.
 
NEXT SPELL

This spell still works fine, I just get an error in the console and I don't want it to be there, sure I can turn of "warn about unsafe scripts" in my config, but I would rather know if there is a problem with my script. So here it is...


Code:
-- SpellCreator generated.

-- =============== COMBAT VARS ===============
-- Areas/Combat for 0ms
local combat0_Brush = createCombatObject()
setCombatParam(combat0_Brush, COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
setCombatParam(combat0_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat0_Brush, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat0_Brush, COMBAT_PARAM_BLOCKSHIELD, 1)
setCombatArea(combat0_Brush,createCombatArea({{0, 1, 0},
{1, 0, 1},
{0, 3, 0}}))
function onGetFormulaValues(cid, level, maglevel)
min = -(level * 0.28 + maglevel * 1.48) + 5.0
max = -(level * 0.55 + maglevel * 2.5) * 1.35
    return min, max
end

setCombatCallback(combat0_Brush, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
local dfcombat0_Brush = {CONST_ANI_SUDDENDEATH,0,1,1,2,-1,2,0,3}

-- Areas/Combat for 100ms
local combat1_Brush = createCombatObject()
setCombatParam(combat1_Brush, COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
setCombatParam(combat1_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat1_Brush, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat1_Brush, COMBAT_PARAM_BLOCKSHIELD, 1)
setCombatArea(combat1_Brush,createCombatArea({{1, 1, 1},
{0, 2, 0}}))
function onGetFormulaValues(cid, level, maglevel)
min = -(level * 0.28 + maglevel * 1.48) + 5.0
max = -(level * 0.55 + maglevel * 2.5) * 1.35
    return min, max
end

setCombatCallback(combat1_Brush, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
local dfcombat1_Brush = {CONST_ANI_SUDDENDEATH,0,2,1,2,-1,2}

-- Areas/Combat for 200ms
local combat2_Brush = createCombatObject()
setCombatParam(combat2_Brush, COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
setCombatParam(combat2_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat2_Brush, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat2_Brush, COMBAT_PARAM_BLOCKSHIELD, 1)
setCombatArea(combat2_Brush,createCombatArea({{1, 1, 1},
{0, 0, 0},
{0, 2, 0}}))
function onGetFormulaValues(cid, level, maglevel)
min = -(level * 0.28 + maglevel * 1.48) + 5.0
max = -(level * 0.55 + maglevel * 2.5) * 1.35
    return min, max
end

setCombatCallback(combat2_Brush, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
local dfcombat2_Brush = {CONST_ANI_SUDDENDEATH,1,3,0,3,-1,3}

-- Areas/Combat for 300ms
local combat3_Brush = createCombatObject()
setCombatParam(combat3_Brush, COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
setCombatParam(combat3_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat3_Brush, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat3_Brush, COMBAT_PARAM_BLOCKSHIELD, 1)
setCombatArea(combat3_Brush,createCombatArea({{1, 1, 1},
{0, 0, 0},
{0, 0, 0},
{0, 2, 0}}))
function onGetFormulaValues(cid, level, maglevel)
min = -(level * 0.28 + maglevel * 1.48) + 5.0
max = -(level * 0.55 + maglevel * 2.5) * 1.35
    return min, max
end

setCombatCallback(combat3_Brush, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
local dfcombat3_Brush = {CONST_ANI_SUDDENDEATH,1,4,0,4,-1,4}

-- Areas/Combat for 400ms
local combat4_Brush = createCombatObject()
setCombatParam(combat4_Brush, COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
setCombatParam(combat4_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat4_Brush, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat4_Brush, COMBAT_PARAM_BLOCKSHIELD, 1)
setCombatArea(combat4_Brush,createCombatArea({{1, 1, 1},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 2, 0}}))
function onGetFormulaValues(cid, level, maglevel)
min = -(level * 0.28 + maglevel * 1.48) + 5.0
max = -(level * 0.55 + maglevel * 2.5) * 1.35
    return min, max
end

setCombatCallback(combat4_Brush, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
local dfcombat4_Brush = {CONST_ANI_SUDDENDEATH,1,5,0,5,-1,5}

-- =============== CORE FUNCTIONS ===============
local function RunPart(c,cid,var,dirList,dirEmitPos,startDir) -- Part
    if (isCreature(cid)) then
        doCombat(cid, c, var)
        if (dirList ~= nil) then -- Emit distance effects
            local i = 2;
            while (i < #dirList) do
                if (startDir == 0) then -- N
                    doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x-dirList[i],y=dirEmitPos.y-dirList[i+1],z=dirEmitPos.z},dirList[1])
                elseif (startDir == 2) then -- S
                    doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x+dirList[i],y=dirEmitPos.y+dirList[i+1],z=dirEmitPos.z},dirList[1])
                elseif (startDir == 1) then -- E
                    doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x+dirList[i+1],y=dirEmitPos.y+dirList[i],z=dirEmitPos.z},dirList[1])
                else -- W / Something weird happened
                    doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x-dirList[i+1],y=dirEmitPos.y-dirList[i],z=dirEmitPos.z},dirList[1])
                end
                i = i + 2
            end      
        end
    end
end

function onCastSpell(cid, var)
    local startPos = getCreaturePosition(cid)
    local startDir = Creature(cid):getDirection()
    RunPart(combat0_Brush,cid,var,dfcombat0_Brush,startPos,startDir)
    addEvent(RunPart,100,combat1_Brush,cid,var,dfcombat1_Brush,startPos,startDir)
    addEvent(RunPart,200,combat2_Brush,cid,var,dfcombat2_Brush,startPos,startDir)
    addEvent(RunPart,300,combat3_Brush,cid,var,dfcombat3_Brush,startPos,startDir)
    addEvent(RunPart,400,combat4_Brush,cid,var,dfcombat4_Brush,startPos,startDir)
    return true
end

Here is it's error.
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/attack/deathwave.lua:onCastSpell
LuaScriptInterface::luaAddEvent(). Argument #4 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/spells/scripts/attack/deathwave.lua:125: in function <data/spells/s
cripts/attack/deathwave.lua:118>
 
@Ninja @Limos @Summ does anyone know what the problem is? I added some commits for the source that were alterations to the conditions, but my buff spells still work, and like I said, for the first spell the condition worked before without any problems, then I didn't edit it, edited the sources now it has error in console and only the condition stopped working...
 
Ok I figured out why my condition wasn't working... My condition wasn't working because I was using it on a monster without an armor value. Anyways, I checked out the source and I know that the problem is in addevent, I know I can make the console error disappear with a change in the config, however I wish to know why the script is "unsafe" I wish to know which arguement is arguement number 4 and why is it unsafe, what is it I did wrong with addevent, anyone know?
 
That "error" is saving you from a server crash. It's because you're passing userdata into addEvent. See these config options:
warnUnsafeScripts = "no"
convertUnsafeScripts = "no"

You can toggle convertUnsafeScripts to "yes" for it to work like you want. Or you can fix your scripts (recommended). Rename "cid" to "creature" and pass creature:getId() instead of cid.
 
That "error" is saving you from a server crash. It's because you're passing userdata into addEvent. See these config options:
warnUnsafeScripts = "no"
convertUnsafeScripts = "no"

You can toggle convertUnsafeScripts to "yes" for it to work like you want. Or you can fix your scripts (recommended). Rename "cid" to "creature" and pass creature:getId() instead of cid.

Before "warnUnsafeScripts" and "convertUnsafeScripts" were implemented, the script still ran without problems. I tried changing convertUnsafeScripts to yes and it didn't do anything, maybe I was supposed to restart my server? Idk. Thank you very much for showing me what was wrong with the script and how to fix it!
 
That "error" is saving you from a server crash. It's because you're passing userdata into addEvent. See these config options:
warnUnsafeScripts = "no"
convertUnsafeScripts = "no"

You can toggle convertUnsafeScripts to "yes" for it to work like you want. Or you can fix your scripts (recommended). Rename "cid" to "creature" and pass creature:getId() instead of cid.

I made the changed you said to make, and everything seems to work perfectly fine. However I just noticed a bug that was probably always there. Say for instance my trainers have no defense and no armor, when doing the spell and only trainers are in area it will not do any damage from bleeding condition. However if I do the spell and demon is in combat area, and so is trainer, it does -77 periodicdamage to demon and -127 periodicdamage to the trainer... I am baffled as to how it came up with this number and how come it is not working correctly.

Also since you are on this page and checking this out, I would also like to bring to attention that my script never really called correct armor value of any monster anyways. For instance the demon who keeps taking -77 only has an armor value of 55 and defense of 55, but yet it still does -77 do you know how I can fix these two problems?
 
Back
Top