• 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 Problem with functions

therrax

Member
Joined
Jul 12, 2012
Messages
262
Solutions
1
Reaction score
11
Hi.
Information: TFS 1.0
I am beginner. ;(

Error:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/talkactions/scripts/gamemaster/cleanhouse.lua:16: attempt to call global 'g
etCreatureLookDirection' (a nil value)
stack traceback:
        [C]: in function 'getCreatureLookDirection'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:16: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:15>
Script:
Code:
local function getLastLoginDiff(name)
local res = db.getResult("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
if res:getID() ~= -1 then
return os.time()-res:getDataInt('lastlogin')
end
end

local config = {
timeInDays = 14,
buyHouseCommand = "!buyhouse",
delay = 10,
delayStorage = 49676
}

function onSay(cid, words, param, channel)
local pos,s,dir = getPlayerPosition(cid),getPlayerPosition(cid),getCreatureLookDirection(cid)
if config.delay ~= 0 and getPlayerStorageValue(cid,config.delayStorage) >= os.time() then
return doSendMagicEffect(pos,2) and doPlayerSendCancel(cid,"You can only use this command every " .. config.delay .. " seconds. You have to wait " .. getPlayerStorageValue(cid,config.delayStorage)-os.time() .. " seconds.")
end
pos.x = dir == 1 and pos.x+1 or dir == 3 and pos.x-1 or pos.x
pos.y = dir == 0 and pos.y-1 or dir == 2 and pos.y+1 or pos.y
local abuse = config.delay ~= 0 and setPlayerStorageValue(cid,config.delayStorage,os.time()+config.delay)

local house = getHouseFromPos(pos)
if house == false then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This ain't a house tile.")
end

if getHouseOwner(house) == 0 then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This house has no owner. You can buy it on the normal way using " .. config.buyHouseCommand .. ".")
end

local owner = getPlayerNameByGUID(getHouseOwner(house))
if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.")
end


if doPlayerRemoveMoney(cid,getHousePrice(house)) then
return doSendMagicEffect(s,13) and setHouseOwner(house, getPlayerGUID(cid)) and doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,owner .. " has been inactive for more than " .. config.timeInDays .. " days.\nYou bought " .. getHouseName(house) .. " for " .. getHousePrice(house) .. ".")
else
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"You need "..getHousePrice(house).." gold coins to buy " .. getHouseName(house) .. ".")
end
end
 
whenever you see "attempt to call global 'SOMETHING' (a nil value)" it usually means the variable or function does not exist.

try replacing :
getCreatureLookDirection(cid)

With
Creature(cid):getDirection()


P.S.: Since it's likely that this script is from older TFS versions, you might run into the same problem in the rest of the script, so keep us updated and we will work it out bit by bit :)
 
@Karain thanks for suggestions :)

I updated it and now:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/talkactions/scripts/gamemaster/cleanhouse.lua:24: attempt to call global 'g
etHouseFromPos' (a nil value)
stack traceback:
        [C]: in function 'getHouseFromPos'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:24: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:15>
 
@Karain thanks for suggestions :)

I updated it and now:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/talkactions/scripts/gamemaster/cleanhouse.lua:24: attempt to call global 'g
etHouseFromPos' (a nil value)
stack traceback:
        [C]: in function 'getHouseFromPos'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:24: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:15>


Alright, try replacing "getHouseFromPos(pos)" to "Tile(pos):getHouse()"
 
Updated :) and more :D :
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/talkactions/scripts/gamemaster/cleanhouse.lua:33: attempt to call global 'g
etPlayerNameByGUID' (a nil value)
stack traceback:
        [C]: in function 'getPlayerNameByGUID'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:33: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:15>

how do you know what to replace? :D
 
@Limos Sorry but I'm begginer and I dont understand it;( My function is
Code:
local owner = getPlayerNameByGUID(getHouseOwner(house))
if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.") 
end
and I dont know what is this :/
Code:
function getPlayerNameByGUID(guid)
     local resultx = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = " .. guid)
     if resultx then
         name = result.getDataString(resultx, 'name')
         result.free(resultx)
         return name
     end
     return LUA_ERROR
end
 
Therrax, put

Code:
function getPlayerNameByGUID(guid)
local resultx = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = " .. guid)
if resultx then
name = result.getDataString(resultx, 'name')
result.free(resultx)
return name
end
return LUA_ERROR
end

Inside Data/global.lua , at the very end of the file, then do /reload global
 
Ooo, know it's simple :D thanks Karain

