• 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 [lua/sql query] getDataString

Slec

Nothing else matters.
Joined
Apr 19, 2014
Messages
124
Reaction score
306
Location
Brazil
Hello, guys! I having this error, i pretty new with scripts so i have no clue of what is going on.
It's a castle war system, i currently using OTX 8.7 distro. I got the error on movements, but it happens whnever the scripts try to execute the getDataString("guild")... Already happened on creaturescripts and globalscripts aswell... i think i configuring it wrong our something... Can someone help me out with it?
Thanks alot!

Executable log error:

[Error - MoveEvents Interface]
data/movements/scripts/efferus/castle-wars.lua:eek:nStepIn
Description:
data/lib/004-database.lua:82: [Result:getDataString] Result not set!
stack traceback:
[C]: in function 'error'
data/lib/004-database.lua:82: in function 'getDataString'
data/movements/scripts/efferus/castle-wars.lua:64: in function <data/movements/scripts/efferus/castle-wars.lua:1>

Movement file.lua that i think is giving the error:

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
if isPlayer(cid) then
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
if item.actionid == 2518 then
if getPlayerGuildId(cid) ~= 0 then
if getPlayerGuildName(cid) == guild:getDataString("guild") then
doTeleportThing(cid, {x=2526,y=1525,z=7})
doSendMagicEffect(getCreaturePosition(cid), 10)
else
doTeleportThing(cid, {x=2526,y=1548,z=7})
doSendMagicEffect(getCreaturePosition(cid), 10)
end
else
doTeleportThing(cid, {x=1430,y=1240,z=9})
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa fazer parte de uma guild para poder participar desse evento.")
doSendMagicEffect(getCreaturePosition(cid), 10)
end

elseif item.actionid == 50093 then
if getPlayerStorageValue(cid, 50093) > os.time() then
doTeleportThing(cid, {x=2526,y=1525,z=7})
doSendMagicEffect({x=2526,y=1525,z=7}, 13)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa esperar " .. (getPlayerStorageValue(cid, 50093)-os.time()) .. " segundos para poder voltar.")
else
doTeleportThing(cid, {x=2486,y=1508,z=7})
doSendMagicEffect(getCreaturePosition(cid), 10)
end

elseif item.actionid == 50094 then
if getPlayerStorageValue(cid, 50093) > os.time() then
doTeleportThing(cid, {x=2526,y=1548,z=7})
doSendMagicEffect({x=2526,y=1548,z=7}, 13)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa esperar " .. (getPlayerStorageValue(cid, 50093)-os.time()) .. " segundos para poder voltar.")
else
doTeleportThing(cid, {x=2483,y=1550,z=7})
doSendMagicEffect(getCreaturePosition(cid), 10)
end

elseif item.actionid == 50095 then
local posEntrando = {
{x=1488,y=1201,z=7},
{x=1489,y=1201,z=7},
{x=1490,y=1201,z=7},
{x=1491,y=1201,z=7},
{x=1536,y=1232,z=6},
{x=1537,y=1232,z=6}
}
local posSaindo = {
{x=1488,y=1203,z=7},
{x=1489,y=1203,z=7},
{x=1490,y=1203,z=7},
{x=1491,y=1203,z=7},
{x=1534,y=1234,z=6},
{x=1535,y=1234,z=6},
{x=1536,y=1234,z=6},
{x=1537,y=1234,z=6}
}
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
if getPlayerStorageValue(cid, 50095) < os.time() then
for t=1,#posEntrando do
if (fromPosition.x == posEntrando[t].x and fromPosition.y == posEntrando[t].y and fromPosition.z == posEntrando[t].z) then
if guild:getDataString("guild") ~= "" then
doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,"Bem vindo à cidade de Agniter, controlada pela guild "..guild:getDataString("guild")..".")
doPlayerSetStorageValue(cid, 50095, os.time() + 60)
end
end
end
for t=1,#posSaindo do
if (fromPosition.x == posSaindo[t].x and fromPosition.y == posSaindo[t].y and fromPosition.z == posSaindo[t].z) then
if guild:getDataString("guild") ~= "" then
doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,"Você está deixando Agniter, cidade controlada pela guild "..guild:getDataString("guild")..".")
doPlayerSetStorageValue(cid, 50095, os.time() + 60)
end

