• 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 Cannot get Onkill to work, any ideas?

Tachi

New Member
Joined
Aug 4, 2007
Messages
376
Reaction score
2
Location
USA, Missouri
When i try to use getItemDefense, get itemAttack, getItemArmor Ect....... they all give a nil value error in the console, TFS 0.3.7 crying damson.....

Now getItemWeight, getItemNameById work just fine... is there something i can do to get these to work properly again....

Just messing with it on the onlogin.lua trying to get it to not give a nil value error.. like this one
Code:
[Error - CreatureScript Interface]
BLAH BLAH:Line: attempt to call global 'getItemAttack' <a nil value>


EXAMPLES OF USAGE OF CODE
Code:
local itenzdef = getItemExtraDefense(getPlayerSlotItem(cid, 5).uid)

if getItemAttack(itemEx.uid) > 0 then


if getItemAttack(2472.uid) > 0 then

None of these work.... =( what else could i try to do to get it to work and not give a nil value error...

And sometimes for some reason the onKill from creature scripts doesnt work.. could there be a reason for it, like no error's just wont do the script
 
Last edited:
getItemInfo(itemid).attack
getItemInfo(itemid).defense
=> Get the values set in items.xml

getItemAttribute(uid, "attack")
=> Should return the value they got if it was changed by script.
 
Lua:
function getItemAttack(item)
	return getItemAttribute(item.uid, "attack") or getItemInfo(item.itemid).attack
end
 
getItemInfo(itemid).attack
getItemInfo(itemid).defense
=> Get the values set in items.xml

getItemAttribute(uid, "attack")
=> Should return the value they got if it was changed by script.


getItemAttribute(uid, "attack") Returns a NIL value still.....

getItemInfo(itemid).defense
Code:
BLAH:line: attempt to index a boolean value



BUT using this function
Code:
[COLOR=#AA9900][B]function[/B][/COLOR] getItemAttack[COLOR=#66CC66]([/COLOR]item[COLOR=#66CC66])[/COLOR]    
[COLOR=#AA9900][B]return[/B][/COLOR] getItemAttribute[COLOR=#66CC66]([/COLOR]item[COLOR=#66CC66].[/COLOR]uid[COLOR=#66CC66],[/COLOR] [COLOR=#FF6666]"attack"[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#AA9900][B]or[/B][/COLOR] getItemInfo[COLOR=#66CC66]([/COLOR]item[COLOR=#66CC66].[/COLOR]itemid[COLOR=#66CC66])[/COLOR][COLOR=#66CC66].[/COLOR]attack
[COLOR=#AA9900][B]end
[/B][/COLOR]
Worked just fine..


And sometimes for some reason the onKill from creature scripts doesnt work.. could there be a reason for it, like no error's just wont do the script

Here's an example of my code, using this for slaying ect...
Code:
Code:
local monsters = {
    --name = storage
    ["troll"] = 55004,
    ["ghoul"] = 55005,
    ["orc"] = 55006,
    ["orc beserker"] = 55006,
    ["orc leader"] = 55006,
    ["orc spearsman"] = 55006,
    ["orc warlord"] = 55006,
    ["orc warrior"] = 55006,
    ["orc rider"] = 55006,
    ["orc shaman"] = 55006,
    ["dragon"] = 55010,
    ["dragon lord"] = 55010,
    ["igor the recruiter"] = 76670
}


function onKill(cid, target)
local monster = monsters[getCreatureName(target):lower()]
    if(isPlayer(target) == FALSE and monster and getPlayerStorageValue(cid, 76670) == 1) then
        local killedMonsters = getPlayerStorageValue(cid, monster)
        if(killedMonsters == -1) then
            killedMonsters = 0
        end
        setPlayerStorageValue(cid, monster, killedMonsters + 1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed Igor!")
    elseif(isPlayer(target) == FALSE and monster and getPlayerStorageValue(cid, 76669) == 2) then
        if getPlayerStorageValue(cid, monster) < 60 then 
            local killedMonsters = getPlayerStorageValue(cid, monster)
            if(killedMonsters == -1) then
                killedMonsters = 1
            end
            setPlayerStorageValue(cid, monster, killedMonsters + 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. killedMonsters .. " of 60 Trolls.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 60 trolls.")
            setPlayerStorageValue(cid, 76669, 3)
        end
    elseif(isPlayer(target) == FALSE and monster and getPlayerStorageValue(cid, 76669) == 5) then
        if getPlayerStorageValue(cid, monster) < 100 then 
            local killedMonsters = getPlayerStorageValue(cid, monster)
            if(killedMonsters == -1) then
                killedMonsters = 1
            end
            setPlayerStorageValue(cid, monster, killedMonsters + 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. killedMonsters .. " of 100 Ghouls.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 100 ghouls.")
            setPlayerStorageValue(cid, 76669, 6)
        end
    elseif(isPlayer(target) == FALSE and monster and getPlayerStorageValue(cid, 76669) == 8) then
        if getPlayerStorageValue(cid, monster) < 150 then 
            local killedMonsters = getPlayerStorageValue(cid, monster)
            if(killedMonsters == -1) then
                killedMonsters = 1
            end
            setPlayerStorageValue(cid, monster, killedMonsters + 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. killedMonsters .. " of 150 Orcs.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 150 orcs.")
            setPlayerStorageValue(cid, 76669, 9)
        end
    elseif(isPlayer(target) == FALSE and monster and getPlayerStorageValue(cid, 76669) == 12) then
        if getPlayerStorageValue(cid, monster) < 150 then 
            local killedMonsters = getPlayerStorageValue(cid, monster)
            if(killedMonsters == -1) then
                killedMonsters = 1
            end
            setPlayerStorageValue(cid, monster, killedMonsters + 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. killedMonsters .. " of 150 Orcs.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 150 orcs.")
            setPlayerStorageValue(cid, 76669, 13)
        end
    end
    return TRUE
end

Could the problem be that all the true's and false's cap'ed?
 
Last edited:
Here's my Login.lua, its kinda long though

Code:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}


function onLogin(cid)
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end


    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end


        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, it appears that your character has been locked for name violating rules, what new name would you like to have?", TALKTYPE_PRIVATE_NP, true, cid)
    elseif(accountManager == MANAGER_ACCOUNT) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type {account} to manage your account. If you would like to start over, type {cancel} anywhere.", TALKTYPE_PRIVATE_NP, true, cid)
    else
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type {account} to create an account or {recover} to recover an account.", TALKTYPE_PRIVATE_NP, true, cid)
    end


    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end
    local expstorage = 19998
    local PlayAc = getPlayerAccess(cid)
    local loginsCounterStorage = 12345
    local loginsCount = getCreatureStorage(cid, loginsCounterStorage)
    if PlayAc <= 1 then
        if loginsCount == -1 then
            local welcomeText = "Welcome " .. getCreatureName(cid) .. ".\n\nOur community would like to welcome you to Aloria. If you need help with anything, please refer to the Help/World channel.\n\nEnjoy your time!"
            local text = "- Welcome to Aloria, here's a list of commands:\n!aol                           -> Buy an amulet of loss for 12 Crystal Coins.\n!spells                      -> List of spells available\n!kills                         -> Check your amount of kills\n!serverinfo           -> Check out the rates of the server..\nCtrl+R                     -> Report bugs to staff\n!- Please visit our webpage for any more information.\n//Aloria Staff"
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ""..text.."")
            broadcastMessage(cid, ""..welcomeText.."", MESSAGE_EVENT_ADVANCE)
            setPlayerStorageValue(cid, 19622, 1)
            setPlayerStorageValue(cid, 13541, 1)
            setPlayerStorageValue(cid, loginsCounterStorage, loginsCount+1)
            return true
        else
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You logged " .. (loginsCount + 1) .. " times.")
            doPlayerSetStorageValue(cid, loginsCounterStorage, loginsCount+1)
            setPlayerStorageValue(cid, 1200, 0)
            setPlayerStorageValue(cid, 2200, 0)
            setPlayerStorageValue(cid, 3200, 0)
            setPlayerStorageValue(cid, 4200, 0)
            setPlayerStorageValue(cid, 5200, 0)
            setPlayerStorageValue(cid, 5520, 0)
            if (os.date('%A') == 'Thursday') then
                doPlayerSetRate(cid, SKILL__LEVEL, 2)
                doPlayerSetStorageValue(cid, expstorage, 2)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Today is extra experience day")
            else
                doPlayerSetStorageValue(cid, expstorage, 1)
            end
            return true
        end
    else
        if (os.date('%A') == 'Thursday') then
            doPlayerSetRate(cid, SKILL__LEVEL, 2)
            doPlayerSetStorageValue(cid, expstorage, 2)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Today is extra experience day")
        else
            doPlayerSetStorageValue(cid, expstorage, 1)
        end
        local itenz = getItemNameById(getPlayerSlotItem(cid, 5).itemid)
        local itenzweight = getItemDefense(getPlayerSlotItem(cid, 5))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Weclome Staff of Alora. Please make sure you have the STAFF channel ALWAY OEPNED!")
        if itenzweight == nil then 
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The Function has Nil'ed OUT!.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Shield: "..itenz.." Def: "..itenzweight..".")
        end
        setPlayerStorageValue(cid, 1200, 0)
        setPlayerStorageValue(cid, 2200, 0)
        setPlayerStorageValue(cid, 3200, 0)
        setPlayerStorageValue(cid, 4200, 0)
        setPlayerStorageValue(cid, 5200, 0)
        setPlayerStorageValue(cid, 5520, 0)
        return true
    end
        
        
        
    
    registerCreatureEvent(cid, "AttributeLogin")
    registerCreatureEvent(cid, "AttributeAdvance")
    registerCreatureEvent(cid, "partyAndGuildProtection")
    registerCreatureEvent(cid, "onPrepareDeath")
    registerCreatureEvent(cid, "Reward")
    registerCreatureEvent(cid, "PointSystem")
    registerCreatureEvent(cid, "onLookItenz")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildEvents")
    registerCreatureEvent(cid, "Idle")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end
    registerCreatureEvent(cid, "demonOakDeath")
    registerCreatureEvent(cid, "demonOakAttack")
    registerCreatureEvent(cid, "demonOakLogout")
    registerCreatureEvent(cid, "ctf")
    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "points")
    registerCreatureEvent(cid, "ThankYou")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end


function getItemDefense(item)
    return getItemAttribute(item.uid, "defense") or getItemInfo(item.itemid).defense
end

And then the onkill im working with is in a mod im working on, although i got 2 mods with onkill's, would that mess with anything? if it does ill just have to make a rly huge mod -.-?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Inquisition" version="2.0" author="Tommy" contact="[email protected]" enabled="yes">
    <config name="inqusitionFunctions"><![CDATA[
        config = {
            message = "Go into the teleporter in 30 seconds, else it will disappear.",
            timeToRemove = 30, -- seconds
            teleportId = 1387,
            MonStor = 48000,
            bosses = { -- Monster Name, Teleport To Position, Teleport Position, UID
                ["igor the recruiter"] = { ptp={ x=1305, y=1377, z=6}, pp={ x=1470, y=1450, z=8, stackpos=1 }, uid=49100 },
            }
        }
        monsters = {
            --name = storage
            ["troll"] = 55004,
            ["ghoul"] = 55005,
            ["orc"] = 55006,
            ["orc beserker"] = 55006,
            ["orc leader"] = 55006,
            ["orc spearsman"] = 55006,
            ["orc warlord"] = 55006,
            ["orc warrior"] = 55006,
            ["orc rider"] = 55006,
            ["orc shaman"] = 55006,
            ["dragon"] = 55010,
            ["dragon lord"] = 55010,
            ["igor the recruiter"] = 76670
        }
    ]]></config>


    <event type="login" name="inquisitionRegister" event="script"><![CDATA[
    domodlib('inqusitionFunctions')
        function onLogin(cid)
            registerCreatureEvent(cid, "Inquisition")
        return true
        end
    ]]></event>


    <event type="kill" name="Inquisition" event="script"><![CDATA[
    domodlib('inqusitionFunctions')
        function removal(position)
            if getThingfromPos(position).itemid == config.teleportId then
                doRemoveItem(getThingfromPos(position).uid)
            end
            return TRUE
        end
        
        function onKill(cid, target)
            local monster = monsters[getCreatureName(target):lower()]
            if(config.bosses[getCreatureName(target):lower()]) then
                local t = config.bosses[getCreatureName(target)]
                local teleport = doCreateTeleport(config.teleportId, t.ptp, t.pp)
                local position = t.pp
                doItemSetAttribute(teleport, "uid", t.uid)
                doCreatureSay(cid, config.message, TALKTYPE_ORANGE_1)
                addEvent(removal, config.timeToRemove * 1000, position)
            elseif (monster and getPlayerStorageValue(cid, 76670) == 1) then
                local killedMonsters = getPlayerStorageValue(cid, monster)
                if(killedMonsters == -1) then
                    killedMonsters = 0
                end
                setPlayerStorageValue(cid, monster, killedMonsters + 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed Igor!")
            elseif (monster and getPlayerStorageValue(cid, 76669) == 2) then
                if getPlayerStorageValue(cid, monster) < 60 then 
                    local killedMonsters = getPlayerStorageValue(cid, monster)
                    if(killedMonsters == -1) then
                        killedMonsters = 1
                    end
                    setPlayerStorageValue(cid, monster, killedMonsters + 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. killedMonsters .. " of 60 Trolls.")
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 60 trolls.")
                    setPlayerStorageValue(cid, 76669, 3)
                end
            elseif (monster and getPlayerStorageValue(cid, 76669) == 5) then
                if getPlayerStorageValue(cid, monster) < 100 then 
                    local killedMonsters = getPlayerStorageValue(cid, monster)
                    if(killedMonsters == -1) then
                        killedMonsters = 1
                    end
                    setPlayerStorageValue(cid, monster, killedMonsters + 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. killedMonsters .. " of 100 Ghouls.")
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 100 ghouls.")
                    setPlayerStorageValue(cid, 76669, 6)
                end
            elseif (monster and getPlayerStorageValue(cid, 76669) == 8) then
                if getPlayerStorageValue(cid, monster) < 150 then 
                    local killedMonsters = getPlayerStorageValue(cid, monster)
                    if(killedMonsters == -1) then
                        killedMonsters = 1
                    end
                    setPlayerStorageValue(cid, monster, killedMonsters + 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. killedMonsters .. " of 150 Orcs.")
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 150 orcs.")
                    setPlayerStorageValue(cid, 76669, 9)
                end
            elseif (monster and getPlayerStorageValue(cid, 76669) == 12) then
                if getPlayerStorageValue(cid, monster) < 150 then 
                    local killedMonsters = getPlayerStorageValue(cid, monster)
                    if(killedMonsters == -1) then
                        killedMonsters = 1
                    end
                    setPlayerStorageValue(cid, monster, killedMonsters + 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. killedMonsters .. " of 150 Orcs.")
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 150 orcs.")
                    setPlayerStorageValue(cid, 76669, 13)
                end
            end    
        return true
        end
    ]]></event>


    <action fromuid="1301" touid="1311" event="script"><![CDATA[
    domodlib('inqusitionFunctions')
        local storage = 50301
        local inquisitionRewards = {
            [1300] = 8890, --a robe of the underworld
            [1301] = 8918, --a spellbook of dark mysteries
            [1302] = 8881, --a fireborn giant armor
            [1303] = 8888, --a master archer's armor
            [1304] = 8851, --a royal crossbow
            [1305] = 7435, --an executioner
            [1306] = 8929, --the stomper
            [1307] = 7417, --a runed sword
            [1308] = 8854, --a warsinger bow
            [1309] = 8903, --a spellbook of lost souls
            [1310] = 2508, --a mystical armor
            [1311] = 8905 --a rainbow shield
        }
        
        if inquisitionRewards[item.uid] then
            if getPlayerStorageValue(cid, storage) < 1 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. getItemArticleById(inquisitionRewards[item.uid]) .. " " .. getItemNameById(inquisitionRewards[item.uid]) .. ".")
                doPlayerAddItem(cid, inquisitionRewards[item.uid], 1)
                setPlayerStorageValue(cid, storage, 1)
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.") 
            end
            return true
        end
    ]]></action>
</mod>




And the second onKill i have

Code:
<event type="kill" name="Zombie" event="script"><![CDATA[
    domodlib('ZombieConfig')
    domodlib('Zombielib')
    function onKill(cid, target)
        if isInRange(getThingPos(cid), config.areaFromPos, config.areaToPos) then
            setGlobalStorageValue(config.zombieCounter, getGlobalStorageValue(cid, config.zombieCounter)-1)
            if getGlobalStorageValue(config.zombieCounter) == 0 then
                doCreatureSay(cid, "You have completed round "..getGlobalStorageValue(config.rounds)..".", TALKTYPE_ORANGE_1)
            elseif getGlobalStorageValue(config.zombieCounter) == 1 then
                doCreatureSay(cid, "There is "..getGlobalStorageValue(config.zombieCounter).. " Zombie Left.", TALKTYPE_ORANGE_1)
            else
                doCreatureSay(cid, "There are "..getGlobalStorageValue(config.zombieCounter).. " Zombies Left.", TALKTYPE_ORANGE_1)
            end
        return true
        end
    end
    ]]></event>

and then the login part is

Code:
<event type="login" name="Zombielog" event="script"><![CDATA[
    domodlib('ZombieConfig')
    function onLogin(cid)
        registerCreatureEvent(cid, "ZombieGlobal")
        registerCreatureEvent(cid, "ZombieGlobal2")
    return true
    end]]></event>
 
Last edited:
Back
Top Bottom