Auto Reset level to 1

Started by Cool, Sep 24, 2016, 09:33 AM

Previous topic - Next topic

Cool

how to make a system which check if user has a level and he does not visit from 3 days so reset his level to 1 if user spend 30 minutes so count his visit other wise not count his visit

KAKAN

check his lastjoined time in each join, and then, with some algorithm, you can get the days :)
Hint: time() uses seconds.
oh no

Anik

When player parts the server check if he has spent 30 minutes or more. if he did then count it. Again when player joins do as KAKAN said and get the days. If days are higher or equal to 3 and if he doesn't have 3 counts then set his level to 1.

Saiyan Attack

#3
Here Is The Codes :
// onScriptload
JoinMyTime <- array(100,0);
CheckJoin <- array(100,false);
LDB <- ConnectSQL("Datas.sqlite");
QuerySQL(LDB,"CREATE TABLE IF NOT EXISTS LevelLimits(Username TEXT, LastJoin TIMESTAMP)" );

// onPlayerJoin
JoinMyTime[player.ID]=0;
JoinMyTime[player.ID]=time();
CheckJoin[player.ID]=false;

if(GetSQLColumnData(QuerySQL(LDB,"SELECT Username FROM LevelLimits WHERE Username='"+escapeSQLString(player.Name.tolower())+"'"),0)) {
local TDTime = time()-GetSQLColumnData(QuerySQL(LDB,"SELECT LastJoin FROM LevelLimits WHERE Username='"+escapeSQLString(player.Name.tolower())+"'"),0).tointeger();
if (TDTime >= 259200/*This Will Count 3 Days You Can Also Modify Them By Adding More Days*/) {
// Add Your Level Here ...
}
}

// onPlayerPart
if (CheckJoin[player.ID]==true) {
if(GetSQLColumnData(QuerySQL(LDB,"SELECT Username FROM LevelLimits WHERE Username='"+escapeSQLString(player.Name.tolower())+"'"),0)) {
QuerySQL(LDB,"UPDATE LevelLimits SET LastJoin='0' WHERE Username='"+escapeSQLString(player.Name.tolower())+"'");
QuerySQL(LDB,"UPDATE LevelLimits SET LastJoin='"+time()+"' WHERE Username='"+escapeSQLString(player.Name.tolower())+"'");
}
}

function CountMyJoin(player)
{
if (CheckJoin[player.ID] == false) {
local LoadTime = (JoinMyTime[player.ID]-(time()-1800));
if (LoadTime<1) {
JoinMyTime[player.ID]=0;
CheckJoin[player.ID]=true;
}
}
}

// Add This Line In Your register Command If You Have ? If Not Then Make A Command For It ....
QuerySQL(LDB,"INSERT INTO LevelLimits(Username, LastJoin) VALUES ( '"+player.Name.tolower()+"', '0')" );
Tested !!

Code #2
// onScriptload
JoinMyTime <- array(100,0);
CheckJoin <- array(100,false);
LDB <- ConnectSQL("Datas.sqlite");
QuerySQL(LDB,"CREATE TABLE IF NOT EXISTS LevelLimits(Username TEXT, Join TIMESTAMP, LastJoin TIMESTAMP)" );

// onPlayerJoin
JoinMyTime[player.ID]=0;
JoinMyTime[player.ID]=time();
CheckJoin[player.ID]=false;

// onPlayerPart
if (CheckJoin[player.ID]==true) {
if(GetSQLColumnData(QuerySQL(LDB,"SELECT Username FROM LevelLimits WHERE Username='"+escapeSQLString(player.Name.tolower())+"'"),0)) {
QuerySQL(LDB,"UPDATE LevelLimits SET Join='0', LastJoin='0' WHERE Username='"+escapeSQLString(player.Name.tolower())+"'");
QuerySQL(LDB,"UPDATE LevelLimits SET Join='"+time()+"', LastJoin='259200' WHERE Username='"+escapeSQLString(player.Name.tolower())+"'");
// If You Want To Add More Days Then Update LastJoin ...
}
}

// This Count System You Can Add onPlayerSpawn Or onPlayerRequestSpawn ...
function CountMyJoin(player)
{
if (CheckJoin[player.ID] == false) {
local LoadTime = (JoinMyTime[player.ID]-(time()-1800));
if (LoadTime<1) {
if(GetSQLColumnData(QuerySQL(LDB,"SELECT Username FROM LevelLimits WHERE Username='"+escapeSQLString(player.Name.tolower())+"'"),0)) {
local q = GetSQLColumnData(QuerySQL(LDB,"SELECT Join, LastJoin FROM LevelLimits WHERE Username='"+escapeSQLString(player.Name.tolower())+"'"),0),
if ((time()-GetSQLColumnData(q,0).tointeger())>=GetSQLColumnData(q,1).tointeger()) {
// Add Your Level Here ...
JoinMyTime[player.ID]=0;
CheckJoin[player.ID]=true;
}
else {
JoinMyTime[player.ID]=0;
CheckJoin[player.ID]=true;
}
}
}
}
}

// Add This Line In Your register Command If You Have ? If Not Then Make A Command For It ....
QuerySQL(LDB,"INSERT INTO LevelLimits(Username, Join, LastJoin) VALUES ( '"+player.Name.tolower()+"', '0', '0')" );
Not-Tested !!

Saiyan Attack

First code what exactly do is that ... When a person join the server and server will detect that a person join after 3 days or not if yes that a person join after 3days then server will reset his level and after 30 minutes it will count his day ...

Second Code Will Do this Reaction After 30 minutes ...

Ankris

QuerySQL(LDB, "UPDATE Accounts SET Level=1 WHERE (SELECT TimeSinceLastJoin FROM Accounts WHERE Username='"+player.Name+"') > 259199");

This should work for the level reset. Add it in your onPlayerJoin event.

And for the rest, make an array saving the Ticks (miliseconds) or time() (seconds) and update it when he joins or logins with:

QuerySQL(LDB, "UPDATE Accounts SET TimeSinceLastJoin="+time()+" WHERE Name='"+player.Name+"'");

And you're done.


Hope this is not a bump (2 days ago since the @OP made the topic).