- Joined
- Mar 16, 2017
- Messages
- 1,439
- Solutions
- 158
- Reaction score
- 2,034
- Location
- London
- GitHub
- MillhioreBT
- Twitch
- millhiorebt
This is a very common script, I even posted a similar one a long time ago, but I still want to post the version for TFS 1.5.
for tfs 1.4 click here
Rewards by online time.
This is a normal reward:
This is a reward for adding points to a database variable:
This is the interval of the event:
- If your server is affected by this script, perhaps you can try increasing the interval to
Check if player has IP:
- If set to false, then players without IP can still count points online.
Check if any player on the same account is already earning points online:
- If set to false, then all players regardless of the same account will still count points.
Number of players with the same IP or with the same account allowed:
- This variable works if any of the options
Storage key, this will be used to keep track of the seconds that have elapsed during the player's online time:
for tfs 1.4 click here
Rewards by online time.
data/scripts/rewardsbyonlinetime.lua
Lua:
--๐๐ฒ๐ต๐ต๐ฑ๐ฒ๐ธ๐ป๐ฎ ๐๐ฃ
local config = {
seconds = 3600, -- 1 hour
eventInterval = 1000, -- 1 second
checkIP = true,
checkAccount = true,
allowMCs = 3,
storageKey = 73106,
rewards = {
{ itemId = 2160, count = 100 },
{ name = "premium points", itemDb = 'accounts', value = 'premium_points', count = 100 }
}
}
local onlineTimeRewards = GlobalEvent("onlineTimeRewards")
function onlineTimeRewards.onThink(interval)
local duplicateIps = {}
local duplicateAccounts = {}
for _, player in pairs(Game.getPlayers()) do repeat
local ip = player:getIp()
if config.checkIP and ip == 0 or (duplicateIps[ip] or 0) >= config.allowMCs then
break
end
duplicateIps[ip] = duplicateIps[ip] and duplicateIps[ip] + 1 or 1
local accountId = player:getAccountId()
if config.checkAccount and (duplicateAccounts[accountId] or 0) >= config.allowMCs then
break
end
duplicateAccounts[accountId] = duplicateAccounts[accountId] and duplicateAccounts[accountId] + 1 or 1
local seconds = math.max(player.storage[storageKey], 0) + math.ceil(interval/1000)
if seconds >= config.seconds then
player.storage[storageKey] = 0
local rewards = {}
for _, reward in pairs(config.rewards) do
if reward.itemDb then
if db.query(string.format("UPDATE `%s` SET `%s` = `%s` + %d WHERE `id` = %d", reward.itemDb, reward.value, reward.value, reward.count, accountId)) then
rewards[#rewards + 1] = string.format('%s x%d', reward.name, reward.count)
else
print(string.format("[onlineTimeRewards] Error while rewarding player %s.", player:getName()))
end
else
local item = player:addItem(reward.itemId, reward.count)
if item then
rewards[#rewards + 1] = string.format('%s x%d', item:getName(), reward.count)
end
end
end
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received the following reward(s): " .. table.concat(rewards, ', '))
break
end
player.storage[storageKey] = seconds
until true end
return true
end
onlineTimeRewards:interval(config.eventInterval)
onlineTimeRewards:register()
This is a normal reward:
{ itemId = 2160, count = 100 } -- 100 crystal coins.
This is a reward for adding points to a database variable:
{ name = "premium points", itemDb = 'accounts', value = 'premium_points', count = 100 } -- 100 premium points.
This is the interval of the event:
- If your server is affected by this script, perhaps you can try increasing the interval to
2000
, 3000
, 10000
, although if you set very large intervals the script may lose a bit of efficiency and not grant very much. accuracy the rewards in the estimated time.eventInterval = 1000, -- 1 second
Check if player has IP:
- If set to false, then players without IP can still count points online.
checkIP = true
Check if any player on the same account is already earning points online:
- If set to false, then all players regardless of the same account will still count points.
checkAccount = true
Number of players with the same IP or with the same account allowed:
- This variable works if any of the options
checkIP
, checkAccount
is true.allowMCs = 3
Storage key, this will be used to keep track of the seconds that have elapsed during the player's online time:
storageKey = 73106
Last edited: