• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Premium account to free account

Set a certain storage key to a player when they purchase premium time.
Code:
player:setStorageValue(storageKey, 1)

and add something like this to your login.lua
Code:
if player:getPremiumDays() == 0 and player:getStorageValue(storageKey) == 1 then
    player:setStorageValue(storageKey, 0)
    player:setTown(Town(2)) -- Thais
    player:teleportTo(player:getTown():getTemplePosition())
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
 
Set a certain storage key to a player when they purchase premium time.
Code:
player:setStorageValue(storageKey, 1)

and add something like this to your login.lua
Code:
if player:getPremiumDays() == 0 and player:getStorageValue(storageKey) == 1 then
    player:setStorageValue(storageKey, 0)
    player:setTown(Town(2)) -- Thais
    player:teleportTo(player:getTown():getTemplePosition())
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
Do I add player:setStorageValue(storageKey, 1) to my ACC config file? I believe that is where they purchase premium.
Also I have it saved in vocations.xml for promotions to still be available when player is free account by using prem="0"
But when the account changes to free account they are non promoted. Any way around that? Thank you for your reply.
 
Do I add player:setStorageValue(storageKey, 1) to my ACC config file? I believe that is where they purchase premium.
Add this to your login.lua
Code:
if player:getPremiumDays() > 0 and player:getStorageValue(storageKey) ~= 1 then
    player:setStorageValue(storageKey, 1)
elseif player:getPremiumDays() == 0 and player:getStorageValue(storageKey) == 1 then
    player:setStorageValue(storageKey, 0)
    player:setTown(Town(2)) -- Thais
    player:teleportTo(player:getTown():getTemplePosition())
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
Also I have it saved in vocations.xml for promotions to still be available when player is free account by using prem="0"
But when the account changes to free account they are non promoted. Any way around that? Thank you for your reply.
Yes, you can change this in game.cpp, put a comment block around this code (/* code */)
Code:
else if (player->isPromoted()) {
    player->setVocation(player->vocation->getFromVocation());
}
 
Yes, you can change this in game.cpp, put a comment block around this code (/* code */)
Code:
else if (player->isPromoted()) {
    player->setVocation(player->vocation->getFromVocation());
}
[/QUOTE]

I have never edited a .cpp file before. Can I do this in wordpad or do I need to use MS visual? Also whats a comment block would it look like this:

/* else if (player->isPromoted()) {
player->setVocation(player->vocation->getFromVocation());
} */

Sorry, I don't have much experience in this part of editing the server. I really appreciate your reply.
 
Last edited:
It didn't work. Even the first part about the login.lua didn't work. This is what I added:

function onLogin(cid)
local player = Player(cid)

local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
if player:getLastLoginSaved() <= 0 then
loginStr = loginStr .. " Please choose your outfit."
player:sendOutfitWindow()
else
if loginStr ~= "" then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
end

loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
end
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

player:registerEvent("PlayerDeath")
return true
end

if player:getPremiumDays() > 0 and player:getStorageValue(storageKey) ~= 1 then
player:setStorageValue(storageKey, 1)
elseif player:getPremiumDays() == 0 and player:getStorageValue(storageKey) == 1 then
player:setStorageValue(storageKey, 0)
player:setTown(Town(2)) -- Thais
player:teleportTo(player:getTown():getTemplePosition())
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
 
http://pastebin.com/LQLqnRx0, Don't forget to replace storageKey with the storage key of your choice.
Yes, you can change this in game.cpp, put a comment block around this code (/* code */)
Code:
else if (player->isPromoted()) {
    player->setVocation(player->vocation->getFromVocation());
}

I have never edited a .cpp file before. Can I do this in wordpad or do I need to use MS visual? Also whats a comment block would it look like this:

/* else if (player->isPromoted()) {
player->setVocation(player->vocation->getFromVocation());
} */

Sorry, I don't have much experience in this part of editing the server. I really appreciate your reply.
Yes, that's correct and you need Visual Studio 2013 for compilation (tutorial).
 
