• 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
 
On line 24, replace it with the other local house line.
This does the same except in this function in compat.lua it also checks if it's nil and returns false if it is.
 
Now, when I use command front to the doors:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/talkactions/scripts/gamemaster/cleanhouse.lua:2: attempt to call field 'get
Result' (a nil value)
stack traceback:
        [C]: in function 'getResult'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:2: in function 'getLa
stLoginDiff'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:36: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:15>
 
Replace the function at the top.
Code:
local function getLastLoginDiff(name)
     local res = db.storeQuery("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
     if res then
         xres = result.getDataString(res, 'lastlogin')
         result.free(res)
         return os.time()-xres
     end
     return 0
end
 
Ok it's updated. Now only this:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/gamemaster/cleanhouse.lua:onSay
data/talkactions/scripts/gamemaster/cleanhouse.lua:45: attempt to call global 'g
etHousePrice' (a nil value)
stack traceback:
        [C]: in function 'getHousePrice'
        data/talkactions/scripts/gamemaster/cleanhouse.lua:45: in function <data
/talkactions/scripts/gamemaster/cleanhouse.lua:18>

For help.
My updated script:
Code:
local function getLastLoginDiff(name)
     local res = db.storeQuery("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
     if res then
         xres = result.getDataString(res, 'lastlogin')
         result.free(res)
         return os.time()-xres
     end
     return false
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 = getTileHouseInfo(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 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


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
 
Last edited by a moderator:
Ops but wait :D Script works. I dont have errors in console, it change owner of the house. But items are still in house. It's possible to sent items to depot?

@Limos one more question - up /\
 
Last edited by a moderator:
@Limos @Karain So it's weird. I put for example demon shield to house. I use command. Owner changed but it's all. "
00:36 Sorcerer Sample has been inactive for more than 21 days.
You bought Enigma Square I for 465000."
I dont have errors in console.
My script:
Code:
local function getLastLoginDiff(name)
     local res = db.storeQuery("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
     if res then
         xres = result.getDataString(res, 'lastlogin')
         result.free(res)
         return os.time()-xres
     end
     return false
end

local config = {
timeInDays = 21,
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 = getTileHouseInfo(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 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


if doPlayerRemoveMoney(cid,(configManager.getNumber(configKeys.HOUSE_PRICE) * Tile(pos):getHouse():getTileCount())) 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 " .. (configManager.getNumber(configKeys.HOUSE_PRICE) * Tile(pos):getHouse():getTileCount()) .. ".")
else
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"You need "..(configManager.getNumber(configKeys.HOUSE_PRICE) * Tile(pos):getHouse():getTileCount()).." gold coins to buy " .. getHouseName(house) .. ".")
end
end
Thanka for all guys. ;)
 
Back
Top