Hello OtLand,
Here I have an amazing script for an amazing function for a Tibia Otserv. The only problem is that it was written to be used in TFS1.2 and I have 0.4. Can you guys help me out converting this script? If its not possible, thats fine, just let me know!! Thanks in advance yall.
Here I have an amazing script for an amazing function for a Tibia Otserv. The only problem is that it was written to be used in TFS1.2 and I have 0.4. Can you guys help me out converting this script? If its not possible, thats fine, just let me know!! Thanks in advance yall.
LUA:
function onLogin(player)
player:registerEvent("FriendsPoints")
if player:getStorageValue(_invite_friends.storages[1]) < 0 then
player:setStorageValue(_invite_friends.storages[1], 0)
player:setStorageValue(_invite_friends.storages[4], 0)
end
if getInvitePoints(player) > 0 then
local acc = player:getAccountId()
local FriendPoints, CheckPoints = getInvitePoints(player), player:getStorageValue(_invite_friends.storages[4])
for vod, ka in pairs(_invite_friends.rewards) do
local str = ""
if FriendPoints >= vod and CheckPoints < vod then
str = str.."--> Invite Players System <--\n\nVocê acaba de receber algumas recompensas:\n\nItems: \n"..getItemsFromList(ka.items)..".\n\n"
if ka.p_days > 0 then
player:addPremiumDays(ka.p_days)
str = str.."Premium Days:\n"..ka.p_days.." Premium Days."
end
if ka.p_points > 0 then
db.executeQuery('UPDATE accounts SET premium_points=premium_points+' .. ka.p_points ..' WHERE id=' .. acc)
str = str.."Premium Points:\n"..ka.p_points.." Premium Points."
end
if ka.out[1] > 0 then
player:addOutfitAddon(player:getSex() == PLAYERSEX_FEMALE and ka.out[1] or ka.out[2], 3)
str = str.."[New Outfit]\nRecebeu uma Nova Outfit."
end
if ka.mount_id > 0 then
player:addMount(ka.mount_id)
str = str.."[New Outfit]\nRecebeu uma Nova Montaria."
end
player:setStorageValue(_invite_friends.storages[4], FriendPoints)
local town_id = player:getTown():getId()
if #ka.items > 0 then
local parcel = player:getDepotChest(town_id, true):addItem(2595)
for _, i_i in ipairs(ka.items) do
local item, amount = i_i[1],i_i[2]
if isItemStackable(item) or amount == 1 then
parcel:addItem(item, amount)
else
for i = 1, amount do
parcel:addItem(item, 1)
end
end
end
end
local townid = player:getTown():getId()
local letter = player:getDepotChest(town_id, true):addItem(2598, 1, true, 1)
letter:setAttribute(ITEM_ATTRIBUTE_WRITER, "[+] Invite Players System [+]")
letter:setAttribute(ITEM_ATTRIBUTE_TEXT, str)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE,"[Invite Players System] Você Recebeu algumas premiações por estar convidando jogadores para o servidor, Por favor conferir os itens no Depot.")
end
end
end
return true
end
function onAdvance(player, skill, oldlevel, newlevel)
if (skill == SKILL__LEVEL) then
if hasInviteFriend(player) and player:getStorageValue(_invite_friends.storages[3]) < newlevel and _invite_friends.levels_win[newlevel] then
local f_name, points = getNameFriend(player), _invite_friends.levels_win[newlevel]
player:setStorageValue(_invite_friends.storages[3], newlevel)
addInvitePoints(f_name, points)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "[Invite Friends] você atingiu o level "..newlevel.." e o seu amigou "..f_name.." recebeu "..points.." Friend Points. Obrigado!")
end
end
return true
end
LUA:
_invite_friends = {
storages = {202301, 202302, 202303, 202304}, -- points, jogador, recompensa lvl, recompensa items
level_max = 30, -- até que level ele precisa falar seu friend
level_need = 50, -- que lever o jogador precisa ser para ganhar pontos
levels_win = {
[50] = 5,
[80] = 6,
[100] = 8,
[150] = 10
},
rewards = {
[10] = {items = {{2160,1},{2173,1}}, p_days = 0, mount_id = 0, p_points = 0 , out = {0,0}},
[25] = {items = {{2160,2},{2173,1}}, p_days = 0, mount_id = 0, p_points = 0 , out = {0,0}},
[50] = {items = {{2160,3},{2173,1}}, p_days = 0, mount_id = 0, p_points = 0 , out = {0,0}},
[100] = {items = {{2160,4},{2173,1}}, p_days = 0, mount_id = 0, p_points = 0 , out = {0,0}},
[200] = {items = {{2160,5},{2173,1}}, p_days = 0, mount_id = 0, p_points = 0 , out = {0,0}},
[250] = {items = {{2160,6},{2173,1}}, p_days = 0, mount_id = 0, p_points = 0 , out = {0, 0}},
[500] = {items = {{2160,7},{2173,1}}, p_days = 0, mount_id = 0, p_points = 0 , out = {0,0}}
}
}
function getInvitePoints(cid)
local cid = Player(cid)
if cid == nil then
return false
end
return getPlayerStorageValue(cid, _invite_friends.storages[1]) < 0 and 0 or getPlayerStorageValue(cid, _invite_friends.storages[1])
end
function hasInviteFriend(cid)
local cid = Player(cid)
if cid == nil then
return false
end
return getPlayerStorageValue(cid, _invite_friends.storages[2]) > 0 and true or false
end
function getNameFriend(cid)
local cid = Player(cid)
if cid == nil then
return false
end
return getPlayerNameByGUID(getPlayerStorageValue(cid, _invite_friends.storages[2]))
end
function addInvitePoints(name, amount)
local pid, Guid = getPlayerByName(name), getPlayerGUIDByName(name)
if not pid then
local getFriendPoints = db.storeQuery("SELECT `value` FROM `player_storage` WHERE `player_id` = ".. Guid .." AND `key` = ".._invite_friends.storages[1])
if getFriendPoints ~= false then
db.asyncQuery("UPDATE `player_storage` SET `value` = ".. (result.getDataInt(getFriendPoints, "value")+amount) .." WHERE `player_id` = ".. Guid .." AND `key` = ".._invite_friends.storages[1])
end
else
setPlayerStorageValue(getPlayerByName(name), _invite_friends.storages[1], getInvitePoints(getPlayerByName(name))+amount)
end
return true
end
function getItemsFromList(items) -- by vodka
local str = ''
if table.maxn(items) > 0 then
for i = 1, table.maxn(items) do
str = str .. items[i][2] .. ' ' .. ItemType(items[i][1]):getName()
if i ~= table.maxn(items) then str = str .. ', ' end end end
return str
end
function getPlayerNameByGUID(guid)
local a = db.storeQuery('SELECT `name` FROM `players` WHERE `id` = ' .. guid .. ' LIMIT 1')
if a then
return result.getDataString(a, "name")
end
return nil
end
function PlayerExist(name) -- by vodka
local a = db.storeQuery('SELECT `id` FROM `players` WHERE `name` = ' .. db.escapeString(name))
if a ~= false then
return true
end
return false
end
LUA:
function onSay(player, words, param)
local param = param:lower()
if param == "" or not param then
player:sendCancelMessage("Você precisa digitar o nome de um jogador.") return false
elseif param == "points" then
player:popupFYI("[+] Invite Friend System [+]\n\nvocê tem ["..getInvitePoints(player).."] Friends Points.") return false
elseif hasInviteFriend(player) then
player:sendCancelMessage("Você já agradeceu o jogador ["..getNameFriend(player).."] por te convidar a jogar neste servidor.") return false
elseif not getPlayerGUIDByName(param) then
player:sendCancelMessage("Desculpe, mas o jogador [" .. param .. "] não existe.") return false
elseif player:getLevel() > _invite_friends.level_max or result.getDataInt(db.storeQuery("SELECT `level` FROM `players` WHERE `id` = "..getPlayerGUIDByName(param)), "level") < _invite_friends.level_need then
player:sendCancelMessage((player:getLevel() > _invite_friends.level_max and "Desculpe, mas você precisa ter no maximo level ".._invite_friends.level_max.." para usar este comando." or "Desculpe, mas o jogador ["..param.."] precisa ter no minimo level ".._invite_friends.level_need.." para ser escolhido.")) return false
elseif player:getName():lower() == param then
player:sendCancelMessage("Desculpe, mas você não pode se auto invitar.") return false
end
player:setStorageValue(_invite_friends.storages[2], getPlayerGUIDByName(param))
player:sendTextMessage(25, "Você indicou o jogador "..param..", este sistema é uma forma de agradecer a vocês por trazerem seus amigos para jogar.")
player:getPosition():sendMagicEffect(math.random(28,30))
return false
end