• Comms advert?
    4 replies, posted
I made thread about this awhile back, but I don't think I fully understood what I was trying to say. I found a little piece of code that is supposed to create an alternative /advert command but for comms. I just do not know where to put it? Anybody have any ideas? Server.cfg? [CODE]local function PlayerAdvertise(ply, args) if args == "" then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", "")) return "" end local DoSay = function(text) if text == "" then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", "")) return end for k,v in pairs(player.GetAll()) do local col = team.GetColor(ply:Team()) DarkRP.talkToPerson(v, col, DarkRP.getPhrase("comms") .. " " .. ply:Nick(), Color(255, 255, 0, 255), text, ply) end end return args, DoSay end DarkRP.defineChatCommand("comms", PlayerAdvertise, 1.5)[/CODE] Also how would I implement only certain jobs being able to see it? Thanks for help :D
Put it in any server file (.lua not .cfg) And to make it for certain teams, check if the player is in the team (in the loop), if so, run that talktoperson function. I would type up some simple code but I'm not on my pc at the moment. Edit: Here is an example: [CODE] local teams = {TEAM_TEAM1, TEAM_TEAM2} for k, v in pairs(player.GetAll()) do if table.HasValue(teams, v:Team()) then --Run the function on v here. end end [/CODE]
Alright I think I did what you were trying to tell me, I am not too good at lua but here it is. Is it sort of right? [CODE]local function PlayerAdvertise(ply, args) if args == "" then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", "")) return "" end local DoSay = function(text) if text == "" then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", "")) return end local teams = {TEAM_TEAM1, TEAM_TEAM2} for k, v in pairs(player.GetAll()) do if table.HasValue(teams, v:Team()) then DarkRP.talkToPerson(v, col, DarkRP.getPhrase("RComms") .. " " .. ply:Nick(), Color(100, 0, 17, 255), text, ply) end end return args, DoSay end DarkRP.defineChatCommand("RComms", PlayerAdvertise, 1.5)[/CODE] [editline]6th June 2016[/editline] Also I understand how you implemented the teams in here, but will this make it so only those teams will see it? or just for them to type it? [editline]6th June 2016[/editline] Sorry If I sound dumb I feel you
[QUOTE=shucksnoris;50466576]Alright I think I did what you were trying to tell me, I am not too good at lua but here it is. Is it sort of right? [CODE]local function PlayerAdvertise(ply, args) if args == "" then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", "")) return "" end local DoSay = function(text) if text == "" then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", "")) return end local teams = {TEAM_TEAM1, TEAM_TEAM2} for k, v in pairs(player.GetAll()) do if table.HasValue(teams, v:Team()) then DarkRP.talkToPerson(v, col, DarkRP.getPhrase("RComms") .. " " .. ply:Nick(), Color(100, 0, 17, 255), text, ply) end end return args, DoSay end DarkRP.defineChatCommand("RComms", PlayerAdvertise, 1.5)[/CODE] [editline]6th June 2016[/editline] Also I understand how you implemented the teams in here, but will this make it so only those teams will see it? or just for them to type it? [editline]6th June 2016[/editline] Sorry If I sound dumb I feel you[/QUOTE] Replace th TEAM_TEAM1 and the others with the teams you want to see the advert
Thanks a ton man, you really helped me out. +1 to you. Thanks for all the help but I have seem to run into a problem [CODE]local function PlayerAdvertise(ply, args) if args == "" then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", "")) return "" end local DoSay = function(text) if text == "" then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", "")) return end local teams = {TEAM_SUPREME, TEAM_YOUNGLING, TEAM_INITIATE, TEAM_PADAWAN, TEAM_KNIGHT, TEAM_MASTER, TEAM_COUNCIL, TEAM_GRAND, TEAM_MLGMAN, TEAM_JEDISMOKE, TEAM_RECRUITR, TEAM_REPT, TEAM_REPS, TEAM_REPH, TEAM_REPM, TEAM_REPC, TEAM_REPP, TEAM_REPSF, TEAM_REPCOM, TEAM_REPG, TEAM_REPSC, TEAM_REPEN, TEAM_REPLI, TEAM_REPCA, TEAM_REPCOMMO, TEAM_REPAD} for k, v in pairs(player.GetAll()) do if table.HasValue(teams, v:Team()) then DarkRP.talkToPerson(v, col, DarkRP.getPhrase("rcomms") .. " " .. ply:Nick(), Color(100, 0, 17, 255), text, ply) end end return args, DoSay end DarkRP.defineChatCommand("rcomms", PlayerAdvertise, 1.5)[/CODE] This is my finished product, the only problem is, it does not work. Do I need to replace the starting function with something else? I put it inside /garrysmod/gamemodes/darkrp/gamemode/modules/chat/chatcommands.lua. [editline]6th June 2016[/editline] I put the rcomms inside /garrysmod/gamemodes/darkrp/gamemode/modules/chat/sh_chatcommands.lua. Declaring the Chat command. IT sort of works. The advert part works but other people who are not of the TEAM can still see it. Also it looks like this [URL="http://steamcommunity.com/sharedfiles/filedetails/?id=698857424"]http://steamcommunity.com/sharedfiles/filedetails/?id=698857424[/URL]
Sorry, you need to Log In to post a reply to this thread.