• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Reward Time System

pablobion

Member
Joined
Aug 31, 2016
Messages
39
Solutions
1
Reaction score
5
Does anyone have script that gives an item every one hour online on the server?

1 hour online on the server = 1 crystal coin
2 = 5 crystal coin
....

tfs 0.4
 
Solution
XML:
<event type="login" name="itemLogin" event="script" value="*****.lua"/>
<event type="logout" name="itemLogout" event="script" value="*****.lua"/>
in login.lua
Lua:
registerCreatureEvent(cid, "itemLogin")
registerCreatureEvent(cid, "itemLogout")

*****.lua
Lua:
local items = {
    [1] = {
        itemid = 2160,
        count = 1,
    },
    [2] = {
        itemid = 2160,
        count = 2
    }
}

local events = {}

local function addReward(cid, rewardId)
    if not isPlayer(cid) then
        return
    end
    local item = items[rewardId or #items]
    doPlayerAddItem(cid, item.itemid, item.count)
    events[cid] = addEvent(addReward, 60 * 60 * 1000, cid, rewardId + 1)
end

function onLogin(cid)
    events[cid] = addEvent(addReward, 60...
XML:
<event type="login" name="itemLogin" event="script" value="*****.lua"/>
<event type="logout" name="itemLogout" event="script" value="*****.lua"/>
in login.lua
Lua:
registerCreatureEvent(cid, "itemLogin")
registerCreatureEvent(cid, "itemLogout")

*****.lua
Lua:
local items = {
    [1] = {
        itemid = 2160,
        count = 1,
    },
    [2] = {
        itemid = 2160,
        count = 2
    }
}

local events = {}

local function addReward(cid, rewardId)
    if not isPlayer(cid) then
        return
    end
    local item = items[rewardId or #items]
    doPlayerAddItem(cid, item.itemid, item.count)
    events[cid] = addEvent(addReward, 60 * 60 * 1000, cid, rewardId + 1)
end

function onLogin(cid)
    events[cid] = addEvent(addReward, 60 * 60 * 1000, cid, 1)
    return true
end

function onLogout(cid)
    if events[cid] then
        stopEvent(events[cid])
        events[cid] = nil
    end
    return true
end
 
Solution
XML:
<event type="login" name="itemLogin" event="script" value="*****.lua"/>
<event type="logout" name="itemLogout" event="script" value="*****.lua"/>
in login.lua
Lua:
registerCreatureEvent(cid, "itemLogin")
registerCreatureEvent(cid, "itemLogout")

*****.lua
Lua:
local items = {
    [1] = {
        itemid = 2160,
        count = 1,
    },
    [2] = {
        itemid = 2160,
        count = 2
    }
}

local events = {}

local function addReward(cid, rewardId)
    if not isPlayer(cid) then
        return
    end
    local item = items[rewardId or #items]
    doPlayerAddItem(cid, item.itemid, item.count)
    events[cid] = addEvent(addReward, 60 * 60 * 1000, cid, rewardId + 1)
end

function onLogin(cid)
    events[cid] = addEvent(addReward, 60 * 60 * 1000, cid, 1)
    return true
end

function onLogout(cid)
    if events[cid] then
        stopEvent(events[cid])
        events[cid] = nil
    end
    return true
end

does tfs 1.2 work? I do not see 0.4
 
XML:
<event type="login" name="itemLogin" event="script" value="*****.lua"/>
<event type="logout" name="itemLogout" event="script" value="*****.lua"/>
in login.lua
Lua:
registerCreatureEvent(cid, "itemLogin")
registerCreatureEvent(cid, "itemLogout")

*****.lua
Lua:
local items = {
    [1] = {
        itemid = 2160,
        count = 1,
    },
    [2] = {
        itemid = 2160,
        count = 2
    }
}

local events = {}

local function addReward(cid, rewardId)
    if not isPlayer(cid) then
        return
    end
    local item = items[rewardId or #items]
    doPlayerAddItem(cid, item.itemid, item.count)
    events[cid] = addEvent(addReward, 60 * 60 * 1000, cid, rewardId + 1)
end

function onLogin(cid)
    events[cid] = addEvent(addReward, 60 * 60 * 1000, cid, 1)
    return true
end

function onLogout(cid)
    if events[cid] then
        stopEvent(events[cid])
        events[cid] = nil
    end
    return true
end




Code:
Event onAdvance not found. data/creaturescripts/scripts/rewards.lua

I get this error in console
 
I need the exact same script but for TFS 1.3 :D
5cc every hour you are online :D
try this globalevent, not tested
XML:
<globalevent name="OnlinePoints" interval="1800000" script="others/online_points.lua" />

Lua:
    local config = {
    storageTime = 25230, -- storage time online
    timeMax = (20000), -- 1 hour
    pointsPerTime = 1, -- 1 point per hour
    itemPoint = 2160 -- item per hour
    }

    function onThink(interval)

    for _, player in ipairs(Game.getPlayers()) do
    local playerIp = player:getIp()
    if (playerIp ~= 0) then
    local time = player:getStorageValue(config.storageTime)
    if (time < 0) then time = 0 end
    if (time >= config.timeMax) then
    player:setStorageValue(config.storageTime, 0)
    player:addItem(config.itemPoint, config.pointsPerTime)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'You recieved ' .. config.pointsPerTime .. ' ' .. ItemType(config.itemPoint):getName() .. ' because 30 minutes of gameplay has passed in Greed.')
    else
    player:setStorageValue(config.storageTime, (time + interval))
    end end end

    return true
    end
 
try this globalevent, not tested
XML:
<globalevent name="OnlinePoints" interval="1800000" script="others/online_points.lua" />

Lua:
    local config = {
    storageTime = 25230, -- storage time online
    timeMax = (20000), -- 1 hour
    pointsPerTime = 1, -- 1 point per hour
    itemPoint = 2160 -- item per hour
    }

    function onThink(interval)

    for _, player in ipairs(Game.getPlayers()) do
    local playerIp = player:getIp()
    if (playerIp ~= 0) then
    local time = player:getStorageValue(config.storageTime)
    if (time < 0) then time = 0 end
    if (time >= config.timeMax) then
    player:setStorageValue(config.storageTime, 0)
    player:addItem(config.itemPoint, config.pointsPerTime)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'You recieved ' .. config.pointsPerTime .. ' ' .. ItemType(config.itemPoint):getName() .. ' because 30 minutes of gameplay has passed in Greed.')
    else
    player:setStorageValue(config.storageTime, (time + interval))
    end end end

    return true
    end
Thx! This worked perfectly!
 
sorry for bumping this, i'm having this error with the 0.4 script I know it is caused by a loop on the tables, I was looking this post but couldn't get it, can someone fix this so I can get the example, please, thanks in advance!

View attachment 46695
change line 19 to
Lua:
local item = items[rewardId <= #items and rewardId or #items]
 
did you get the script for 1.3?

change
Lua:
local item = player:addItem(config.pointItemId, config.pointsPerHour)
for
Lua:
player:addTibiaCoins(amount)

and delye in congif itemID, if u want tibia coins.
 
Back
Top