I currently run a TTT server, and I was wondering if there was any way to make a chat command that when a player types '!traitors' in the chat, it will run the console command 'ttt_print_traitors' (the clients console, not server), it would also check that they are dead/spectator, and check that they have the rank of member or above (I use ULX). Any help would be appreciated.
[lua]local function Imgay(ply, text)
if string.sub(text, 1, 9) == "!traitors" then
if ply != LocalPlayer() then return true end
RunConsoleCommand("ttt_print_traitors")
end
end
hook.Add("OnPlayerChat", "I am extremely gay", Imgay)[/lua]
Drop it into GAME/lua/autorun/client
[QUOTE=zerothefallen;42780086][lua]local function Imgay(ply, text)
if string.sub(text, 1, 9) == "!traitors" then
if ply != LocalPlayer() then return true end
RunConsoleCommand("ttt_print_traitors")
end
end
hook.Add("OnPlayerChat", "I am extremely gay", Imgay)[/lua]
Drop it into GAME/lua/autorun/client[/QUOTE]
That works, but it doesn't check if they are dead and what ranks would be able to use this?
And why call the function Imgay?
[QUOTE=TheBobanator2;42780339]That works, but it doesn't check if they are dead and what ranks would be able to use this?
And why call the function Imgay?[/QUOTE]
lets start from the beginning
ttt_print_traitors shows the traitors from that round, and automatically has built in admin checks (IsSuperAdmin()) and dead or not doesnt matter. If you want to see "current alive" traitors, make the talbe yourself.
uh, you can make a custom console command for it yourself. I'll try to make something in a second
[QUOTE=zerothefallen;42780914]lets start from the beginning
ttt_print_traitors shows the traitors from that round, and automatically has built in admin checks (IsSuperAdmin()) and dead or not doesnt matter. If you want to see "current alive" traitors, make the talbe yourself.[/QUOTE]
When I say checks if they are alive, I mean the person using the command, not the traitors
[QUOTE=TheBobanator2;42790939]When I say checks if they are alive, I mean the person using the command, not the traitors[/QUOTE]
[editline]7th November 2013[/editline]
[QUOTE=TheBobanator2;42790939]When I say checks if they are alive, I mean the person using the command, not the traitors[/QUOTE]
[code]local function imhappy(ply, text)
if string.sub(text, 1, 9) == "!traitors" then
if ply = Alive() then return end
RunConsoleCommand("ttt_print_traitors")
end
end
hook.Add("OnPlayerChat", "I am extremely happy", imhappy)[/code]
lua pro2013, should work, test for me bb
[QUOTE=74pantera;42791623][editline]7th November 2013[/editline]
[code]local function imhappy(ply, text)
if string.sub(text, 1, 9) == "!traitors" then
if ply = Alive() then return end
RunConsoleCommand("ttt_print_traitors")
end
end
hook.Add("OnPlayerChat", "I am extremely happy", imhappy)[/code]
[/QUOTE]
What stops you from just running the console command when you are dead instead of the chat command?
[QUOTE=King Penisless;42791701]What stops you from just running the console command when you are dead instead of the chat command?[/QUOTE]
you need admin permissions? lol
[editline]7th November 2013[/editline]
[QUOTE=King Penisless;42791701]What stops you from just running the console command when you are dead instead of the chat command?[/QUOTE]
you need admin permissions? lol, of course, you could always modify the code in the TTT files
[editline]7th November 2013[/editline]
[QUOTE=King Penisless;42791701]What stops you from just running the console command when you are dead instead of the chat command?[/QUOTE]
dumb rate war
[QUOTE=74pantera;42791719]you need admin permissions? lol, of course, you could always modify the code in the TTT files[/QUOTE]
I assumed the point of the OP's request was that he wanted to make so admins couldn't abuse this and would have to be dead to use it. Overriding core TTT files is also not going to be advisable as it makes updating TTT a pain. OP I would suggest overriding the default ttt_print_traitors command and just adding a check to make sure the player is dead.
You can find the code you need here [URL]https://github.com/garrynewman/garrysmod/blob/ff51a59d5a821dec3c8f524631c86150b3e4744d/garrysmod/gamemodes/terrortown/gamemode/admin.lua[/URL]
and 74pantera I rated you dumb because you are relying on a alive check that is client side based, the users can just run the command manually. Never trust the client to tell you the truth and don't advise others to run code that is easily bypassable.
[lua]local function getTraitors(ply, text)
if string.sub(text, 1, 9) == "!traitors" then
if ply != LocalPlayer() or ply:Alive() then return end
if ply:IsUserGroup("groupname") then -- replace groupname with ulx group name.
for k, v in pairs(player.GetAll) do
if v:Role() == ROLE_TRAITOR then -- not sure if Role or GetRole
ply:Print(v:Nick())
end
end
end
end
end
hook.Add("OnPlayerChat", "traitor.Get", getTraitors[/lua]
Try this
[QUOTE=74pantera;42791623]
[code]local function imhappy(ply, text)
if string.sub(text, 1, 9) == "!traitors" then
if ply = Alive() then return end
RunConsoleCommand("ttt_print_traitors")
end
end
hook.Add("OnPlayerChat", "I am extremely happy", imhappy)[/code][/QUOTE]
The if statement is wrong. It's supposed to be:
[code]if ply:Alive() then[/code]
Also the format for the ULX command is wrong. WhitePilot did everything in the function correctly besides the hooking and group checking.
[code]
local function ulx.getTraitors(calling_ply)
if (!calling_ply:Alive() || !calling_ply:IsValid()) then
traitorlist = "Traitors: "
for k, v in pairs(player.GetAll()) do
if v:GetRole() == ROLE_TRAITOR then
traitorlist = traitorlist .. " [" .. v.Nick() .. "]" --Will show up like Traitors: [gurgle528] [white rose] [other name] [another name]
end
end
ULib.tsay(calling_ply, traitorlist, false)
else
ULib.tsayError( calling_ply, "You are alive and cheating is frowned upon!", false ) --If they are alive tell them to go screw themself
end
end
local getTraitors = ulx.command( CATEGORY_NAME, "ulx gettraitors", ulx.getTraitors, "!traitors" ) --registering command
getTraitors:defaultAccess( ULib.ACCESS_ADMIN ) --all admins get it
getTraitors:help( "Identifies the traitors" ) -- what shows up in xgui
[/code]
After putting this into and already existing script (in lua\ulx\modules\sh or addons\ulx\modules\sh) such as utility.lua all admins will have access to this. You can then use xgui (type xgui in console) to control which groups do and do not have access to it.
[edit]
changed script to do :IsValid() on player to allow console
not sure if parentheses are needed to surround it but they look purty in if statement
Erm, you do realize manual/local keybinds are a thing?
Instead of going having to write up Lua or a !traitors command, you could easily just bind ttt_print_traitors to a key via the gmod console.
[QUOTE=gurgle528;42792691]The if statement is wrong. It's supposed to be:
[code]if ply:Alive() then[/code]
Also the format for the ULX command is wrong. WhitePilot did everything in the function correctly besides the hooking and group checking.
[code]
local function ulx.getTraitors(calling_ply)
if (!calling_ply:Alive() || !calling_ply:IsValid()) then -- the ! means not, so if the player is not alive then continue. The || means or, the isvalid will return false if ran on console so if it is not true then continue so basically only continue if false i suck at wording
traitorlist = "Traitors: "
for k, v in pairs(player.GetAll()) do
if v:GetRole() == ROLE_TRAITOR then
traitorlist = traitorlist .. " [" v.Nick() .. "]" --Will show up like Traitors: [gurgle528] [white rose] [other name] [another name]. Too lazy to make it do commas and not do it on the first one and it's not super necessary
end
end
ULib.tsay(calling_ply, traitorlist, false) --last variable (false) means no waiting 1 frame. This will also display it in their chat box so they don't need to go to console
else
ULib.tsayError( calling_ply, "You are alive and cheating is frowned upon!", false ) --If they are alive tell them to go screw themself
end
end
local getTraitors = ulx.command( CATEGORY_NAME, "ulx gettraitors", ulx.getTraitors, "!traitors" ) --registering command
getTraitors:defaultAccess( ULib.ACCESS_ADMIN ) --all admins get it
getTraitors:help( "Identifies the traitors" ) -- what shows up in xgui
[/code]
After putting this into and already existing script (in lua\ulx\modules\sh or addons\ulx\modules\sh) such as utility.lua all admins will have access to this. You can then use xgui (type xgui in console) to control which groups do and do not have access to it.
[edit]
changed script to do :IsValid() on player to allow console
not sure if parentheses are needed to surround it but they look purty in if statement[/QUOTE]
[Error] addons/ulx/lua/ulx/modules/sh/util.lua:4 '(' expected near '.'
1. unknown - addons/ulx/lua/ulx/modules/sh/util.lua:0
getting this error when I join
[editline]8th November 2013[/editline]
[QUOTE=NiandraLades;42795805]Erm, you do realize manual/local keybinds are a thing?
Instead of going having to write up Lua or a !traitors command, you could easily just bind ttt_print_traitors to a key via the gmod console.[/QUOTE]
Thats not the point. I would like a command that people are able to use without having to bind keys. Also the ttt_print_traitors is only usable by super admins.
[QUOTE=TheBobanator2;42799385][Error] addons/ulx/lua/ulx/modules/sh/util.lua:4 '(' expected near '.'
1. unknown - addons/ulx/lua/ulx/modules/sh/util.lua:0
getting this error when I join
[/QUOTE]
What is on line 3-6 of your util.lua?
The only possible error I see in my code would be player.GetAll() but all documentation I find says it should be a .GetAll and not :GetAll.
[QUOTE=gurgle528;42800214]What is on line 3-6 of your util.lua?
The only possible error I see in my code would be player.GetAll() but all documentation I find says it should be a .GetAll and not :GetAll.[/QUOTE]
3
4 local function ulx.getTraitors(calling_ply)
5 if (!calling_ply:Alive() || !calling_ply:IsValid()) then -- the ! means not, so if the player is not alive then continue. The || means or, the isvalid will return false if ran on console so if it is not true then continue so basically only continue if false i suck at wording
6 traitorlist = "Traitors: "
just go edit it so ttt_print_traitors shows to anyone with x rank, literally its 1 line of code
if v.IsUserGroup("DONATOR ADMIN HURP DURP") then
--- let them do shit u leech
end
[QUOTE=zerothefallen;42801617]just go edit it so ttt_print_traitors shows to anyone with x rank, literally its 1 line of code
if v.IsUserGroup("DONATOR ADMIN HURP DURP") then
--- let them do shit u leech
end[/QUOTE]
It's not necessary to edit base game mode files and using ULX (which is what he wants to do) you can easily control which groups gave access to what.
As for why my code isn't working, I suggest trying to move it below another ULX command in util.lua. The command code usually ends with a line setting the commands help. I will check this out further when I get home.
[QUOTE=gurgle528;42803733]I suggest trying to move it below another ULX command in util.lua.[/QUOTE]
Still giving the same error, just different line number.
[QUOTE=rejax;42808867]should be
[CODE]traitorlist = traitorlist .. " [" .. v.Nick() .. "]"[/CODE][/QUOTE]
Ah thank you, I was way too tired to notice it. Updated original code.
[LUA]
function ulx.getTraitors( calling_ply )
if (!calling_ply:Alive() || !calling_ply:IsValid()) then
traitorlist = "Traitors: "
for k, v in pairs(player.GetAll()) do
if v:GetRole() == ROLE_TRAITOR then
traitorlist = traitorlist .. " [" .. v:Nick() .. "]"
end
end
ULib.tsay(calling_ply, traitorlist, false)
else
ULib.tsayError( calling_ply, "You are alive and cheating is frowned upon!", false )
end
end
local getTraitors = ulx.command( CATEGORY_NAME, "ulx gettraitors", ulx.getTraitors, "!traitors" )
getTraitors:defaultAccess( ULib.ACCESS_ADMIN )
getTraitors:help( "Identifies the traitors" )
[/LUA]
After some slight editing, this is the final, fully working code.
Sorry, you need to Log In to post a reply to this thread.