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

TFS 0.3 db class for 0.2

Colandus

Advanced OT User
Senator
Joined
Jun 6, 2007
Messages
2,434
Solutions
19
Reaction score
219
Location
Sweden
Hey I made this for my 0.2 server as I didn't feel for updating to 0.3 :D

However, the case was that I had made some scripts for my other server which is 0.3 and I didn't feel for remaking them to 0.2 sql functions~

Here I made this class so you can use 0.3 db crap in ur 0.2 serv

Make new file called db.lua in data folder. Then in global.lua write:
Lua:
-- Colandus & grandmather sistemas
dofile('data/db.lua')

And in db.lua:
Lua:
--[[
CREDITS:
>> 80% COLANDUS
>> 20% GRANDMATHER, FIX MANY ISSUE!
]]--

db = {}
db.__index = db

function getConnection()
    local env, con
    if sqlType == "mysql" then
        env = assert(luasql.mysql())
        con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
    else -- sqlite
        env = assert(luasql.sqlite3())
        con = assert(env:connect(sqliteDatabase))
    end
  
    return env, con
end

function db.escapeString(str)
    return "'" .. escapeString(str) .. "'"
end

function db.executeQuery(sql)
    local env, con = getConnection()
    cur = assert(con:execute(sql))
    if(type(cur) ~= 'number') then
        cur:close()
    end
    con:close()
    env:close()
end

function db.getResult(sql)
    local mt = {}

    mt.env, mt.con = getConnection()
    mt.cur = assert(mt.con:execute(sql))
  
    if(mt.cur:numrows() > 0) then
        mt.val = mt.cur:fetch({}, "a")
    end

    setmetatable(mt, db)
    return mt
end

function db:getID()
    return self.val and true or LUA_ERROR
end

function db:next()
    self.val = self.cur:fetch(self.val, "a")
    if self.val then
        return true
    end
end

function db:getDataInt(name)
    if(self.val) then
        return tonumber(self.val[name])
    end
end

function db:getDataString(name)
    if(self.val) then
        return tostring(self.val[name])
    end
end

function db:free()
    self.cur:close()
    self.con:close()
    self.env:close()
end


gz rep or ded
 
Last edited:
nobody can skript like grandmather :mad: you wannabe grandmather.....


WHY NO LOOK HERE??? ALL CRY "PLS TFS 0.3 SKRYPT EROR"
 
Oh my, this is just a lifesaver. Thanks :*

P.S You must spread some Reputation around before giving it to Colandus again.
 
What this does? So i can use my globalevent script on a 0.2? server? Just copy the folder there?
 
I keep getting this error:

Code:
[23/06/2009 11:50:11] data/db.lua:39: attempt to index field 'con' (a nil value)
[23/06/2009 11:50:11] stack traceback:
[23/06/2009 11:50:11] 	data/db.lua:39: in function 'getResult'
[23/06/2009 11:50:11] 	data/global.lua:746: in function 'getMarryStatus'
[23/06/2009 11:50:11] 	data/npc/scripts/Marriage NPC.lua:52: in function 'callback'
[23/06/2009 11:50:11] 	data/npc/lib/npcsystem/npchandler.lua:374: in function 'onCreatureSay'
[23/06/2009 11:50:11] 	data/npc/scripts/Marriage NPC.lua:8: in function <data/npc/scripts/Marriage NPC.lua:8>



NVM FIXED, just delete that SQLLITE PART in the beginning and it works!
 
I HAVE ONE QUESTION !!!!!!!

if I add this in my TFS 0.2, will work things like "exp ring" and "exp scroll" ??


I already rep++ ;D
 
Back
Top