end
end
end

end
end
return true
end

Query i executing:

CREATE TABLE IF NOT EXISTS castle_wars (
id int(11) NOT NULL auto_increment,
castle_name varchar(255) NOT NULL,
guild varchar(255) NOT NULL,
castle_war varchar(255) NOT NULL,
last_conqueror varchar(255) NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1

CREATE TABLE IF NOT EXISTS castles_war (
castle_id int(5) NOT NULL,
guild_id int(5) NOT NULL,
damage int(20) NOT NULL,
time int(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

complete lib 004-database:

db.updateQueryLimitOperator = db.updateLimiter
db.stringComparisonOperator = db.stringComparer
db.stringComparison = db.stringComparer
db.executeQuery = db.query
db.quote = db.escapeString

if(result == nil) then
print("> WARNING: Couldn't load database lib.")
return
end

Result = createClass(nil)
Result:setAttributes({
id = -1,
query = ""
})

function Result:getID()
return self.id
end

function Result:setID(_id)
self.id = _id
end

function Result:getQuery()
return self.query
end

function Result:setQuery(_query)
self.query = _query
end

function Result:create(_query)
self:setQuery(_query)
local _id = db.storeQuery(self:getQuery())
if(_id) then
self:setID(_id)
end

return self:getID()
end

function Result:getRows(free)
local free = free or false
if(self:getID() == -1) then
error("[Result:getRows] Result not set!")
end

local c = 0
repeat
c = c + 1
until not self:next()

local _query = self:getQuery()
self:free()
if(not free) then
self:create(_query)
end

return c
end

function Result:getDataInt(s)
if(self:getID() == -1) then
error("[Result:getDataInt] Result not set!")
end

return result.getDataInt(self:getID(), s)
end

function Result:getDataLong(s)
if(self:getID() == -1) then
error("[Result:getDataLong] Result not set!")
end

return result.getDataLong(self:getID(), s)
end

function Result:getDataString(s)
if(self:getID() == -1) then
error("[Result:getDataString] Result not set!")
end

return result.getDataString(self:getID(), s)
end

function Result:getDataStream(s)
if(self:getID() == -1) then
error("[Result:getDataStream] Result not set!")
end

return result.getDataStream(self:getID(), s)
end

function Result:next()
if(self:getID() == -1) then
error("[Result:next] Result not set!")
end

return result.next(self:getID())
end

function Result:free()
if(self:getID() == -1) then
error("[Result:free] Result not set!")
end

self:setQuery("")
local ret = result.free(self:getID())
self:setID(-1)
return ret
end

Result.numRows = Result.getRows
function db.getResult(query)
if(type(query) ~= 'string') then
return nil
end

local ret = Result:new()
ret:create(query)
return ret
end
 
Try changing your movement file to this:
Code:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
if isPlayer(cid) then
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
    if item.actionid == 2518 then
        if getPlayerGuildId(cid) ~= 0 then
            if getPlayerGuildName(cid) == guild:getDataString("guild") then
                doTeleportThing(cid, {x=2526,y=1525,z=7})
                doSendMagicEffect(getCreaturePosition(cid), 10)
            else
                doTeleportThing(cid, {x=2526,y=1548,z=7})
                doSendMagicEffect(getCreaturePosition(cid), 10)
            end
        else
            doTeleportThing(cid, {x=1430,y=1240,z=9})
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa fazer parte de uma guild para poder participar desse evento.")
            doSendMagicEffect(getCreaturePosition(cid), 10)
        end
    elseif item.actionid == 50093 then
        if getPlayerStorageValue(cid, 50093) > os.time() then
            doTeleportThing(cid, {x=2526,y=1525,z=7})
            doSendMagicEffect({x=2526,y=1525,z=7}, 13)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa esperar " .. (getPlayerStorageValue(cid, 50093)-os.time()) .. " segundos para poder voltar.")
        else
            doTeleportThing(cid, {x=2486,y=1508,z=7})
            doSendMagicEffect(getCreaturePosition(cid), 10)
        end

    elseif item.actionid == 50094 then
        if getPlayerStorageValue(cid, 50093) > os.time() then
            doTeleportThing(cid, {x=2526,y=1548,z=7})
            doSendMagicEffect({x=2526,y=1548,z=7}, 13)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa esperar " .. (getPlayerStorageValue(cid, 50093)-os.time()) .. " segundos para poder voltar.")
        else
            doTeleportThing(cid, {x=2483,y=1550,z=7})
            doSendMagicEffect(getCreaturePosition(cid), 10)
        end

    elseif item.actionid == 50095 then
        local posEntrando = {
            {x=1488,y=1201,z=7},
            {x=1489,y=1201,z=7},
            {x=1490,y=1201,z=7},
            {x=1491,y=1201,z=7},
            {x=1536,y=1232,z=6},
            {x=1537,y=1232,z=6}
        }
        local posSaindo = {
            {x=1488,y=1203,z=7},
            {x=1489,y=1203,z=7},
            {x=1490,y=1203,z=7},
            {x=1491,y=1203,z=7},
            {x=1534,y=1234,z=6},
            {x=1535,y=1234,z=6},
            {x=1536,y=1234,z=6},
            {x=1537,y=1234,z=6}
        }
        local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
        local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
        if getPlayerStorageValue(cid, 50095) < os.time() then
            for t=1,#posEntrando do
                if (fromPosition.x == posEntrando[t].x and fromPosition.y == posEntrando[t].y and fromPosition.z == posEntrando[t].z) then
                    if guild:getId() ~= -1 and guild:getDataString("guild") ~= "" then
                        doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,"Bem vindo à cidade de Agniter, controlada pela guild "..guild:getDataString("guild")..".")
                        doPlayerSetStorageValue(cid, 50095, os.time() + 60)
                    end
                end
            end
            for t=1,#posSaindo do
                if (fromPosition.x == posSaindo[t].x and fromPosition.y == posSaindo[t].y and fromPosition.z == posSaindo[t].z) then
                    if guild:getId() ~= -1 and guild:getDataString("guild") ~= "" then
                        doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,"Você está deixando Agniter, cidade controlada pela guild "..guild:getDataString("guild")..".")
                        doPlayerSetStorageValue(cid, 50095, os.time() + 60)
                    end
                end
            end
        end
    end
end
return true
end
 
Thanks for the reply @imkingran!

I replaced and tested. Now i've got this error:

[Error - MoveEvents Interface]
data/movements/scripts/efferus/castle-wars.lua:eek:nStepIn
Description:
data/movements/scripts/efferus/castle-wars.lua:71: attempt to call method 'getId' (a nil value)
stack traceback:
data/movements/scripts/efferus/castle-wars.lua:71: in function <data/movements/scripts/efferus/castle-wars.lua:1>

EDIT: I've found this on my source... idk if it helps

/** Get the String of a field in database
*\returns The String of the selected field and row
*\param s The name of the field
*/
DATABASE_VIRTUAL std::string getDataString(const std::string&) {return "";}

EDIT 2: This script was originaly used on a TFS 0.4... i trying to use it on a OTX now

EDIT: I compared my OTX source with the TFS source... the TFS source used this:

/** Get the String of a field in database
*\returns The String of the selected field and row
*\param s The name of the field
*/
DATABASE_VIRTUAL std::string getDataString(const std::string&) {return "''";}

If i "import" this last TFS part to my OTX, ll it works?! our ll prob give bugs?

EDIT: Nvm, i have replaced and compiled... its was ok, but whn i tested ingame i got the same error
 
Last edited:
Try this:
Code:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
if isPlayer(cid) then
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
    if item.actionid == 2518 then
        if getPlayerGuildId(cid) ~= 0 then
            if getPlayerGuildName(cid) == guild:getDataString("guild") then
                doTeleportThing(cid, {x=2526,y=1525,z=7})
                doSendMagicEffect(getCreaturePosition(cid), 10)
            else
                doTeleportThing(cid, {x=2526,y=1548,z=7})
                doSendMagicEffect(getCreaturePosition(cid), 10)
            end
        else
            doTeleportThing(cid, {x=1430,y=1240,z=9})
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa fazer parte de uma guild para poder participar desse evento.")
            doSendMagicEffect(getCreaturePosition(cid), 10)
        end
    elseif item.actionid == 50093 then
        if getPlayerStorageValue(cid, 50093) > os.time() then
            doTeleportThing(cid, {x=2526,y=1525,z=7})
            doSendMagicEffect({x=2526,y=1525,z=7}, 13)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa esperar " .. (getPlayerStorageValue(cid, 50093)-os.time()) .. " segundos para poder voltar.")
        else
            doTeleportThing(cid, {x=2486,y=1508,z=7})
            doSendMagicEffect(getCreaturePosition(cid), 10)
        end

    elseif item.actionid == 50094 then
        if getPlayerStorageValue(cid, 50093) > os.time() then
            doTeleportThing(cid, {x=2526,y=1548,z=7})
            doSendMagicEffect({x=2526,y=1548,z=7}, 13)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa esperar " .. (getPlayerStorageValue(cid, 50093)-os.time()) .. " segundos para poder voltar.")
        else
            doTeleportThing(cid, {x=2483,y=1550,z=7})
            doSendMagicEffect(getCreaturePosition(cid), 10)
        end

    elseif item.actionid == 50095 then
        local posEntrando = {
            {x=1488,y=1201,z=7},
            {x=1489,y=1201,z=7},
            {x=1490,y=1201,z=7},
            {x=1491,y=1201,z=7},
            {x=1536,y=1232,z=6},
            {x=1537,y=1232,z=6}
        }
        local posSaindo = {
            {x=1488,y=1203,z=7},
            {x=1489,y=1203,z=7},
            {x=1490,y=1203,z=7},
            {x=1491,y=1203,z=7},
            {x=1534,y=1234,z=6},
            {x=1535,y=1234,z=6},
            {x=1536,y=1234,z=6},
            {x=1537,y=1234,z=6}
        }
        local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
        local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
        if getPlayerStorageValue(cid, 50095) < os.time() then
            for t=1,#posEntrando do
                if (fromPosition.x == posEntrando[t].x and fromPosition.y == posEntrando[t].y and fromPosition.z == posEntrando[t].z) then
                    if guild:getID() ~= -1 and guild:getDataString("guild") ~= "" then
                        doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,"Bem vindo à cidade de Agniter, controlada pela guild "..guild:getDataString("guild")..".")
                        doPlayerSetStorageValue(cid, 50095, os.time() + 60)
                    end
                end
            end
            for t=1,#posSaindo do
                if (fromPosition.x == posSaindo[t].x and fromPosition.y == posSaindo[t].y and fromPosition.z == posSaindo[t].z) then
                    if guild:getID() ~= -1 and guild:getDataString("guild") ~= "" then
                        doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,"Você está deixando Agniter, cidade controlada pela guild "..guild:getDataString("guild")..".")
                        doPlayerSetStorageValue(cid, 50095, os.time() + 60)
                    end
                end
            end
        end
    end
end
return true
end
 
Oh well it did worked! at least its not giving the errors anymore, wht have u done exactly? Because now i have to fix the creaturescript and globalevents scripts.... so i need to kow the logic, unless u r a good samaritan and fix them for me xD and thnaks alot dude.
 
Oh well it did worked! at least its not giving the errors anymore, wht have u done exactly? Because now i have to fix the creaturescript and globalevents scripts.... so i need to kow the logic, unless u r a good samaritan and fix them for me xD and thnaks alot dude.

In your original script I changed this line:
Code:
if guild:getDataString("guild") ~= "" then
To:
Code:
if guild:getID() ~= -1 and guild:getDataString("guild") ~= "" then

The part I added was a check to see if the query returned any results:
Code:
guild:getID() ~= -1

The error in my first post was that I wrote getId() instead of getID() :p

Good luck in your other scripts! :)
 
Back
Top