@Karain I add it to my global at the very end. Take a look now:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/global.lua:787: attempt to concatenate local 'guid' (a boolean value)
stack traceback:
        [C]: in function '__concat'
        data/global.lua:787: in function 'getPlayerNameByGUID'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:33: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:15>
 
Last edited by a moderator:
End of my global.lua
Code:
-- end of vip system lib

function isSummon(cid)
return getCreatureMaster(cid) ~= cid or false
end
function getItemAttack(uid)
return ItemType(getThing(uid).itemid):getAttack()
end
function getItemDefense(uid)
return ItemType(getThing(uid).itemid):getDefense()
end
function getItemArmor(uid) return ItemType(getThing(uid).itemid):getArmor()
end
function getItemWeaponType(uid)
return ItemType(getThing(uid).itemid):getWeaponType()
end
function isArmor(uid) if (getItemArmor(uid) ~= 0 and getItemWeaponType(uid) == 0)
then
return true
else
return false
end
end
function isWeapon(uid)
return (getItemWeaponType(uid) > 0 and getItemWeaponType(uid) ~= 4)
end
function isShield(uid)
return getItemWeaponType(uid) == 4
end
function isBow(uid)
return (getItemWeaponType(uid) == 5 and (not ItemType(getThing(uid).itemid):isStackable()))
end
function Position.getTile(self)
    return Tile(self)
end

function getPlayerNameByGUID(guid)
local resultx = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = " .. guid)
if resultx then
name = result.getDataString(resultx, 'name')
result.free(resultx)
return name
end
return LUA_ERROR
end

dofile('data/lib/001_04_compat.lua')
 
@Limos
Code:
false

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/global.lua:786: attempt to concatenate local 'guid' (a boolean value)
stack traceback:
        [C]: in function '__concat'
        data/global.lua:786: in function 'getPlayerNameByGUID'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:34: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:15>
 
Limos, i updated it :p my new error:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/talkactions/scripts/gamemaster/cleanhouse.lua:24: attempt to index a nil va
lue
stack traceback:
        [C]: in function '__index'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:24: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:15>

updated script:
Code:
local function getLastLoginDiff(name)
local res = db.getResult("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
if res:getID() ~= -1 then
return os.time()-res:getDataInt('lastlogin')
end
end

local config = {
timeInDays = 1,
buyHouseCommand = "!buyhouse",
delay = 10,
delayStorage = 49676
}

function onSay(cid, words, param, channel)
local pos,s,dir = getPlayerPosition(cid),getPlayerPosition(cid),Creature(cid):getDirection()
if config.delay ~= 0 and getPlayerStorageValue(cid,config.delayStorage) >= os.time() then
return doSendMagicEffect(pos,2) and doPlayerSendCancel(cid,"You can only use this command every " .. config.delay .. " seconds. You have to wait " .. getPlayerStorageValue(cid,config.delayStorage)-os.time() .. " seconds.")
end
pos.x = dir == 1 and pos.x+1 or dir == 3 and pos.x-1 or pos.x
pos.y = dir == 0 and pos.y-1 or dir == 2 and pos.y+1 or pos.y
local abuse = config.delay ~= 0 and setPlayerStorageValue(cid,config.delayStorage,os.time()+config.delay)

local house = Tile(pos):getHouse():getId()
if house == false then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This ain't a house tile.")
end

if getHouseOwner(house) == 0 then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This house has no owner. You can buy it on the normal way using " .. config.buyHouseCommand .. ".")
end

print(getHouseOwner(house))
local owner = getPlayerNameByGUID(getHouseOwner(house))
if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.")
end


if doPlayerRemoveMoney(cid,getHousePrice(house)) then
return doSendMagicEffect(s,13) and setHouseOwner(house, getPlayerGUID(cid)) and doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,owner .. " has been inactive for more than " .. config.timeInDays .. " days.\nYou bought " .. getHouseName(house) .. " for " .. getHousePrice(house) .. ".")
else
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"You need "..getHousePrice(house).." gold coins to buy " .. getHouseName(house) .. ".")
end
end
 

then replace
Code:
local owner = getPlayerNameByGUID(getHouseOwner(house))
if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.")
end

With

Code:
local owner = getPlayerNameByGUID(getHouseOwner(house))
if owner then  -- checks if there is an owner in the first place
if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.")
end
end
 
You can also use the compat function, this will return false when any of them is nil.
Code:
local house = getTileHouseInfo(pos)
 
Back
Top