http://pastebin.com/LQLqnRx0, Don't forget to replace storageKey with the storage key of your choice.
Okay, I figured out the storagekey system. I can use any storage key, cool I didn't know about that thank you 100x. I'm still stuck on the compiling. I have no idea how to do it and will check out the tutorial, but do I need to compile the WHOLE server or can I just compile/edit that game.cpp file?
 
Okay, I figured out the storagekey system. I can use any storage key, cool I didn't know about that thank you 100x. I'm still stuck on the compiling. I have no idea how to do it and will check out the tutorial, but do I need to compile the WHOLE server or can I just compile/edit that game.cpp file?
you need to edit game.cpp and then recompile the whole server with all the other files, but is just pressing a button (i think so)
 
you need to edit game.cpp and then recompile the whole server with all the other files, but is just pressing a button (i think so)
Will that change all of the files I've already edited? (Like vocations.xml, spells.xml, login.lua) I don't want to have to change those again.
 
Yes, that's correct and you need Visual Studio 2013 for compilation (tutorial).
Ninja, isn't there a simple code I can use instead of compiling the server? Like in login after all of this:

if player:getPremiumDays() > 0 and player:getStorageValue(storageKey) ~= 1 then
player:setStorageValue(storageKey, 1)
elseif player:getPremiumDays() == 0 and player:getStorageValue(storageKey) == 1 then
player:setStorageValue(storageKey, 0)
player:setTown(Town(2)) -- Thais
player:teleportTo(player:getTown():getTemplePosition())
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end

Could I just have a command like "giveplayerpromotion" if the player is level 20. So that way they will lose their promotion with the premium account, but the code would give it back to them as soon as they log in
 
Will that change all of the files I've already edited? (Like vocations.xml, spells.xml, login.lua) I don't want to have to change those again.
this files have nothing to do, and you will not have to change them again

To recompile a server you need the sources of it, do you have them?
let's say that you are just changing the .exe file when you edit the game.cpp
 
Last edited:
this files have nothing to do, and you will not have to change them again

To recompile a server you need the sources of it, do you have them?
let's say that you are just changing the .exe file when you edit the .cpp
Okay that makes sense. I do have the sources. The only reason I'm trying not to compile it, is I already tried 3 tutorials and every time I open theforgottenserver.sln in the vc12 folder I get an error.
 
I just tried it again. I went into configuration manager changed the drop down menu to "release" and the other to "x64"
then when i hit build, this comes up
Error 1 error C1083: Cannot open include file: 'boost/asio.hpp': No such file or directory c:\users\miller\documents\krithonia\src\otpch.h 30 1 theforgottenserver
 
what are you trying to do? to tp the player to thais when the premium expires, use the code ninja posted
Actually I had a successful build when I re-installed boost. The code Ninja gave me doesn't work. When I set the premium days to 0 in the database to test it out, the character still remained in darashia. He only lost his promotion. This is my login.lua

function onLogin(cid)
local player = Player(cid)

local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
if player:getLastLoginSaved() <= 0 then
loginStr = loginStr .. " Please choose your outfit."
player:sendOutfitWindow()
else
if loginStr ~= "" then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
end

loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
end
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

if player:getPremiumDays() > 0 and player:getStorageValue(storageKey, 0) ~= 1 then
player:setStorageValue(storageKey, 1)
elseif player:getPremiumDays() == 0 and player:getStorageValue(storageKey, 1) == 1 then
player:setStorageValue(storageKey, 0)
player:setTown(Town(2)) -- Thais
player:teleportTo(player:getTown():getTemplePosition())
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end

player:registerEvent("PlayerDeath")
return true
end
 
Players get premium from my website, NOT in game with any codes like !buypremium. Is that what may be causing the problem? Because if I understand it correct, login.lua is for characters not for the account. Am I right?
 
Actually I had a successful build when I re-installed boost. The code Ninja gave me doesn't work. When I set the premium days to 0 in the database to test it out, the character still remained in darashia. He only lost his promotion.
you could open the source files? then edit that on game.cpp

any error with the code that ninja gave?
 
Back
Top