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

Script Unsafe

xLosT

Member
Joined
Jan 11, 2010
Messages
1,022
Reaction score
13
Location
Brasil, Rio Grande do Sul
in tfs 1.2 have one erro
Code:
Lua Script Error: [Weapon Interface]
data/weapons/scripts/wand.lua:onUseWeapon
luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/weapons/scripts/wand.lua:17: in function


Code:
w = {
[1] = {ef = 36, sh = 3, dmg = COMBAT_FIREDAMAGE},
[2] = {ef = 42, sh = 28, dmg = COMBAT_ICEDAMAGE},
[3] = {ef = 45, sh = 38, dmg = COMBAT_POISONDAMAGE},
[4] = {ef = 17, sh = 31, dmg = COMBAT_DEATHDAMAGE},
[5] = {ef = 11, sh = 35, dmg = COMBAT_ENERGYDAMAGE},
[6] = {ef = 31, sh = 35, dmg = COMBAT_PHYSICALDAMAGE},
[7] = {ef = 49, sh = 37, dmg = COMBAT_HOLYDAMAGE}
}

function onUseWeapon(cid, var)
min, max = 180, 350 -- dano minimo e maximo
target = getCreatureTarget(cid)
if target ~= 0 then
wx = w[math.random(1, #w)]
doSendDistanceShoot(getThingPos(cid), getThingPos(target), wx.sh)
addEvent(doAreaCombatHealth, 100, cid, wx.dmg, getThingPos(target), 0, -min, -max, wx.ef)
end
return true
end
 
Lua Script Error: [Weapon Interface] data/weapons/scripts/wand.lua:eek:nUseWeapon luaAddEvent(). Argument #3 is unsafe stack traceback: [C]: in function 'addEvent' data/weapons/scripts/wand.lua:17: in function

Never use userdata as a parameter of addEvent, it is just like pointer in C, if your userdata doesnt exist anymore on memory at event time then you got a dangling pointer and your server get crashed, instead use player name uid or id as parameter e.g:
addEvent(doAreaCombatHealth, 100, cid:getId(), wx.dmg, getThingPos(target), 0, -min, -max, wx.ef)
 
you arent even using 1.2 functions or arguments lol
it's counting cid as a userdata and tfs cries when you do that because the userdata may become nil once the event goes off

Code:
w = {
    {effect = 36, shoot = 3, dmg = COMBAT_FIREDAMAGE},
    {effect = 42, shoot = 28, dmg = COMBAT_ICEDAMAGE},
    {effect = 45, shoot = 38, dmg = COMBAT_POISONDAMAGE},
    {effect = 17, shoot = 31, dmg = COMBAT_DEATHDAMAGE},
    {effect = 11, shoot = 35, dmg = COMBAT_ENERGYDAMAGE},
    {effect = 31, shoot = 35, dmg = COMBAT_PHYSICALDAMAGE},
    {effect = 49, shoot = 37, dmg = COMBAT_HOLYDAMAGE}
}

local min, max = 180, 350

function onUseWeapon(player, variant)
    local target = player:getTarget()
    if target then
        shootType = w[math.random(#w)]
        player:getPosition():sendDistanceEffect(target:getPosition(), shootType.shoot)
        addEvent(function(cid, pos)
            if not Player(cid) then
                return
            end
            doAreaCombatHealth(cid, shootType.dmg, pos, 0, -min, -max, shootType.effect)
        end, 100, player:getId(), target:getPosition())
    end
    return true
end
 
Code:
addEvent(doAreaCombatHealth, 100, cid:getId(), wx.dmg, getThingPos(target), 0, -min, -max, wx.ef)
i change and work

Xeraphus i test your script and debug if attack[/code]
Code:
w = {
    {effect = 36, shoot = 3, dmg = COMBAT_FIREDAMAGE},
    {effect = 42, shoot = 28, dmg = COMBAT_ICEDAMAGE},
    {effect = 45, shoot = 38, dmg = COMBAT_POISONDAMAGE},
    {effect = 17, shoot = 31, dmg = COMBAT_DEATHDAMAGE},
    {effect = 11, shoot = 35, dmg = COMBAT_ENERGYDAMAGE},
    {effect = 31, shoot = 35, dmg = COMBAT_PHYSICALDAMAGE},
    {effect = 49, shoot = 37, dmg = COMBAT_HOLYDAMAGE}
}

local min, max = 180, 350

function onUseWeapon(player, variant)
    local target = player:getTarget()
    if target then
        local shootType = w[math.random(#w)]
        player:getPosition():sendDistanceEffect(target:getPosition(), shootType.shoot)
        addEvent(function(cid, tid)
            local target = Creature(tid)
            if not Player(cid) or not target then
                return
            end
            doAreaCombatHealth(cid, shootType.dmg, target:getPosition(), 0, -min, -max, shootType.effect)
        end, 100, player:getId(), target:getId())
    end
    return true
end
make sure you replace everything not just the function
 
Back
Top