• 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!

TFS 1.X+ How add premium days

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
151
Reaction score
9
Hello guys, how can i add premium days? I saw my database, have a long number in premium table... i need make some tests when the player lose premium, for example can i add less them 1 day? Or 1 minute of premium?
 
Solution
Hello guys, how can i add premium days? I saw my database, have a long number in premium table... i need make some tests when the player lose premium, for example can i add less them 1 day? Or 1 minute of premium?
Functions for premium days are:
Lua:
player:getPremiumDays()
player:addPremiumDays(days)
player:removePremiumDays(days)

No you cannot use these functions to manipulate premium to the hour, minute or second. If you want to remove a premium day for testing purposes you will have to change lastday within the database.

As you can see here: https://github.com/otland/forgottenserver/blob/46658953a9a31a38a2840d8d4ba3a247ea25b733/src/game.cpp#L4658

The column lastday in database is what is used to determine when a...
Hello guys, how can i add premium days? I saw my database, have a long number in premium table... i need make some tests when the player lose premium, for example can i add less them 1 day? Or 1 minute of premium?
Functions for premium days are:
Lua:
player:getPremiumDays()
player:addPremiumDays(days)
player:removePremiumDays(days)

No you cannot use these functions to manipulate premium to the hour, minute or second. If you want to remove a premium day for testing purposes you will have to change lastday within the database.

As you can see here: https://github.com/otland/forgottenserver/blob/46658953a9a31a38a2840d8d4ba3a247ea25b733/src/game.cpp#L4658

The column lastday in database is what is used to determine when a premium day must be removed, so if you edit this number subtracting 86,000 from it (total seconds in a day) then the next time you log in the premium will be one day less.
 
Solution
Lua:
-- Register premium scroll action

local premiumScroll = Action()

premiumScroll:id(5546)



function premiumScroll.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local premiumDays = 30 -- Number of days to add as premium



    -- Calculate the timestamp for the premium end time (in seconds)

    local SECONDS_IN_DAY = 24 * 60 * 60

    local timestamp = os.time() + (premiumDays * SECONDS_IN_DAY)



    -- Set the premium end time for the player

    player:setPremiumEndsAt(timestamp)



    -- Inform the player about the premium upgrade

    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have been upgraded to premium account for 30 days!")



    -- Remove the premium scroll from the player's inventory

    item:remove(1)



    return true

end



premiumScroll:register()
revscript just change item id to some tome for 7.x versions which players cant have or some items like ball gown etc.



for nekiro 1.5
 
Lua:
-- Register premium scroll action

local premiumScroll = Action()

premiumScroll:id(5546)



function premiumScroll.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local premiumDays = 30 -- Number of days to add as premium



    -- Calculate the timestamp for the premium end time (in seconds)

    local SECONDS_IN_DAY = 24 * 60 * 60

    local timestamp = os.time() + (premiumDays * SECONDS_IN_DAY)



    -- Set the premium end time for the player

    player:setPremiumEndsAt(timestamp)



    -- Inform the player about the premium upgrade

    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have been upgraded to premium account for 30 days!")



    -- Remove the premium scroll from the player's inventory

    item:remove(1)



    return true

end



premiumScroll:register()
revscript just change item id to some tome for 7.x versions which players cant have or some items like ball gown etc.



for nekiro 1.5
This will force the player to have exactly 30 days of premium time.
There is use-cases for this.. but I'm pretty certain everyone wants to just add additional premium time.. not set it to exactly 30 days.

So if you wanted to add additional premium time.. do something like this

Lua:
local currentTime = os.time()
local currentPremiumTime = math.max(0, player:getPremiumEndsAt() - currentTime)

local days = 30
local secondsToAdd = days * 24 * 60 * 60

player:setPremiumEndsAt(currentTime + (currentPremiumTime + secondsToAdd))
 
This will force the player to have exactly 30 days of premium time.
There is use-cases for this.. but I'm pretty certain everyone wants to just add additional premium time.. not set it to exactly 30 days.

So if you wanted to add additional premium time.. do something like this

Lua:
local currentTime = os.time()
local currentPremiumTime = math.max(0, player:getPremiumEndsAt() - currentTime)

local days = 30
local secondsToAdd = days * 24 * 60 * 60

player:setPremiumEndsAt(currentTime + (currentPremiumTime + secondsToAdd))
actually works.


Lua:
-- Register premium scroll action
local premiumScroll = Action()
premiumScroll:id(5546)

function premiumScroll.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local currentTime = os.time()
    local currentPremiumTime = math.max(0, player:getPremiumEndsAt() - currentTime)

    local days = 30
    local secondsToAdd = days * 24 * 60 * 60

    player:setPremiumEndsAt(currentTime + (currentPremiumTime + secondsToAdd))
    -- Inform the player about the premium upgrade
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have been upgraded to premium account for 30 days!")
    player:getPosition():sendMagicEffect(84)
    -- Remove the premium scroll from the player's inventory
    item:remove(1)

    return true
end

premiumScroll:register()



-- Register premium scroll action
local weeklypremiumScroll = Action()
weeklypremiumScroll:id(5545)

function weeklypremiumScroll.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   -- local premiumDays = 7 -- Number of days to add as premium

    -- Calculate the timestamp for the premium end time (in seconds)
   -- local SECONDS_IN_DAY = 24 * 60 * 60
    local timestamp = os.time() + (premiumDays * SECONDS_IN_DAY)


    local currentTime = os.time()
    local currentPremiumTime = math.max(0, player:getPremiumEndsAt() - currentTime)

    local days = 7
    local secondsToAdd = days * 24 * 60 * 60

    player:setPremiumEndsAt(currentTime + (currentPremiumTime + secondsToAdd))
    -- Set the premium end time for the player
   -- player:setPremiumEndsAt(timestamp)



    -- Inform the player about the premium upgrade
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have been upgraded to premium account for 7 days!")
    player:getPosition():sendMagicEffect(80)
    -- Remove the premium scroll from the player's inventory
    item:remove(1)

    return true
end

weeklypremiumScroll:register()
 
Back
Top