Grabbing a usermessage from an addon is it possible?

Hello I wanted to use this addon http://www.garrysmod.org/downloads/?a=view&id=70934
in order to show how long a player has been on the server.
and if the player has been on the server for say 4 hours he is allowed to use the SWAT job.
so the question is could I use this addon to get the players time spent to work with the gamemode
or do I have to code it into the gamemode itself.

sending a console command with time spent to the server is a bad idea it would be simple to just time them server side sot hey can’t send info to the server(if they send info to the server its easier to hack)

[lua]
local plytime = CurTime() - ply.Created

if plytime > 14400 then
SwatAllowed = true
else
SwatAllowed = false
end
[/lua]

If plytime is greater than 14400 (4 hours in seconds), then tell us they are allowed to use SWAT.

is plytime automatically saved?
or would i have to do so in a text file?

plytime is only for the current session. If you wanted to know the total time the player has been on, you would save the time to a text file each time they disconnect.

alright hows this look
[lua]local Player = FindMetaTable(“Player”)

function Player:LoadTime()
local FilePath = “syNergYRP”…self:UniqueID()…"/timespent.txt"
if file.Exists(FilePath) then
print(“Players Time has been successfully loaded!”)
local contents = util.KeyValuesToTable(file.Read(FilePath))
self.TimeOnServer = contents
datastream.StreamToClients(self,“timespent”,{time = contents})
else

end

end

function Player:SaveTime()
local FilePath = “syNergYRP”…self:UniqueID()…"/timespent.txt"
if file.Exists(FilePath) then
print(“Players Time has been sucessfully saved!”)

	file.Write(FilePath,util.TableToKeyValues(self.TimeOnServer))
end

end

local function AutoSave( )
local k, v

for k, v in ipairs( player.GetAll( ) ) do
	v:Save( )
end

end

function PlayerTime(ply)
ply:TimeOnServer = CurTime() - pl.Created
end

timer.Create( “SaveTime”, 120, 0, AutoSave )[/lua]

You need to add the current time when you save.

isnt that what self.timeonserver is?
Im not understanding

Can someone explain this to me.
here’s my current code
[lua]local Player = FindMetaTable(“Player”)

function Player:LoadTime()
local FilePath = “syNergYRP”…self:UniqueID()…"/timespent.txt"
if file.Exists(FilePath) then
print(“Players Time has been successfully loaded!”)
local contents = util.KeyValuesToTable(file.Read(FilePath))
self.TimeOnServer = contents
datastream.StreamToClients(self,“timespent”,{time = contents})
else

end

end

function Player:SaveTime()
local FilePath = “syNergYRP”…self:UniqueID()…"/timespent.txt"
if file.Exists(FilePath) then
print(“Players Time has been sucessfully saved!”)

	file.Write(FilePath,util.TableToKeyValues(self.TimeOnServer))
end

end

local function AutoSave( )
local k, v

for k, v in ipairs( player.GetAll( ) ) do
	v:Save( )
end

end

function PlayerTime(ply)
local plytime = CurTime() - ply.Created
if ply:Team() == TEAM_SWAT and plytime > 14400 then
SwatAllowed = true
else
ply:HUD_PRINTTALK(“You have to be on the server for a total of four hours to play a SWAT!”)
SwatAllowed = false
end
end

timer.Create( “SaveTime”, 120, 0, AutoSave )[/lua]

Why not ask me? :smiley:

Yes you can, just depends: when do you want it to check their time to set the rank? I can tell you where you want to do the check and what variables to use.

Here is some code while I’m here:

With that version of BTS you can run this on the server where you want to check if the player can use the job:[lua]
local full, session = BTS.GetTime( ply, true ) // True calculates the times in seconds for you.
if full >= 14400 then
// OH HEY, they can be SWAT
else
// Sorry, you can’t use that job :frowning:
end
[/lua]
That simple :smiley:

so i put that code into dark rp and just put that addon onto the server and done?

Pretty much in a nutshell, addon by default uses steamid and files so it should work out of the box and add that check in the job function, no idea what DarkRP’s code for it looks like but I’m guessing you must know at least enough or more to be able to do it.

[lua]local full, session = BTS.GetTime( ply, true ) // True calculates the times in seconds for you.
if t == TEAM_SWAT and if full >= 14400 then
t = TEAM_SWAT
else
if full < 14400 then
ply:HUD_PRINTTALK(“Sorry you cant be part of the SWAT team.”)
end
end
end
end[/lua]
Would this work?
and yes i know its not indented i just threw this together quick im really tired so yea = D

hmm I put that into a function in player.lua and it broke.
So i tried making it into its own function and.
It broke.
Im unsure what i did wrong.
Any ideas?

Remove the last end.

Okay so i tried adding it to the change job meta table.
That broke something on player initial spawn.
Also I tried making it its own function here is a good chunk of the code some is mine some is dark rp’s
[lua]function meta:DoPropertyTax()
if CfgVars[“propertytax”] == 0 then return end
if self:Team() == TEAM_POLICE or self:Team() == TEAM_MAYOR or self:Team() == TEAM_CHIEF or self:Team() == TEAM_SWAT and CfgVars[“cit_propertytax”] == 1 then return end

local numowned = self:GetTable().OwnedNumz

if numowned &lt;= 0 then return end

local price = 10
local tax = price * numowned + math.random(-5, 5)

if self:CanAfford(tax) then
	if tax == 0 then
		Notify(self, 1, 5, "You have received no property taxes since you don't own a door or a vehicle.")
	else
		self:AddMoney(-tax)
		Notify(self, 1, 5, "Property tax! " .. CUR .. tax)
	end
else
	Notify(self, 1, 8, "You couldn't pay the taxes! Your property has been taken away from you!")
	self:UnownAll()
end

end

function CheckTime()
local full, session = BTS.GetTime( ply, true ) // True calculates the times in seconds for you.
if t == TEAM_SWAT and if full >= 14400 then
t = TEAM_SWAT
else
if full < 14400 then
ply:HUD_PRINTTALK(“Sorry you cant be part of the SWAT team.”)
end
end
end[/lua]
So instead of breaking the whole gamemode this time it just breaks something on PlayerInitialSpawn which really makes no sense at all to me.

bump

bump


(User was banned for this post ("Bump bumpity bump" - mahalis))

Sorry been on vacation with no internet…

What is in the PlayerInitialSpawn function

[lua]function GM:PlayerInitialSpawn(ply)
self.BaseClass:PlayerInitialSpawn(ply)
DB.Log(ply:SteamName()…" ("…ply:SteamID()…") has joined the game")
ply.bannedfrom = {}
ply:NewData()
ply.SID = ply:UserID()
DB.RetrieveSalary(ply)
DB.RetrieveMoney(ply)
timer.Simple(10, ply.CompleteSentence, ply)
end[/lua]