I'm probably just not looking in the right places, but I can't seem to find a function that will return what job a player like TEAM_GUN. Does anyone know what function I should use for this?
You would want to use Team()
Here is an example:
[CODE]
if ply:Team() == TEAM_GUN then
// Run Code here
end
[/CODE]
Thanks man. I'll try it.
[editline]28th May 2016[/editline]
Another question. How would you deny someone access of a job if a variable is false?
[url]http://wiki.darkrp.com/index.php/DarkRP:CustomJobFields[/url]
You would use customCheck and CustomeCheckFailMsg and just add them above sortOrder.
Here is an example of what I use to restrict a user from a job
[CODE]
customCheck = function(ply) return CLIENT or ply:GetUTimeTotalTime() >= 1800 end,
CustomCheckFailMsg = "You need 30 minutes playtime to become this class!",
sortOrder = 19,
[/CODE]
But is there a way to do this without going into the jobs.lua and doing what i said above in a separate file in a totally different addon?
[QUOTE=MelonShooter;50412558]But is there a way to do this without going into the jobs.lua and doing what i said above in a separate file in a totally different addon?[/QUOTE]
Explain more thoroughly what you want to do. Do you want a seperate script to deny a job? Do you want an addon you are currently using to deny a job?
It would be easier to help you if you gave more info on what you are trying to do.
[QUOTE=boxvader;50412747]Explain more thoroughly what you want to do. Do you want a seperate script to deny a job? Do you want an addon you are currently using to deny a job?
It would be easier to help you if you gave more info on what you are trying to do.[/QUOTE]
I'm sorry if I am not being very detailed. So I am making an addon that denies access to jobs before certain time limits using UTime. If you want more detail, tell me.
[QUOTE=MelonShooter;50412918]I'm sorry if I am not being very detailed. So I am making an addon that denies access to jobs before certain time limits using UTime. If you want more detail, tell me.[/QUOTE]
You should really use Cheese_3's example. Otherwise it would be a mess.
This post probably belongs on the DarkRP forum too.
[QUOTE=Bubbie;50412952]You should really use Cheese_3's example. Otherwise it would be a mess.
This post probably belongs on the DarkRP forum too.[/QUOTE]
But I want to make it in a separate addon. And it probably will be a mess :P
[QUOTE=MelonShooter;50412957]But I want to make it in a separate addon. And it probably will be a mess :P[/QUOTE]
Alright, here's an untested version then:
[QUOTE]hook.Add( "OnPlayerChangedTeam", "CanPlayerPlayTeam", function( ply, before, after )
if ( after == TEAM_WHATEVER ) and ( ply:GetUTimeTotalTime() < TIME ) then
ply:changeTeam( before, true, true)
ply:ChatPrint( "Sorry! You haven't played long enough to become that job!" )
end
end )[/QUOTE]
[QUOTE=Bubbie;50412980]Alright, here's an untested version then:[/QUOTE]
I'll try this and get back to you if it works. Thanks for your help. :)
[QUOTE=MelonShooter;50413024]I'll try this and get back to you if it works. Thanks for your help. :)[/QUOTE]
Alright, no problem. :smile:
[QUOTE=Bubbie;50412980]Alright, here's an untested version then:[/QUOTE]
1. Use code tags not quotes.
2. Better to use the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerCanJoinTeam]GM:PlayerCanJoinTeam[/url] hook and just return false.
[QUOTE=boxvader;50413674]1. Use code tags not quotes.[/QUOTE]
Alright, sorry. Kind of new to posting here.
[QUOTE]2. You can just return false, no need to force them to a team.[/QUOTE]
Again, my mistake, I haven't done much coding with DarkRP. :v:
[QUOTE=Bubbie;50413686]Alright, sorry. Kind of new to posting here.
Again, my mistake, I haven't done much coding with DarkRP. :v:[/QUOTE]
No worries man, everyone has to learn at some point I was just letting you know.
For the second one I actually edited it to the hook that you should use instead of OnPlayerChangedTeam. You were probably thinking OnPlayerChangedTeam because that is what you would use if you were setting up a custom check.
[QUOTE=boxvader;50413693]No worries man, everyone has to learn at some point I was just letting you know.
For the second one I actually edited it to the hook that you should use instead of OnPlayerChangedTeam. You were probably thinking OnPlayerChangedTeam because that is what you would use if you were setting up a custom check.[/QUOTE]
Yeah, haha, thanks a lot! :happy:
This is my code, but It's not putting in chat anything and it's not restricting job access.
[CODE]if not SERVER then return end
jobtime = {
{ hours = 5, job = "TEAM_POLICE", name = "Police Officer" }
}
settings = {
{ msgOn = true, msgcolor = Color(0,0,0)}
}
local jobID = 1
function jobSet( ply )
local hours = math.floor((ply:GetUTime() + CurTime() - ply:GetUTimeStart())/60/60)
while hours >= jobtime[jobID].hours and jobID < table.Count(jobtime) do
jobID = jobID + 1
jobTS = jobtime[jobID-1].job
end
if jobID == table.Count(jobtime) then
jobTS = jobtime[table.Count(jobtime)].job
return true
else
if jobID <= 2 then
if hours >= jobtime[1].hours then
return true
end
else
if hours >= jobtime[jobID-1].hours then
return true
end
end
end
return false
end
function allowjobPlayer( ply )
jobID = 1
if jobSet( ply ) and ply:Team() != jobTS then
if settings[1].msgOn then
if jobID == table.Count(jobtime) then
jobID = table.Count(jobtime) + 1
return true
else
ULib.tsayColor(ply,false,settings[1].msgcolor,"You are now allowed to turn into a '"..jobtime[jobID-1].name.."'.")
end
end
jobID = 1
end
end
hook.Add( "GM:PlayerCanJoinTeam", "IfPlayerCanChangeTeam", function( ply, before, after )
if ( after == jobTS ) and !jobSet(ply) then
ply:ChatPrint( "Sorry! You haven't played long enough to become that job!" )
return false
end
end )
function timerJobStart( ply )
timer.Create("JobTime-" ..tostring(ply:SteamID()), 10, -1, allowjobPlayer, ply)
end
hook.Add( "PlayerInitialSpawn", "timerstarting", timerJobStart)[/CODE]
[QUOTE]hook.Add( "GM:PlayerCanJoinTeam", "IfPlayerCanChangeTeam", function( ply, before, after )[/QUOTE]
Try using "PlayerCanJoinTeam" instead of "GM:PlayerCanJoinTeam" ?
Ok I did that and here's my code and I just tested that the message in the jobSet function doesn't work either.
[CODE]if not SERVER then return end
jobtime = {
{ hours = 5, job = "TEAM_POLICE", name = "Police Officer" }
}
settings = {
{ msgOn = true, msgcolor = Color(0,0,0)}
}
local jobID = 1
function jobSet( ply )
local hours = math.floor((ply:GetUTime() + CurTime() - ply:GetUTimeStart())/60/60)
while hours >= jobtime[jobID].hours and jobID < table.Count(jobtime) do
jobID = jobID + 1
jobTS = jobtime[jobID-1].job
end
if jobID == table.Count(jobtime) then
jobTS = jobtime[table.Count(jobtime)].job
return true
else
if jobID <= 2 then
if hours >= jobtime[1].hours then
return true
end
else
if hours >= jobtime[jobID-1].hours then
return true
end
end
end
return false
end
function allowjobPlayer( ply )
jobID = 1
if jobSet( ply ) and ply:Team() != jobTS then
if settings[1].msgOn then
if jobID == table.Count(jobtime) then
jobID = table.Count(jobtime) + 1
return true
else
ULib.tsayColor(ply,false,settings[1].msgcolor,"You are now allowed to turn into a '"..jobtime[jobID-1].name.."'.")
end
end
jobID = 1
end
end
hook.Add( "PlayerCanJoinTeam", "IfPlayerCanChangeTeam", function( ply, before, after )
if ( after == jobTS ) and !jobSet(ply) then
ply:ChatPrint( "Sorry! You haven't played long enough to become that job!" )
return false
end
end )
function timerJobStart( ply )
timer.Create("JobTime-" ..tostring(ply:SteamID()), 10, -1, allowjobPlayer, ply)
end
hook.Add( "PlayerInitialSpawn", "timerstarting", timerJobStart)[/CODE]
Sorry, you need to Log In to post a reply to this thread.