vlw muito bom + REP
- Forums
- OTServ
- Recursos
- Scripting
- Mods, funções e outros
- Hasaccountstorage(Cid, Key, Value)
6
1.1k
info
Group: Cavaleiro
Joined: 20/10/11
Posts: 182
Reputation: +85
Tibia Character: Eu

25 de janeiro de 2012 às 19:20
info
Group: Conde
Joined: 16/06/08
Posts: 998
Reputation: +185
Gender: Masculino

25 de janeiro de 2012 às 20:38
hmm massa a função
esse error é a mesma coisa que print?
info
Group: Herói
Joined: 20/05/10
Posts: 3.4k
Reputation: +1.5k
Gender: Masculino

25 de janeiro de 2012 às 21:39
hmm massa a função
esse error é a mesma coisa que print?
sim,vai dar a mensagem no executável do ot
info
Group: Infante
Joined: 13/10/08
Posts: 1.6k
Reputation: +420
Tibia Character: Demonbholder

25 de janeiro de 2012 às 21:50
Na verdade, a função error() dispara um erro, terminando a execução da função/código.
Ao contrário da função print(), que simplesmente imprimi uma string no interpretador.
Legal a função, parabéns aos criadores.




info
Group: Herói
Joined: 20/05/10
Posts: 3.4k
Reputation: +1.5k
Gender: Masculino
Autor: Jetro
Explicação: É uma função que serve para saber se a conta possui ou não uma certa Key(Storage),muito usada para aquelas situações de jogadores quando alcançarem um determinado level ganharem dias de vip ou premium,não tem aquele bug de todos os jogadores da conta pegarem esses dias.
adicione em data/lib/050-function.lua
Version by Jetro:
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 endVersion by Cykotitan:
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 endExemplo de como usar: