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

Solved Attempt to index local 'r' (a nil value)

1268995

Member
Joined
Sep 9, 2010
Messages
422
Reaction score
13
I am testing the mount system for 8.6 otserver (this one: https://otland.net/threads/8-6-mount-wolf.166160/ )

And got this error:
Code:
[9:51:28.475] [Error - Action Interface]
[9:51:28.475] data/actions/scripts/mountsystem.lua:onUse
[9:51:28.475] Description:
[9:51:28.475] data/actions/scripts/mountsystem.lua:19: attempt to index local 'r' (a nil value)
[9:51:28.475] stack traceback:
[9:51:28.475]   data/actions/scripts/mountsystem.lua:19: in function <data/actions/scripts/mountsystem.lua:17>

mountsystem.lua:

Code:
  --------------------
---- CONDITION -----
--------------------
local wolfCondition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(wolfCondition, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(wolfCondition, {lookType = 4, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0})
--------------------
----- config -------
--------------------
local t =   {
        [2167] = {article='a' ,name='wolf', text='Mount, wolf!', dtext='Demount, wolf!', s=100, condition=wolfCondition},
}     

------------------------------------
--- don't change if you are noob ---
------------------------------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local v, r = getCreaturePosition(cid), t[item.itemid]
        local s = r.s
        local pos = {x = v.x, y = v.y, z = v.z}
        if r then
                if getPlayerStorageValue(cid, s) <= 0 then
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.text, 19)
                        setPlayerStorageValue(cid, s, 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have mounted ' .. r.article .. ' '.. r.name .. '.')
                        return doAddCondition(cid, r.condition) 
                elseif getPlayerStorageValue(cid, s) == 1 then
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.dtext, 19)
                        setPlayerStorageValue(cid, s, 0)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have demounted ' .. r.article .. ' '.. r.name .. '.')
                        return doRemoveCondition(cid, CONDITION_OUTFIT)
                else
                        return doPlayerSendCancel(cid, 'You can\'t do this.')
                end
        else
                return doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE, 'There has been some error, try contacting a staff member.')
        end
end
 
Code:
--------------------
---- CONDITION -----
--------------------
local wolfCondition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(wolfCondition, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(wolfCondition, {lookType = 4, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0})
--------------------
----- config -------
--------------------
local t =   {
        [2167] = {article='a' ,name='wolf', text='Mount, wolf!', dtext='Demount, wolf!', s=100, condition=wolfCondition},
}    

------------------------------------
--- don't change if you are noob ---
------------------------------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local v, r = getCreaturePosition(cid), t[item.itemid]
        if r then
        local s = r.s
        local pos = {x = v.x, y = v.y, z = v.z}
                if getPlayerStorageValue(cid, s) <= 0 then
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.text, 19)
                        setPlayerStorageValue(cid, s, 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have mounted ' .. r.article .. ' '.. r.name .. '.')
                        return doAddCondition(cid, r.condition) 
                elseif getPlayerStorageValue(cid, s) == 1 then
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.dtext, 19)
                        setPlayerStorageValue(cid, s, 0)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have demounted ' .. r.article .. ' '.. r.name .. '.')
                        return doRemoveCondition(cid, CONDITION_OUTFIT)
                else
                        return doPlayerSendCancel(cid, 'You can\'t do this.')
                end
    end
return true
end
 
Last edited:
Code:
  --------------------
---- CONDITION -----
--------------------
local wolfCondition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(wolfCondition, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(wolfCondition, {lookType = 4, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0})
--------------------
----- config -------
--------------------
local t =   {
        [2167] = {article='a' ,name='wolf', text='Mount, wolf!', dtext='Demount, wolf!', s=100, condition=wolfCondition},
}   

------------------------------------
--- don't change if you are noob ---
------------------------------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local v, r = getCreaturePosition(cid), t[item.itemid]
        if r then
        local s = r.s
        local pos = {x = v.x, y = v.y, z = v.z}
                if getPlayerStorageValue(cid, s) <= 0 then
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.text, 19)
                        setPlayerStorageValue(cid, s, 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have mounted ' .. r.article .. ' '.. r.name .. '.')
                        return doAddCondition(cid, r.condition)
                elseif getPlayerStorageValue(cid, s) == 1 then
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.dtext, 19)
                        setPlayerStorageValue(cid, s, 0)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have demounted ' .. r.article .. ' '.. r.name .. '.')
                        return doRemoveCondition(cid, CONDITION_OUTFIT)
                else
                        return doPlayerSendCancel(cid, 'You can\'t do this.')
                end
        else
                return doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE, 'There has been some error, try contacting a staff member.')
        end
end

Worked, but now appear this message when i trying use the item that gives the mount:

"There has been some error, try contacting a staff member."
 
In that case add print("1") in a couple of places (replace 1 with the next number), then check where it stops.
 
In that case add print("1") in a couple of places (replace 1 with the next number), then check where it stops.

Am i correct making this?:

