• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

hasAccountStorage(cid, key, value)

Jetro

jangeldev
Joined
Aug 1, 2011
Messages
452
Reaction score
68
Location
Venezuela
Hi all, this is a simple function to know if player has a storage in some of the players in him/her account, returns true if it has and false if hasn't. Maybe will be useful to someone. What would be an option to use it? maybe for an account quest, only a player in account can make the quest :p

add this in your data/lib/050-function.lua
LUA:
function hasAccountStorage(cid, key, value)
	
	if (not isPlayer(cid)) then
		return print("CID MUST BE A PLAYER!") and false
	end
	
	if (not isNumber(key) or not isNumber(value) ) then
		return print("KEY AND VALUE MUST BE NUMBERS!") and false
	end
	
	local id = db.getResult("select `account_id` from `players` where id = "..getPlayerGUID(cid)..";") 
	local players_list = db.getResult("select `id` from `players` where `account_id` = "..id:getDataInt("account_id")..";") 
	
	if players_list:getID() ~= -1 then 
		players = {}
		repeat 
			table.insert (players, players_list:getDataInt("id"))
		until not(players_list:next())
		
		local select_stor = db.getResult ("select * from `player_storage` where `player_id` in ("..table.concat (players, ",")..") and (`key` = "..key.." and `value` = "..value..") ;")
		res = select_stor:getID() > 0 and true or false
		
		if (res) then 
			select_stor:free()	
			id:free()
			players_list:free()
		end
		
	end

	return res
end

How to use it?

LUA:
if ( hasAccountStorageValue(cid, 3232, 4) ) then
        doPlayerSendCancel(cid, "You have already done this quest")
	
else
	doPlayerAddItem(cid, item, count)
end

Shortened version by Cykotitan

I hope you like it :3
Regards
 
Last edited:
Cool, useful when you want to do, for example, the quest which will be available one per account.

:)
 
will be fine if u add function
getAccountStorage(cid, key)

You can change the name to whatever you wish, if I used this, I would call it: hereBitchGetAllTheStorageInformationYouNeed(cid, key, value)
 
its already storage functions done in tfs.
getCreatureStorage(cid, key)
unnecessary waste of using mysql queries.
 
its already storage functions done in tfs.
getCreatureStorage(cid, key)
unnecessary waste of using mysql queries.

Could be useful for account-based donations or stuff like that.
Nobody could make multiple characters for free shit or whatnot.
 
LUA:
function hasAccountStorage(cid, key, value)
	if isPlayer(cid) == false then
		error("[hasAccountStorage] Player not found (cid=" .. tostring(cid) .. ")")
	elseif tonumber(key) == nil then
		error("[hasAccountStorage] Invalid key (key=" .. tostring(key) .. ")")
	else
		local q = db.getResult('SELECT player_id FROM player_storage LEFT JOIN players ON player_storage.player_id=players.id WHERE players.account_id=' .. getPlayerAccountId(cid) .. ' AND `key`=' .. key .. (value and ' AND value=' .. db.escapeString(value) or '') .. ' LIMIT 1')
		if q:getID() ~= -1 then
			q:free()
			return true
		end
	end
end
 
Last edited:
you mean the function name?

No, your functions return "true" or "false"

if account have storage with value = x then true, else false


create function which not check true or false, but check value of key storage


for example


account have 3 players, one of them have storage 1200 and value 3


in script we want to have:

if getAccountStorage(cid, 1200) == 2 then
lalala
elseif getAccountStorage(cid, 1200) == 3 then
blalblalala
else
tralalal
end


btw.; sorry for my fucking english
 
if getAccountStorage(cid, 1200) == 2 then
lalala
elseif getAccountStorage(cid, 1200) == 3 then
blalblalala
else
tralalal
end
how would this be useful in the real world?
also, if one of the players on account has a storage with value 3 and another player with 2, you might not get the wanted result
 
how would this be useful in the real world?
also, if one of the players on account has a storage with value 3 and another player with 2, you might not get the wanted result

for example

account Tralalala have characters:
Ziomek, Fiolek, Kutasek

player Ziomek has completed quest and have storage 350
player Fiolek has storage in this quest 200
player Kutasek has storage -1 in this quest

we want to know how much in total this account have value of storagekey

200+300 = 500
(if player have storage -1 then will be show as 0) (pl; jak ma storage -1 to pokazuje, ze ma 0)


it will be useful for example in tasks or in killed monster counter :)
for example we have NPC Countererus

selfSay("You have killed " .. getAccountStorage(cid, storage) .. " rats by all your characters. In this u have killed ".. getPlayerStorageValue(cid, storage) .." by " .. getPlayerName(cid) ..".", cid)
 
Back
Top