Olá a todos, e estou de volta pra postar alguns conteúdos...
Fui atrás de um online bonus system para tfs 1.3 e não achei e portanto decidi fazer o meu, com a ajuda do @vankk.
================================================================================================================
Testado em TFS 1.3 na versão 8.60.
================================================================================================================
================================================================================================================
No seu banco de dados, execute a seguinte query
ALTER TABLE `players` ADD `online_time` int(11) NOT NULL DEFAULT 0
================================================================================================================
O próximo passo é apenas para quem gostaria de que, a cada server save, o número seja zerado!
================================================================================================================
Em globalevents/scripts/startup.lua, após o inicio da função onStartup() adicione o seguinte código
db.query("UPDATE `players` SET `online_time` = 0")
================================================================================================================
Agora crie um arquivo chamado onlinebonus.lua em creaturescripts/scripts com isso dentro
local event = {}
local function addOnlineToken(playerId)
local player = Player(playerId)
if not player then
return false
end
if player:getIp() == 0 then
event[player:getId()] = nil
return false
end
player:addOnlineTime(1)
player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você ganhou 1 online token por permanecer online por 1 hora sem deslogar.")
player:addItem(12543, 1)
event[player:getId()] = addEvent(addOnlineToken, 60 * 60 * 1000, player:getId())
end
function onLogin(player)
player:registerEvent("OnlineBonus")
player:registerEvent("OnlineBonusLogout")
if event[player:getId()] == nil then
event[player:getId()] = addEvent(addOnlineToken, 60 * 60 * 1000, player:getId())
end
return true
end
function onLogout(player)
if event[player:getId()] then
event[player:getId()] = nil
end
return true
end
-- <event type="login" name="OnlineBonus" script="onlineBonus.lua" />
-- <event type="logout" name="OnlineBonusLogout" script="onlineBonus.lua" />
A tag XML está no fim desse código.
================================================================================================================
Agora, na pasta lib, crie um arquivo chamado onlineTime.lua e coloque isso dentro
function Player.getOnlineTime(self)
local resultId = db.storeQuery(string.format('SELECT online_time FROM `players` WHERE `id` = %d', self:getGuid()))
if not resultId then
return 0
end
local value = result.getNumber(resultId, "online_time")
result.free(resultId)
return value
end
function Player.addOnlineTime(self, amount)
db.query(string.format("UPDATE `players` SET `online_time` = `online_time` + %d WHERE `id` = %d", amount, self:getGuid()))
end
Não esqueça de registrar essa lib no lib.lua.
================================================================================================================
Agora, na pasta talkactions/scripts, crie um arquivo chamado onlinebonus.lua com o seguinte código dentro:
function onSay(player, words, param)
local skill = player:getOnlineTime(player)
local message = "--------[+]------- [Online Bonus System] -------[+]--------\n\nGanhe um online token a cada hora que você passa online sem deslogar.\n\n---------------------------------------------------\n Total\n Desde o server save você já ganhou " .. skill .. " online tokens."
doPlayerPopupFYI(player, message)
end
-- <talkaction words="!onlinebonus" script="onlineBonus.lua"/>
A tag XML está no fim desse código.
================================================================================================================
O usuário irá receber um item a cada hora online sem deslogar.
O item está no código de creaturescripts com o id 12543, que pode ser alterado para qualquer item que seja agrupável.
================================================================================================================
É isso por hoje.