DarkRP Steamid whitlist-addon

So, ive recently attempted to create an addon which is supposed to kick everyone out of a certain job that is not entered in the whitelist.
The thing is, it does not work, and i dont know why. Any help, and maybe even improvement? Im quite new to coding and would love to see how it could be done better.
Ive located it to autorun/client. Heres the piece of code:


Whitelistteam = { 
	"Gangster",
	"TheJob" 
}
whitelistedids = {
	"STEAM_0:1:59826259",
	"STEAM_0:1:59826259",
	"STEAM_0:1:59826259"
}
function GameInitialize()
	timer.Create( "teamcheck", 1, 0, teamcheck )

end
hook.Add( "Initialize", "gameInit", GameInitialize )


function teamcheck(ply)
		if table.HasValue( Whitelistteam, team.GetName(ply:Team()) ) then
			if ply:SteamID() == whitelistedids then
				DarkRP.notify(ply, 3, 5, "(Debug) You have job access.")
			end
			
			else
				DarkRP.notify(ply, 3, 5, "You are not listed on the jobs whitelist!")
				-- Demote command here
			end
		end
end

Thank you very much already!

Why use Initalize hook, and not CanChangeJob hook by DarkRP?
http://wiki.darkrp.com/index.php/Hooks/Server/canChangeJob

How would the code have to look if i would use it?
Ive watched trough the wiki and im not really having a clue how to implent it.

[editline]18th July 2015[/editline]


Whitelistteam = { 
	"Gangster",
	"TheJob" 
}
whitelistedids = {
	"STEAM_0:1:59826259",
	"STEAM_0:1:59826259",
	"STEAM_0:1:59826259"
}

hook.Add("canChangeJob", "whitelistedjobs", function(ply, job)
	if ply:Team() = whitelistteam and 
	if not ply:SteamID() == whitelistedids then
		return false, "You are not listed on the jobs whitelist!" end
	end
end)


Something like this?

  1. You need to loop through the table.
  2. Why use ply:Team(), this is before the job change.
    Your 2nd paramater:
    job (string)
    The job name (what the player entered in the /job command).

table.HasValue is your friend here.

Ive no idea what you mean with that. Sorry.


Whitelistteam = { 
	"Gangster",
	"TheJob" 
}
whitelistedids = {
	"STEAM_0:1:59826259",
	"STEAM_0:1:59826259",
	"STEAM_0:1:59826259"
}

hook.Add("canChangeJob", "whitelistedjobs", function(ply)
while true do
	for k, v in pairs(player.GetAll()) do
		if table.HasValue( whitelistteam, team.GetName(v:Team()) ) and
			if not ply:SteamID() == whitelistedids then
			return false, "You are not listed on the jobs whitelist!" end
		end
	end
end
end)



That better?

The hook canChangeJob refers to /job command, not changing from Citizen to Gangster or whatever, which is playerCanChangeTeam.

Now, I haven’t tested it, but something like this should work.
[lua]Whitelisted_Teams = {
TEAM_GANG,
TEAM_THEJOB,
}

Whitelisted_SteamIDs = {
“STEAM_0:1:59826259”,
“STEAM_0:1:59826259”,
“STEAM_0:1:59826259”,
}

hook.Add(“playerCanChangeTeam”, “DoJobsWhistelist”, function(ply, job, forced)
if not forced then
if table.HasValue(Whitelisted_Teams, job) and not table.HasValue(Whitelisted_SteamIDs, ply:SteamID()) then
DarkRP.notify(ply, 3, 5, “You are not on the jobs whitelist!”)
return false
end
end
end)
[/lua]

It works, thanku!
Now i would want to let a timer run to check if someone sneakly forced himself with admincommands into a job. Ive already created the timer, but i cant find a command that sets the team of someone for example to citizen. Can someone help out?

Yea sure, go on darkrp.com go to functions, and get it…

[editline]19th July 2015[/editline]

Btw by removing if forced, it wont let admins set thier team.

Hm, something is not working there.
The job is not getting checked, in other words, it does not accept the jobs as they are. If i set The tablevalue to “if not” it works, so it has to be this.

Can you have a look at it and tell me where the mistake might be?

[editline]19th July 2015[/editline]

Btw, thanks with that forced. This works out nice and clean.

So it works?

The code itself does.
The only thing that does not seem to work is the Job check (Checking if the jobs whitelisted)

Strange…
Try this code, shouldn’t be different though?
[lua]
Whitelisted_Teams = {
TEAM_GANG,
TEAM_THEJOB,
}

Whitelisted_SteamIDs = {
“STEAM_0:1:59826259”,
“STEAM_0:1:59826259”,
“STEAM_0:1:59826259”,
}

hook.Add(“playerCanChangeTeam”, “DoJobsWhistelist”, function(ply, job, forced)
if not forced then – If we’re not forcing the change
if table.HasValue(Whitelisted_Teams, job) then – If the job should be whitelisted.
if not table.HasValue(Whitelisted_SteamIDs, ply:SteamID()) then – If the player is not whitelisted.
DarkRP.notify(ply, 3, 5, “You are not on the jobs whitelist!”) – Tell them.
return false – Block the change.
end
end
end
end)
[/lua]
I mean, I’m confused.

whats the problem with that code?

There isn’t anything wrong with it, he’s suggesting for him to use it

Ive worked with other Developers of our Community, we changed the code, and it works now. Thanks everyone for helping!

If you don’t mind, what was the fix?