How do I disable the spawnmenu but keep it enabled for certain DarkRP jobs.
You can use hook.Add with GM:OnSpawnMenuOpen and check if they are the correct Team or not. This doesn't stop them from spawning items through console though.
Are you able to type the code I'm not very good at coding.
local ply = LocalPlayer()
hook.Add("OnSpawnMenuOpen", function()
if ply:getJobTable() == "TEAM_SOMETHING" then // type here the job
return true
end
elseif ply:getJobTable() == "TEAM_SOMETHING" then // type here the job
return false
end
end)
Thanks I'll test
GM:OnSpawnMenuOpen is a clientside hook.
That code won't work (job ID's are variables, not strings). Use this:
local ply = LocalPlayer()
hook.Add("OnSpawnMenuOpen", function()
return ply:Team() == TEAM_COP --change TEAM_COP to your team's ID.
end)
Put that code in lua/autorun/client and then put THIS code in lua/autorun/server to prevent people from spawning things with console commands:
hook.Add("PlayerSpawnObject","darkrp_limiter",function(ply)
return ply:Team() == TEAM_COP
end)
Cheers.
LocalPlayer() returns NULL if it's called before GM:InitPostEntity.
What do you mean, sorry for the hassle.
Instead of doing
local ply = LocalPlayer()
hook.Add("SpawnMenuOpen","darkrp_limiter", function()
return ply:Team() == TEAM_COP --change TEAM_COP to your team's ID.
end)
do this
hook.Add("SpawnMenuOpen", "darkrp_limiter", function()
return LocalPlayer():Team() == TEAM_COP
end)
I need to do multiple jobs I tried this but it does not work, any ideas ?
You can't do an if statement like that. You can do this however:
hook.Add("SpawnMenuOpen", "darkrp_limiter", function()
local allowedJobs = {TEAM_TIMELORDS, TEAM_10THDOCTOR, TEAM_11THDOCTOR, TEAM_12THDOCTOR, TEAM_THEMASTER}
return table.HasValue(allowedJobs, LocalPlayer():Team())
end)
It worked cheers mate!
C'mon man did you see the post?
Yeah, I know that's a thing, just for simplicity's sake I did that.
You don't even need to check if its nil, just simply do return allowedJobs[LocalPlayer():Team()]
You can do even better by storing the table outside of the function.
No because it's a hook we want to return a hard false instead of nil to end the propagation.
Sorry, you need to Log In to post a reply to this thread.