Sorry about spamming this forum with my questions, I've been having a hard time with this is all haha. Anyways I have one last question:
local adminGroups = {
["superadmin"] = true,
["senioradmin"] = true,
["admin"] = true,
["moderator"] = true
-- more..
}
lastjob = {}
lastpos = {}
hook.Add("OnPlayerChangedTeam", "oldteam", staffoldteam)
function staffoldteam (ply, oldTeam, newTeam)
teambefore = oldTeam
lastjob[ply:SteamID()] = teambefore
end
isOnDuty = false
hook.Add("canChangeJob", "StaffChangeFix", staffchangefixfunction)
function staffchangefixfunction(ply)
if isOnDuty == true then ply:ChatPrint("something") return false end
end
hook.Add( "PlayerSay", "StaffArea", function( ply, text, public )
if ( string.lower( text ) == "!staffonduty" ) and adminGroups[ply:GetUserGroup()] then
if isOnDuty == true then
ply:ChatPrint("You're already on duty!")
else
userlastpos = ply:GetPos()
lastpos[ply:SteamID()] = userlastpos
ply:changeTeam(44, true, true)
isOnDuty = true
return ""
end
end
end )
hook.Add( "PlayerSay", "StaffArea2", function( ply, text, public )
if ( string.lower( text ) == "!staffoffduty" ) and adminGroups[ply:GetUserGroup()] then
if isOnDuty == false then
ply:ChatPrint("You're already off duty!")
else
ply:changeTeam( lastjob[ply:SteamID()] or 2 )
ply:SetPos(Vector(lastpos[ply:SteamID()] or 11575.844727, -1995.730591, 146.373474))
isOnDuty = false
return ""
end
end
end )
at the hook.Add("canChangeJob", "StaffChangeFix", staffchangefixfunction) I have a function right under it. The hook is working properly, players can't switch jobs, but it's not printing the ChatPrint... Any idea why? https://wiki.darkrp.com/index.php/Hooks/Server/canChangeJob no errors or anything p.s I realize there is three returns, but when I do return false, "Something" that doesn't work either.
Where are you running all of this? Clientside or serverside?
Serverside
I think, I've already told you that you MUST DEFINE FUNCTION FIRST and then use it as hook callback. hook.Add just updates the hook table with new key and value pair. When you call hook.Add your value is not defined (so it's nil). It equals to Table["OnPlayerChangedTeam"] = nil.
how do you expect isOnDuty to work for all players? Might not relate to the issue, but still a very important detail to address.
btw the second return option for canchangejob is a message that you send to the player in case you decide he can't change, so do this instead of chatprint
return false, "message"
I don't understand...
Not tested this, but this should work
And just so you know, you're hooking to a function before the function even exists, and ply:GetPos() returns a vector, so you only need ply:SetPos(lastpos[ply:SteamID()])
On Duty || Off Duty ( Pastebin Link )
local adminGroups = {
["superadmin"] = true,
["senioradmin"] = true,
["admin"] = true,
["moderator"] = true
}
local commands = {
["!onduty"] = true,
["!offduty"] = true,
["!staffonduty"] = true,
["!staffoffduty"] = true
}
local function SetBool(ply)
ply:SetNW2Bool("Admin_OnDuty", false)
end
hook.Add("PlayerInitialSpawn", "Set_Bools", SetBool)
local function OnDuty(ply, text)
if commands[text] then
if not adminGroups[ply:GetUserGroup()] then return end
local onDuty = ply:GetNW2Bool("Admin_OnDuty")
if not onDuty then
ply._LastPos = ply:GetPos()
ply._OldTeam = ply:Team()
ply:changeTeam(44, true, false)
ply:SetNW2Bool("Admin_OnDuty", true)
DarkRP.notify(ply, 4, 4, "You are now on duty")
else
ply:SetPos(ply._LastPos)
ply:changeTeam(ply._OldTeam, true, false)
ply:SetNW2Bool("Admin_OnDuty", false)
DarkRP.notify(ply, 4, 4, "You are now off duty")
end
end
end
hook.Add("PlayerSay", "OnDutyOffDuty", OnDuty)
Thank you! Would you happen to know how to make it so players can't change jobs while on duty and it notifys then why they cant? I got the can't change jobs part, but I can't seem to give them a message aswell.
This should work; https://wiki.darkrp.com/index.php/Hooks/Server/playerCanChangeTeam
local function denyJobChange(ply)
if ply:GetNW2Bool("Admin_OnDuty") then
DarkRP.notify(ply, 4, 4, "You can't change jobs while on duty!")
return false
end
end
hook.Add("playerCanChangeTeam", "DisallowAdminJob", denyJobChange)
Thank you again for all your help It worked! One thing I don't understand though, this was my current code before I switched to yours hastebin. It's pretty much the same thing, why does yours work?
Sorry, you need to Log In to post a reply to this thread.