guiismiti
Well-Known Member
- Joined
- May 19, 2014
- Messages
- 315
- Solutions
- 3
- Reaction score
- 68
Hello!
I wrote this today for my server, and I remember seeing some unanswered threads in OTLand asking for it.
What it does is, it checks for other characters in the same account and then checks the houses table for an owner with that id.
There are two advantages over using an extra attribute in 'accounts' in your DB:
If you are afraid of spoofing with !buyhouse, use a player storage with some kind of cooldown.
Place this in the end of the file lib/miscellaneous/050-functions.lua
If you have a !buyhouse talkaction, add this check:
If you have a !sellhouse talkaction, add this check:
If your server has other means of getting a house in game, don't forget to add the check to them.
I wrote this today for my server, and I remember seeing some unanswered threads in OTLand asking for it.
What it does is, it checks for other characters in the same account and then checks the houses table for an owner with that id.
There are two advantages over using an extra attribute in 'accounts' in your DB:
- you don't need to make an extra modification in your DB;
- there are too many ways a player can loose a house, and you would need to think of all of them in order to change the house key in 'accounts' for every hypothesis.
If you are afraid of spoofing with !buyhouse, use a player storage with some kind of cooldown.
Place this in the end of the file lib/miscellaneous/050-functions.lua
Lua:
function checkAccHouses(player)
-- returns true if there is another character that already owns a house in the same account
local playerAccId = player:getAccountId()
local resultId = db.storeQuery('SELECT `id` FROM `players` WHERE `account_id` = ' .. playerAccId)
if resultId ~= false then
repeat
local playerId = result.getNumber(resultId, 'id')
local ownerId = db.storeQuery('SELECT `id` FROM `houses` WHERE `owner` = ' .. playerId)
if ownerId ~= false then
return true
end
until not result.next(resultId)
result.free(resultId)
end
return false
end
Lua:
if checkAccHouses(player) then
player:sendCancelMessage("You already own a house with this account.")
return false
end
Lua:
if checkAccHouses(tradePartner) then
player:sendCancelMessage("The buyer already owns a house with his account.")
return false
end