Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
Set the limit of players to save data to 5
Browse files Browse the repository at this point in the history
Set the limit of players to save data to 5 to prevent farming/spamming.

Also added a function to save player data when players left (only if
there are more than 4 players in the room)
  • Loading branch information
Seniru committed Jan 11, 2020
1 parent b21eac8 commit cb5d5d5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ local timer = Timer("time-sys", function()
end, 1000, true)

local saveDataTimer = Timer("dataTimer", function()
for name, _ in next, tfm.get.room.playerList do
system.savePlayerData(name, dHandler:dumpPlayer(name))
if #tfm.get.room.playerList >= 5 then
for name, _ in next, tfm.get.room.playerList do
system.savePlayerData(name, dHandler:dumpPlayer(name))
end
print('Player Data Saved!')
end
print('Player Data Saved!')
end, 1000 * 60 * 2, true)

--creating the class Player
Expand Down Expand Up @@ -1054,6 +1056,14 @@ function eventNewPlayer(name)
system.bindKeyboard(name, 72, true, true)
end

function eventPlayerLeft(name)
if #tfm.get.room.playerList < 5 then
tfm.exec.chatMessage("You need atleast 5 players to save stats")
else
system.savePlayerData(name, dHandler:dumpPlayer(name))
end
end

function eventPlayerDataLoaded(name, data)
print("Loaded player data (" .. name .. ")") --.. data)
dHandler:newPlayer(name, data)
Expand Down

0 comments on commit cb5d5d5

Please sign in to comment.