|
| 17 Aug 2016 03:14 AM |
I didn't test it though, it's for my game. I have it stored in ServerScriptService btw so if i use proper validation it wont get exploited anyways. Is this correct?
local bans = game:GetService('DataStoreService'):GetDataStore('Bans');
game.Players.PlayerAdded:connect(function(player) local bannedStatus = bans:GetAsync(player.UserId); if bannedStatus then local banReason = bannedStatus.reason; local banTime = bannedStatus.time; if (banTime == 'infinite') then player:Kick('You are banned for: '..banReason..", your ban will never expire."); elseif (banTime >= os.time()) then player:Kick('You are banned for: '..banReason..", your ban expires in "..(banTime / 60).." minutes."); end; end; end);
return { setBanStatus = function(player, reason, time) bans:SetAsync(player.userId, {reason = reason, time = time}); end; removeBanStatus = function(player) bans:SetAsync(player.userId, nil); end; };
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:17 AM |
How would it get "exploited" in the first place, it's a server script and one that the client should never have any power to do anything with.
Anyways it looks fine enough, but it'd be way more useful if you had a ban function that takes how many seconds/whatever they'll be banned for, not just the end time |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:20 AM |
@Flux
I'm saying it wont get exploited, I just put that there so people would know that it wont be (so I don't get hate). I'm trying to make quality code & improve my knowledge. I forgot to do that btw, I should have added os.time() to the 'time' variable.
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:22 AM |
Here's the fixed version guys, I also converted the ban time to days.
local bans = game:GetService('DataStoreService'):GetDataStore('Bans');
game.Players.PlayerAdded:connect(function(player) local bannedStatus = bans:GetAsync(player.UserId); if bannedStatus then local banReason = bannedStatus.reason; local banTime = bannedStatus.time; if (banTime == 'infinite') then player:Kick('You are banned for: '..banReason..", your ban will never expire."); elseif (banTime >= os.time()) then player:Kick('You are banned for: '..banReason..", your ban expires in "..(banTime/60/60).." days."); end; end; end);
return { setBanStatus = function(player, reason, time) bans:SetAsync(player.userId, {reason = reason, time = (os.time() + time)}); end; removeBanStatus = function(player) bans:SetAsync(player.userId, nil); end; };
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:24 AM |
I don't know why you don't use the time along with the amount of days.
"You've been banned for 12 days, 4 hours, 3 minutes, and 2 seconds" |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:28 AM |
@Flux
Don't know how :(
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:30 AM |
It's just division and modulus...
local days = math.floor(secsBanned / (60*60*24)) local hours = math.floor(secsBanned / (60*60)) % 24 local minutes = math.floor(secsBanned / 60) % 60 local seconds = secsBanned % 60 |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:31 AM |
What does modulus do?
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:33 AM |
| Gets the remainder from division. |
|
|
| Report Abuse |
|
|
MiniNob
|
  |
| Joined: 14 May 2013 |
| Total Posts: 822 |
|
|
| 17 Aug 2016 03:33 AM |
| It gets the remainder of the division of two numbers |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 03:40 AM |
@flux Okay does this look good?
local bans=game:GetService('DataStoreService'):GetDataStore('Bans'); local ceil = math.ceil;
game.Players.PlayerAdded:connect(function(player) local bannedStatus=bans:GetAsync(player.UserId); if bannedStatus then local banReason=bannedStatus.reason; local banTime=bannedStatus.time; if banTime=='infinite' then player:Kick('You are banned for: '..banReason..', your ban will never expire.'); elseif banTime+bannedStatus.osTime>=os.time() then player:Kick('You are banned for: '..banReason..'. Your ban expires in '..ceil(banTime/(60*60*24))..' days, '..(ceil(banTime/(60*60))%24)..' hours, '..(ceil(banTime/60)%60)..' minutes, and '..banTime..' seconds.'); end; end; end);
return{ setBanStatus=function(player,reason,time) bans:SetAsync(player.userId, { reason=reason; time=time; osTime=os.time(); } ); end; removeBanStatus=function(player) bans:SetAsync(player.userId,nil); end; };
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Aug 2016 04:10 AM |
@Flux
I know but it's better to round up isn't it, so they wont get disappointed if its off?
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 04:13 AM |
| no, because it won't be off. Rounding up is the dumbest idea because if they have 1 second left on their ban it will say "1 days 1 hour 1 minute 1 second" and not "0 days 0 hours 0 minutes 1 second"... |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 06:16 AM |
why not just round it accurately with
math.ceil(num-.5)
??? |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 06:54 AM |
I save my bans in a table in one key
63,237 |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 06:56 AM |
@Happy That's an incredibly bad idea, IMO.
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 07:44 AM |
'why not just round it accurately with math.ceil(num-.5)' Because one does not simply round 13 hours to a day. The flooring is to chop off the extra seconds from the whole |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 08:48 AM |
it's not a bad idea lol
tell me why
what if you want a banlist?
How do other games do that?
they store it in a table
63,218 |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 05:16 PM |
@Happy I thought you meant like 1 giant value, such as a string or something. My bad, I was tired.
-R.B. Box (Regalius Boxikins Box) |
|
|
| Report Abuse |
|
|
| |
|