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

TFS 1.X+ error in spells and check onHealthChange

theduck

Member
Joined
Dec 6, 2018
Messages
246
Reaction score
20
Code:
function checkAreaForItem(pos, range, item)
    local from = {x=pos.x-range, y=pos.y-range, z=pos.z}
    local to = {x=pos.x+range, y=pos.y+range, z=pos.z}
    for z = from.z, to.z do
        for y = from.y, to.y do
            for x = from.x, to.x do
                local t = Tile(Position(x, y, z))
                if t:getItemById(item) then
                    return true
                end
            end
        end
    end
end
 



function storage()
   setGlobalStorageValue(91231522,0) 
 end
    
    local condition = Condition(CONDITION_PARALYZE)
    condition:setParameter(CONDITION_PARAM_TICKS, 7000)
    condition:setFormula(-1111.7333, 0, -11110.9333, 0)
     
function onCastSpell(creature, var)
 
    local pos = creature:getPosition()
 
         
    if checkAreaForItem(pos, 2, 36309) and checkAreaForItem(pos, 2, 36310) and checkAreaForItem(pos, 2, 36311) and checkAreaForItem(pos, 2, 36312) and  getGlobalStorageValue(91231522) >= 1   then 
 
        creature:addCondition(condition)
      addEvent(storage, 10000)
    end 
    
    if   checkAreaForItem(pos, 1, 36309) and checkAreaForItem(pos, 1, 36310) and checkAreaForItem(pos, 1, 36311) and checkAreaForItem(pos, 1, 36312) and  getGlobalStorageValue(91231522) >= 1   then 
          creature:addCondition(condition)
        addEvent(storage, 10000)
    end 
   
   if  checkAreaForItem(pos, 3, 36309) and checkAreaForItem(pos, 3, 36310) and checkAreaForItem(pos, 3, 36311) and checkAreaForItem(pos, 3, 36312) and  getGlobalStorageValue(91231522) >= 1   then 
         creature:addCondition(condition)
    addEvent(storage, 10000)
  end
    return true
end

  • Lua Script Error: [Spell Interface]
  • data/spells/scripts/monster/.lua:eek:nCastSpell
  • data/spells/scripts/monster/.lua:8: attempt to index local 't' (a nil value)
  • stack traceback:
  • [C]: in function '__index'
  • data/spells/scripts/monster/.lua:8: in function 'checkAreaForItem'
  • data/spells/scripts/monster/.lua:48: in function <data/spells/scripts/monster/.lua:27>

in other script

Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
local hp = math.random(2000,7500) 
    if not creature:isMonster() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if  creature:getName() == "demon"  and getGlobalStorageValue(91231522) >= 1  then 
        if attacker and attacker:isPlayer() then
            if primaryDamage > 0 then
                            print(creature:addHealth(-hp))
            end
            if secondaryDamage > 0 then
                print(creature:addHealth(-hp))
                   end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
in this other script I'm trying to make sure that whenever he hits and globalstorage is active he suffers a random attack
 
First script you should check if t exists before doing t:getItemByID.
You can either add to the preexisting one or just add another if statement above to check if t exists.
 
Code:
 function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if not creature:isMonster() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if getGlobalStorageValue(91231522) >= 1  and creature:getName() == "demon"  then 
        if primaryType == COMBAT_HEALING or secondaryType == COMBAT_HEALING then
            return primaryDamage, primaryType, secondaryDamage, secondaryType
        end    
        if attacker and attacker:isPlayer() then
            if primaryDamage > 0 then
            local hp = math.random(2000,7500)
            creature:addHealth(-hp)
            end
             
            if secondaryDamage > 0 then
            local hp = math.random(2000,7500)
            creature:addHealth(-hp)
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end


this one works but the char that attacks it needs is close to the monster if I was far away it doesn't work
 
Back
Top