DarkRP Anonymous Advertisement

Hi.
I’m quite new to LUA so bear with me here, and don’t hate on DarkRP.
I was trying to make a feature where if a player typed “/anonadvert <message>” it would show up as this (in white and a global message):
[Anonymous] <message>

I put this in the file main.lua:


local function PlayerAnonAdvertise(ply, args)
	if args == "" then return "" end
	local DoSay = function(text)
		if text == "" then return end
		for k,v in pairs(player.GetAll()) do
			local col = team.GetColor(ply:Team())
			TalkToPerson(v, col, LANGUAGE.Anonymous .." "..Color(255,255,255,255), text, ply)
		end
	end
	return args, DoSay
end
AddChatCommand("/anonadvert", PlayerAnonAdvertise)

However when I did the command /anonadvert nothing happened.
Could someone clue me in?
On top of that, is there anything like that to make a local OOC?
Thanks again

Perhaps, I’m stupid, or you’re stupid, or we are both stupid… or
I don’t know, but…

[lua] if args == “” then return “” end
local DoSay = function(text)
if text == “” then return end[/lua]

What do you mean with that?

Just check for lua errors first… I’m too tired to think atm.

As far as local OOC, here’s code


function LOOC(ply, args)

if args == "" then return "" end
local col = team.GetColor(ply:Team())
local col2 = Color(128,0,0,255)
if not ply:Alive() then
col2 = Color(255,200,200,255)
col = col2
end
TalkToRange(ply, "(LocalOOC) " .. ply:Nick(), args, 350) 
return ""
end
AddChatCommand(".//", LOOC, true)
AddChatCommand("[[", LOOC, true)
AddChatCommand("/looc", LOOC, true)

Haven’t tested but I believe it will work.

You sure that’ll work without the spaces and such?

For the anonymous advertisements, try this:

[lua]
local function PlayerAnonAdvertise(ply, args)
if args == “” then return “” end
for k,v in pairs(player.GetAll()) do
local col = Color( 150, 150, 0 ) – what color you want the adverts to be
TalkToPerson(v, col, LANGUAGE.Anonymous, col, args, ply)
end
return “”
end
AddChatCommand("/anonadvert", PlayerAnonAdvertise)[/lua]

I used that, but I get the error
[gamemodes\darkrp\gamemode\main.lua:736] attempt to index global ‘GM’ (a nil value)
Any idea what this could mean?

What’s line 736

  1.            local audience = {}
    
  2.            if ply:IsCP() then\
    

I deleted it, too, now but the same exact error shows.

What program are you using for coding? Sometimes the line in the program doesn’t read as the same line in gmod if, for example, the coding program counts the comments as lines.

Can you list all the instances of “GM” in your code? Or just copy and paste the whole code into the thread

I’m not sure what causes your GM error.

However, your original problem is that you’ve forgot a comma.
[lua]
TalkToPerson(v, col, LANGUAGE.Anonymous …" "…Color(255,255,255,255), text, ply)
[/lua]

should be

[lua]
TalkToPerson(v, col, LANGUAGE.Anonymous …" ", Color(255,255,255,255), text, ply)
[/lua]

What do you mean local OOC? Like, only to people within range?
If so, you’ve got TalkToRange. Looks like this:

[lua]
function TalkToRange(ply, PlayerName, Message, size) // definition
TalkToRange(ply, “(”… LANGUAGE.whisper … ") " … ply:Nick(), text, 90) // example of use, where 90/size is the distance of your local chat. Yell is 550.
[/lua]