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

CreatureEvent Upgrade weapon by killing monsters!

When I run this and kill something, it bugs out. It says there's something wrong with like 68 which is where there's a %. What exactly does the % do and could that be bugging it?

Code:
[19:56:04.857] [Error - CreatureScript Interface]
[19:56:04.857] data/creaturescripts/scripts/monster_weapon_upgrade.lua:onKill
[19:56:04.858] Description:
[19:56:04.858] ...a/creaturescripts/scripts/monster_weapon_upgrade.lua:68: attem
pt to compare nil with number
[19:56:04.858] stack traceback:
[19:56:04.859]  ...a/creaturescripts/scripts/monster_weapon_upgrade.lua:68: in f
unction <...a/creaturescripts/scripts/monster_weapon_upgrade.lua:42>
 
0.4 fix
Lua:
--[[
    ** Monster weapon upgrader by slawkens **
 
    kills - how much monsters must be killed
    extraAttack - how much extraAttack points will this weapon get
    extraAttackLimit - you can set limit of extraAttack points added
]]--
 
local monsters = {
    ['rat'] = {
        [2395] = {
            kills = 3,
            extraAttack = 1,
            extraAttackLimit = 3,
            storage = 19332
        }
    },
    ['dragon'] = {
        [2383] = {
            kills = 500,
            extraAttack = 1,
            extraAttackLimit = 20,
            storage = 34001
        }
    }
}
 
function onKill(cid, target, damage, flags)
    if not isMonster(target) or not isInArray({1,2,3},flags) then
        return true
    end
 
    if not monsters[getCreatureName(target):lower()] then
        return true
    end
 
    local playerWeapon = getPlayerWeapon(cid, true)
    if playerWeapon.itemid == 0 then
        return true
    end
 
    if not monsters[getCreatureName(target):lower()][playerWeapon.itemid] then
        return true
    end
    doSendAnimatedText(getThingPos(cid), 'CHECK1!', COLOR_LIGHTBLUE)
 
    local weapon = monsters[getCreatureName(target):lower()][playerWeapon.itemid]
    local currentExtraAttack = getItemAttribute(playerWeapon.uid, 'extraattack') == nil and 0 or getItemAttribute(playerWeapon.uid, 'extraattack')
    
    doCreatureSetStorage(cid, weapon.storage, math.max(1,getCreatureStorage(cid, weapon.storage)+1))
    doSendAnimatedText(getThingPos(cid), 'CHECK2!', COLOR_LIGHTBLUE)
    if getCreatureStorage(cid, weapon.storage) >= weapon.kills and currentExtraAttack < weapon.extraAttackLimit then
        doCreatureSetStorage(cid, weapon.storage, 0)
        doSendAnimatedText(getThingPos(cid), 'CHECK3!', COLOR_LIGHTBLUE)
        doItemSetAttribute(playerWeapon.uid, 'extraattack', currentExtraAttack + weapon.extraAttack)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations! Your weapon received +' .. weapon.extraAttack .. ' attack points and now have total extra damage of +' .. (currentExtraAttack + weapon.extraAttack) .. ' points!')
    end
    return true
end
 
Last edited:
I'v read the comments so take this as a request and maybe someone could be kind enough to figure it out but here is the error given by the original script tested on TFS 0.3.6:
k75Pc4.png

The latest script which was by @cbrm sadly it was for 0.4 but I gave it a shot and nothing happens.

If anyone has a script or could maybe fix this script for TFS 0.3.6 I'd greatly appreciate it.

Thank You.

~Sin
 
Nil means nothing right?
So if it is attempting to compare nothing with a number... Maybe look back over it one more time, that line is comparing something that has no value to something that does, so problem could be with that line, or problem could also be before that line....
 
Nil means nothing right?
So if it is attempting to compare nothing with a number... Maybe look back over it one more time, that line is comparing something that has no value to something that does, so problem could be with that line, or problem could also be before that line....

Usually "nil value" just means it doesn't understand what function you are using in a script or it's written wrong. But thanks for the shout out.

That being said I have a good idea what it could be just no time to test it out, maybe when I get back from the airport.

~Sin
 
Is this working now with 0.4?

0.4 fix
Code:
--[[
    ** Monster weapon upgrader by slawkens **

    kills - how much monsters must be killed
    extraAttack - how much extraAttack points will this weapon get
    extraAttackLimit - you can set limit of extraAttack points added
]]--

local monsters = {
    ['rat'] = {
        [2395] = {
            kills = 3,
            extraAttack = 1,
            extraAttackLimit = 3,
            storage = 19332
        }
    },
    ['dragon'] = {
        [2383] = {
            kills = 500,
            extraAttack = 1,
            extraAttackLimit = 20,
            storage = 34001
        }
    }
}

function onKill(cid, target, damage, flags)
    if not isMonster(target) or not isInArray({1,2,3},flags) then
        return true
    end

    if not monsters[getCreatureName(target):lower()] then
        return true
    end

    local playerWeapon = getPlayerWeapon(cid, true)
    if playerWeapon.itemid == 0 then
        return true
    end

    if not monsters[getCreatureName(target):lower()][playerWeapon.itemid] then
        return true
    end
    doSendAnimatedText(getThingPos(cid), 'CHECK1!', COLOR_LIGHTBLUE)

    local weapon = monsters[getCreatureName(target):lower()][playerWeapon.itemid]
    local currentExtraAttack = getItemAttribute(playerWeapon.uid, 'extraattack') == nil and 0 or getItemAttribute(playerWeapon.uid, 'extraattack')
  
    doCreatureSetStorage(cid, weapon.storage, math.max(1,getCreatureStorage(cid, weapon.storage)+1))
    doSendAnimatedText(getThingPos(cid), 'CHECK2!', COLOR_LIGHTBLUE)
    if getCreatureStorage(cid, weapon.storage) >= weapon.kills and currentExtraAttack < weapon.extraAttackLimit then
        doCreatureSetStorage(cid, weapon.storage, 0)
        doSendAnimatedText(getThingPos(cid), 'CHECK3!', COLOR_LIGHTBLUE)
        doItemSetAttribute(playerWeapon.uid, 'extraattack', currentExtraAttack + weapon.extraAttack)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations! Your weapon received +' .. weapon.extraAttack .. ' attack points and now have total extra damage of +' .. (currentExtraAttack + weapon.extraAttack) .. ' points!')
    end
    return true
end
 
Back
Top