Code:
--------------------
---- CONDITION -----
--------------------
local wolfCondition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(wolfCondition, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(wolfCondition, {lookType = 4, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0})
--------------------
----- config -------
--------------------
local t =   {
        [2167] = {article='a' ,name='wolf', text='Mount, wolf!', dtext='Demount, wolf!', s=100, condition=wolfCondition},
}   

------------------------------------
--- don't change if you are noob ---
------------------------------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local v, r = getCreaturePosition(cid), t[item.itemid]
        if r then
        local s = r.s
        local pos = {x = v.x, y = v.y, z = v.z}
                if getPlayerStorageValue(cid, s) <= 0 then
print("1")
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.text, 19)
                        setPlayerStorageValue(cid, s, 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have mounted ' .. r.article .. ' '.. r.name .. '.')
                        return doAddCondition(cid, r.condition)
                elseif getPlayerStorageValue(cid, s) == 1 then
print("2")
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.dtext, 19)
                        setPlayerStorageValue(cid, s, 0)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have demounted ' .. r.article .. ' '.. r.name .. '.')
                        return doRemoveCondition(cid, CONDITION_OUTFIT)
                else
                        return doPlayerSendCancel(cid, 'You can\'t do this.')
print("3")
                end
    end
return true
end
 
In that case you will only see what if statment it enters, so yes and no.
If you see ex. 2 getting printed out then add new lines between the function in that block to see where it cancels out.
 
In that case you will only see what if statment it enters, so yes and no.
If you see ex. 2 getting printed out then add new lines between the function in that block to see where it cancels out.

With the code i posted, appear on console:

Code:
[12:38:43.134] [Error - LuaInterface::loadFile] data/actions/scripts/mountsystem.lua:38: 'end' expected (to close 'if' at line 22) near 'print'
[12:38:43.134] [Error - Event::checkScript] Cannot load script (data/actions/scripts/mountsystem.lua)
[12:38:43.134] data/actions/scripts/mountsystem.lua:38: 'end' expected (to close 'if' at line 22) near 'print'
 
Code:
--------------------
---- CONDITION -----
--------------------
local wolfCondition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(wolfCondition, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(wolfCondition, {lookType = 4, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0})
--------------------
----- config -------
--------------------
local t =   {
        [2167] = {article='a' ,name='wolf', text='Mount, wolf!', dtext='Demount, wolf!', s=100, condition=wolfCondition},
}  

------------------------------------
--- don't change if you are noob ---
------------------------------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local v, r = getCreaturePosition(cid), t[item.itemid]
        if r then
        local s = r.s
        local pos = {x = v.x, y = v.y, z = v.z}
                if getPlayerStorageValue(cid, s) <= 0 then
                        print("1")
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.text, 19)
                        setPlayerStorageValue(cid, s, 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have mounted ' .. r.article .. ' '.. r.name .. '.')
                        return doAddCondition(cid, r.condition)
                elseif getPlayerStorageValue(cid, s) == 1 then
                        print("2")
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.dtext, 19)
                        setPlayerStorageValue(cid, s, 0)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have demounted ' .. r.article .. ' '.. r.name .. '.')
                        return doRemoveCondition(cid, CONDITION_OUTFIT)
                else
                    print("3")
                        return doPlayerSendCancel(cid, 'You can\'t do this.')
                end
    end
return true
end
 
Code:
--------------------
---- CONDITION -----
--------------------
local wolfCondition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(wolfCondition, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(wolfCondition, {lookType = 4, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0})
--------------------
----- config -------
--------------------
local t =   {
        [2167] = {article='a' ,name='wolf', text='Mount, wolf!', dtext='Demount, wolf!', s=100, condition=wolfCondition},
} 

------------------------------------
--- don't change if you are noob ---
------------------------------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local v, r = getCreaturePosition(cid), t[item.itemid]
        if r then
        local s = r.s
        local pos = {x = v.x, y = v.y, z = v.z}
                if getPlayerStorageValue(cid, s) <= 0 then
                        print("1")
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.text, 19)
                        setPlayerStorageValue(cid, s, 1)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have mounted ' .. r.article .. ' '.. r.name .. '.')
                        return doAddCondition(cid, r.condition)
                elseif getPlayerStorageValue(cid, s) == 1 then
                        print("2")
                        doSendMagicEffect(pos, 10)
                        doCreatureSay(cid, r.dtext, 19)
                        setPlayerStorageValue(cid, s, 0)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'You have demounted ' .. r.article .. ' '.. r.name .. '.')
                        return doRemoveCondition(cid, CONDITION_OUTFIT)
                else
                    print("3")
                        return doPlayerSendCancel(cid, 'You can\'t do this.')
                end
    end
return true
end

With this code no error appeared, but also no print appeared on console...
 
Code:
local wolfCondition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(wolfCondition, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(wolfCondition, {lookType = 4, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0})

local mountArray =   {
    [5903] = {article = "a", name = "wolf", text = "Mount, wolf!", demountText = "Demount, wolf!", storage = 100, condition = wolfCondition},
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local mount = mountArray[item.itemid]
    if not mount then
        return true
    end
   
    local playerStorage = getPlayerStorageValue(cid, mount.storage)
    if playerStorage <= 0 then
        doSendMagicEffect(getCreaturePosition(cid), 10)
        doCreatureSay(cid, mount.text, 19)
        setPlayerStorageValue(cid, mount.storage, 1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You have mounted " .. mount.article .. " ".. mount.name .. ".")
        doAddCondition(cid, mount.condition)
    elseif playerStorage == 1 then
        doSendMagicEffect(getCreaturePosition(cid), 10)
        doCreatureSay(cid, mount.demountText, 19)
        setPlayerStorageValue(cid, mount.storage, 0)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You have demounted " .. mount.article .. " ".. mount.name .. ".")
        doRemoveCondition(cid, CONDITION_OUTFIT)
    else
        doPlayerSendCancel(cid, "You can't do this.")
    end
    return true
end

The problem was that you used the wrong itemid.
 
Back
Top