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

Lua System for de-leveling offline character skills/experience

E

Evil Puncker

Guest
tfs latest.

So I had a crazy idea to solve one of the issues that happen to new players in old ots: they need to work TOO hard to surpass offline/inactive characters (I mean, people that doesn't play anymore but still got plenty of experience and skills), so I was thinking about a system that would be executed on server startup (just like those house cleaners/account purge systems) and the system will reduce X% of character experience every Y days and reduce Z% of character skill tries and mana spent.

The part I mentioned before should be really easy to do with a few SQL queries... The tricky part thought: recalculate all the character stats (new: level, health, mana, cap, skills, magic level, etc) while offline (remember it is planned to be used only on characters that didn't have logged in for a certain amount of days)...

Known side effects:
  • character will be carrying more items than the cap its have
  • character will have higher level items than he can use
but I see no problem on these and can have them ignored


I don't know if anyone is going to work on this, it was just an idea I had in my mind and didn't wanted to throw it away
 
I don't know if anyone is going to work on this, it was just an idea I had in my mind and didn't wanted to throw it away
Hey,
I appreciate your huge contributions to the tibia community overall, especially TFS development, not sure if this code will be helpful for anybody else but your idea is amazing, I will write this code today, I will share it for free, and will be using it in Asgard.

I might have a few questions :
1) [Ongame Startup state]: is this the state before server save? so why not just make a function onTime(interval) that runs at the same time as server save?
1) after 5 mins of thinking about it: the only way to make this system work for online/offline players is by using database queries, do you think there is a way to substitute queries?

With my limited knowledge, I'm sure there isn't a way for TFS to run functions offline.
 
1) after 5 mins of thinking about it: the only way to make this system work for online/offline players is by using database queries, do you think there is a way to substitute queries?

onStartup is executed when the server is just "started up" 😁 , yeah you just opened it. that is the perfect time to run queries like this because all players will be offline, and we don't have do worry about modifying online players because the idea is to execute the queries just on players that have not logged in for a long time...


example:
  • startup
  • check for how long player has been offline
  • decrease its level/experience/skill_tries/manaspent
  • recalculate player status: mana/max_mana/health/max_health/cap/skill_level/magic_level
 
onStartup is executed when the server is just "started up" 😁 , yeah you just opened it. that is the perfect time to run queries like this because all players will be offline, and we don't have do worry about modifying online players because the idea is to execute the queries just on players that have not logged in for a long time...


example:
  • startup
  • check for how long player has been offline
  • decrease its level/experience/skill_tries/manaspent
  • recalculate player status: mana/max_mana/health/max_health/cap/skill_level/magic_level
Its a safe way but we can't say its the best, somebody like me i do restart my server only on patches/updates which can be every 100-500 hours, not efficient to be every restart should have a specific timeframe [48HRS or smth], because if a player been away for 1 month and the server never restarted to start up and he found through discord we are updating he can just login and logout and that will not reduce his EXP/skills as it should, what i thought of is doing something like this on the same time as server save.

1) Code brings list from DB with players that have last-logout 3-4 days and [not lastLogin > lastLogout] : because lastLogin is always higher till the player logs out.
2) example code for what i might be doing to prevent extra CPU usage by frequently running queries.
this code is written by zibuzu [not sure if i got the name correctly but should be fine]
[this code is not the code we are talking about, we just might use the same techqniue.

Lua:
local function delayedSave(cid)
    local p = Player(cid)
    if p then
        p:save()
    end
end

function onThink(interval)
    local players = Game.getPlayers()
    local delay = 250

    for _, player in ipairs(players) do
        delay = delay + delayBetweenSaves
        addEvent(delayedSave, delay, player:getId())
    end
    return true
end
so if it is like this we can have 4 queries running per second[if delay is 250] which won't do 0.01% CPU usage as i know.

This should prevent :
-Burning your CPU on 100 players online
-unexploitable system that reduces levels/skills by a timeframe as stated in the the if conditions


[I went that far because I imagined the system to do slight reduction for anybody inactive for 2-3 days and it just stacks till he login after a month losing like 50-60 would be better instead suddenly reducing the 50-60 level by doing 1 restart]
let me know what you think
 
Sounds like a good idea, but it would make people mad.
This would be way easier to do in source side, because you can load offline players into Player instance and then save them with no problems, you don't even have to do any sql queries, cause server will do all of it automatically.
Also just do it once per startup and calculate time passed, no point in using onThink or some shit as it doesn't matter, if player logs in it shouldn't take his exp.

tl;dr: save last logout, on startup -> count time, if time is higher than your defined time for being offline then remove exp (you would need some formula to calculate how much to remove using removeExperience, this will also drop the level and automatically recalculate all values, cap, mana etc), this way you dont need a big logic to do that, last logout will automatically take care of the intervals
 
Last edited:
Sounds like a good idea, but it would made people mad.
This would be way easier to do in source side, because you can load offline players into Player instance and then save them with no problems, you don't even have to do any sql queries, cause server will do all of it automatically.
Also just do it once per startup and calculate time passed, no point in using onThink or some shit as it doesn't matter, if player logs in it shouldn't take his exp.
I can imagine how mad they will be, but we can't forget that they will keep their items, in a balanced well made server good equipment should make it easier to level up, and must have welcome back rewards if this system will be implemented in an official server, welcome back rewards can be EXP bonus and some stuff like if I reduced your level from 200 to 100 you have x3 EXP till level 200.

actually from my simple point of view this system will give players a reason to jump in daily / like active lottery system [randomly rewards only one from who uses the lever in X pos] + will make it more fun for who got bored from the server and want to come back.

feels cool just to take a different path than seasonal ots.
 
global onthink sql queries -> deleveling, deskilling
onlogin -> check equipment, deequip to backpack or worst case scenario to depo

i see no problem at all in implementation tbh
 
Why not just calculate this on player login individually, you just check how long they've been offline for and create a formula to adjust everything accordingly. You can then do all the other things such as dequipping items.

I cant think of many negatives of this, perhaps website highscores etc.

EDIT: I didn't read the first few lines properly.

If a server save type event is too heavy(I can't see it being too much of a problem), and someone doesn't want to make a source edit for whatever reason.

Perhaps a PHP cron job, or something similar could be an alternative.
 
I cant think of many negatives of this, perhaps website highscores etc.
exactly, that was the main goal, to get rid off of inactive players from highscores, but now that I said it, maybe we could just achieve it AAC-side instead lol
 
exactly, that was the main goal, to get rid off of inactive players from highscores, but now that I said it, maybe we could just achieve it AAC-side instead lol
can be done in many ways, everyone will just use the way following what they are trying to achieve (accuracy, activity, clean boards) if your target is cleaning highscores just like we hide players with account_id XYZ you can just hide player with lastlogout > timestamp - TIME[MILISECONDS]
 
Hueh you wanna fool players. It can be done by an algorithm on website.

Just player_stats/inactive days = new player_stats

And then we can see an abstraction e.g. in highscores. False informations will be visible only.

A new player with 100lvl is higher in top then a player with 1000 lvl and 10 days inactivity.

The problem will be if the player login to the game (he has 1000lvl but on side 90lvl)
 
somebody like me i do restart my server only on patches/updates which can be every 100-500 hours,
You should restart every night. No reason not too really, and increases playability. Even if the server does fine its good to do. Backups, ect. What happens if you crash at 400 hours? That's a lot of time loss.
 
Back
Top