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

[Functions] getPlayerAccount and getAccountType

AGS

DeathSouls Owner
Joined
Oct 29, 2007
Messages
400
Reaction score
10
Location
Mexico
Two simple Sql functions, getPlayerAccount(name) and getAccountType(id).

I don't think I need to explain what they do.
They can be used for example...to make talkactions only for certain accounts or certain accountypes, or maybe a spy rune that shows the account number too...etc

And they can be easily edited to make them get other attributes like email...
getPlayerAccount is already in TFS 0.3 as getPlayerAccountId and getPlayerAccount and account types are not used anymore.
Add this in global.lua
PHP:
function [B]getPlayerAccount[/B](name)
	dofile("./config.lua")
	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 
	local nametodb = escapeString(name)
	result_plr = assert(con:execute("SELECT `account_id` FROM `players` WHERE `name` = '" .. nametodb .. "';"))
	player = result_plr:fetch({}, "a")
	local players = 0
	while player do
		players = players + 1
		account = tonumber(player.account_id)
		player = result_plr:fetch (player, "a")
	end
	con:close()
	env:close()
    return account
end

PHP:
function [B]getAccountType[/B](id)
	dofile("./config.lua")
	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 
	result_plr = assert(con:execute("SELECT `id`, `type` FROM `accounts` WHERE `id` = '" .. id .. "';"))
	account = result_plr:fetch({}, "a")
	local accounts = 0
	while account do
		accounts = accounts + 1
		acctype = tonumber(account.type)
		account = result_plr:fetch (account, "a")
	end
	con:close()
	env:close()
    return acctype
end
If you are using TFS 0.3, this may be useful:
getAccountGroup(accid)
PHP:
function getAccountGroup(accid)
	if type(accid) ~= 'number' then
		debugPrint("getAccountGroup: Invalid account number.")
		return LUA_ERROR
	end
	local accdata = db.getResult("SELECT `id`, `group_id` FROM `accounts` WHERE `id` = " .. accid .. ";")
	if(accdata:getID() ~= -1) then
		local accgroup = accdata:getDataInt("group_id")
		accdata:free()
		return accgroup
	else
		debugPrint("getAccountGroup: Account doesn\'t exists.")
		return LUA_ERROR
	end
end
 
Last edited:
That's what i expect from my Scripter nice work like always rep++++++ :D

yours Evil Hero,
 
Why so long?
Code:
	local cur = assert(con:execute("SELECT `account_id` FROM `players` WHERE `name` = '"..escapeString(name).."';"))
	con:close( )
	env:close( )
	return tonumber(cur:fetch( ))
 
I really don't know...I was high?...

Anyways, this is useless now :p

Now there's getAccountNumberByPlayerName(name) and account types are going to be removed in TFS 0.3
 
Added getAccountGroup, it may still be useful for TFS 0.3.
 
Back
Top