Forum Multiplayer Timer

Discussion and help relating to the PlayerIO Multiplayer API.

Timer

Postby 12345hassan » March 31st, 2018, 3:31 pm

Can someone help me to code a timer of ban?
Like when i ban a player using a command and the time i enter the countdown will start and after the time ends he will be unbanned
like
/b;Hassan;23:4:60
and it sets the timer on the players database
InfoPPL.Set("bantime", 23:4:60)
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: Timer

Postby Emalton » April 10th, 2018, 11:45 pm

Maybe when you ban someone for example a day, store the current DateTime in their PlayerObject with an additional day, and check to see if that time has passed when they join a room.
Emalton
 
Posts: 86
Joined: June 28th, 2013, 3:49 am

Re: Timer

Postby robscherer123 » April 11th, 2018, 1:45 pm

Yes, I do this for banning my players. Just check ban them and set the ban property to UTC + when they are to be unbanned. And when they try to log in, you can count the number of days it has been by subtracting the current UTC time by their ban date time. There is a TimeSpan class which can be used to count the elapsed amount of time between the two.
robscherer123
Paid Member
 
Posts: 313
Joined: December 12th, 2012, 8:46 pm

Re: Timer

Postby 12345hassan » April 11th, 2018, 4:18 pm

Can u gimme code?
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: Timer

Postby robscherer123 » April 11th, 2018, 4:52 pm

Something along the lines of this:

Code: Select all
//Below will ban the player for 3 days.
dbObject.set("banEnd", DateTime.UtcNow.AddDays(3));

//Below will check the players ban time that has passed once their data has been loaded.
TimeSpan banTimeRemaining = dbObject.GetDateTime("banEnd") - DateTime.Now;
if(banTimeRemaining.totalDays <= 0){
     //The player has be unbanned here.
} else {
    //The player can not be unbanned.  banTimeRemaining.totalDays will show the amount of days remaining.
}

That's a simplified version off the top of my head, but I believe something like that should work.
robscherer123
Paid Member
 
Posts: 313
Joined: December 12th, 2012, 8:46 pm

Re: Timer

Postby 12345hassan » April 14th, 2018, 7:26 am

I tried the code the ban works the time finishes and player doesnt get unban
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: Timer

Postby Emalton » April 18th, 2018, 5:07 pm

What I do is similar:

Code: Select all
public override void GameStarted()
{
    PreloadPlayerObjects = true;
}


Code: Select all
public override bool AllowUserJoin(Player player)
{
    if (player.PlayerObject.GetDateTime("BannedEnd", DateTime.MinValue) > DateTime.UtcNow)
    {
        // They are banned.
        return false;
    }
    else
    {
        // They are not banned, let them through.
        return true;
    }
}
Emalton
 
Posts: 86
Joined: June 28th, 2013, 3:49 am

Re: Timer

Postby 12345hassan » April 21st, 2018, 12:37 pm

My problem is that the time finishes and the player isnt unbanned
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: Timer

Postby Emalton » April 21st, 2018, 9:15 pm

12345hassan wrote:My problem is that the time finishes and the player isnt unbanned

Both snippets of code above work fine for me, are you talking about removing the property based off the time? There isn't a really good way to do this, just check to see if the banishment end date was in the past when they join and if so remove it and let them through. You don't need a timer for this.
Emalton
 
Posts: 86
Joined: June 28th, 2013, 3:49 am


Return to Multiplayer



cron