• Get players current job
    7 replies, posted
I'm custom coding a menu that allows the player to change jobs, and have run into a snag. I need to be able to find out what the player's current job is, so that I don't populate that button in the menu, but I don't know where to get that info. Have searched docs, gmod wiki, etc. This is what I have so far. I'm a citizen currently, and as you can see, the citizen button is still there. I can hide it if I can find out that I'm a citizen already... [QUOTE][IMG]http://i.gyazo.com/ad73829e51ee9acda1b5bf13baa7356e.png[/IMG][/QUOTE] ([url]http://i.gyazo.com/ad73829e51ee9acda1b5bf13baa7356e.png[/url])
-snip- Read below
[QUOTE=The Beta;44239709][LUA]v = LocalPlayer() Job = DarkRP.getPhrase("job", v:getDarkRPVar("job") or "")[/LUA][/QUOTE] That's not going to work if they change the title of their job. [url]http://wiki.garrysmod.com/page/team/GetName[/url] Although for this you may just want to get the player's team rather than the name.. [lua] if ( ply:Team( ) == TEAM_CITIZEN ) then [/lua]
Okay, thanks. I'll test it out. Edit: if I do the ply:Team to see if they're a citizen though wont I have to do that check for each job? Is there an easier way?
How do you create the buttons? Are you looping through the teams and creating a button for each one inside the loop, or are you manually creating the buttons for every team? I only ask because it seems you've completely overridden the DarkRP jobs tab, so there's a possibility your method of adding the buttons may be different than the original for DarkRP.
Yes, I'm creating a loop. I could post my code if you'd like.
That would help, but it should be as simple as just comparing the team the button is for to the player's team, and if they're the same don't create the button.
I know the code looks a little messy, and I'm sorry if its not easily understood. But here it is: [CODE] //Jobs Table(this is an example of how my table is laid out.) local gvtJobsTable = { {"Civil Protection", "models/player/Police.mdl", "/cp", "Example Discription Here", "Example Weapons Here"}, {"SWAT", "models/player/riot.mdl", "/swat", "", "" }, {"Mayor", "models/player/breen.mdl", "/mayor", "", "" }, {"Secret Service", "models/player/Group02/male_06.mdl", "/ss", "", "" } } //Button Layout function addButtonToCategory(category, position, job, mod, cmd, dsc, wep) btnNum = btnNum + 1; local i=btnNum; buttons[i] = vgui.Create( "DButton", category ) buttons[i]:SetText( "" ) buttons[i]:SetPos( 0, 20 + 55 * (position-1) ) buttons[i]:SetSize( 447, 50 ) buttons[i].Paint = function() draw.RoundedBox( 4, 0, 0, buttons[i]:GetWide(), buttons[i]:GetTall(), Color( 50, 140, 220, 130 ) ) draw.SimpleText(job, "labellarge", 5, 10, Color(255,255,255,255)) end buttons[i].OnCursorEntered = function() jobmodel:SetModel(mod) buttons[i].Paint = function() draw.RoundedBox( 4, 0, 0, buttons[i]:GetWide(), buttons[i]:GetTall(), Color( 90, 90, 90, 170 ) ) draw.SimpleText(job, "labellarge", 5, 10, Color(255,255,255,255)) end jobDescription:SetText(dsc) jobDescription:SetVisible(true) end buttons[i].OnCursorExited = function() jobmodel:SetModel( LocalPlayer():GetModel() ) function jobmodel.Entity:GetPlayerColor() return Vector ( 1, 0, 0 ) end buttons[i].Paint = function() draw.RoundedBox( 4, 0, 0, buttons[i]:GetWide(), buttons[i]:GetTall(), Color( 50, 140, 220, 130 ) ) draw.SimpleText(job, "labellarge", 5, 10, Color(255,255,255,255)) end jobDescription:SetVisible(false); end buttons[i].DoClick = function () RunConsoleCommand( "say", cmd ) -- What happens when you press the button end end //Tab Tables (example of a tabs table) local i; for i=1, #gvtJobsTable do local job=gvtJobsTable[i][1] local mod=gvtJobsTable[i][2] local cmd=gvtJobsTable[i][3] local dsc=gvtJobsTable[i][4] local wep=gvtJobsTable[i][5] addButtonToCategory(governmenttab, i, job, mod, cmd, dsc, wep) end // Handle custom jobs local access; local ply = LocalPlayer(); local numButtons = 0; for j=1, #cstmJobsTable do access = false; local accessTable = customJobsAccess[j] if (ply:IsAdmin()) then access = true else local id=ply:SteamID(); local i; for i=1, #accessTable do if(accessTable[i] == id) then access = true; break; end end end if access==true then numButtons = numButtons + 1; local job=cstmJobsTable[j][1] local mod=cstmJobsTable[j][2] local cmd=cstmJobsTable[j][3] local dsc=cstmJobsTable[j][4] local wep=cstmJobsTable[j][5] addButtonToCategory(customtab, numButtons, job, mod, cmd, dsc, wep) end end [/CODE]
Sorry, you need to Log In to post a reply to this thread.