Please Help! Advert System

So I had this system,

HintsRus = {

}

HintsEng = {
“xx Is Un-active.”,
“xx Is Active.”

}

timer.Create( “Client.HINTS”, 1220, 0, function()
if ( GetConVarString( “gmod_language” ) == “ru” ) then
chat.AddText( Color( 50, 255, 50 ), "[xx] ", Color( 255, 255, 255 ), HintsRus[ math.random( 1, #HintsRus ) ] )
else
chat.AddText( Color( 50, 255, 50 ), "[xx] ", Color( 255, 255, 255 ), HintsEng[ math.random( 1, #HintsEng ) ] )
end
end )

but it’s client side and makes it show up at different times depending on when you joined, How can I make it so it shows at the same time for everyone regardless of when they joined?

You’ll need to do it server-side, and network to the client. See my example below.



if (SERVER) then
	util.AddNetworkString("SendHints");

	local hintDelay = 60;

	local function Hints()
		net.Start("SendHints"); //send the message to display the hint.
		net.Broadcast();
	end


	hook.Add("Initialize", "SendHints", function() //hook into initialze to create a server timer that will be ran on all clients at the same time.
		Hints();

		timer.Create("SendHints", hintDelay, 0, function()
			Hints(); //execute the function.
		end)
	end)

else

	//Definitions
	local hintsRussian = {

	}
	local hintsEnglish = {
		"xx is un-active!";
		"xx is active!";
	}



	net.Receive("SendHints", function()

		local isrus = GetConVarString("gmod_language") == "ru";
		local msg = "No hint!";
		if (isrus) then
			local ran = math.random(1, #hintsRussian);
			msg = hintsRussian[ran];
		else
			local num = math.random(1, #hintsEnglish);
			msg = hintsEnglish[num];
		end

		chat.AddText(Color( 50, 255, 50 ), "[xx] ", Color( 255, 255, 255 ), msg ); //show the message;
	end)
	

end


EDIT: Edited code to fix misspelling seen below.

Is there something else I have to do? I put it in my init.lua, but nothing happened.

Well it’s shared…

I’m sorry, I’m unfamiliar with darkrp, theres no shared file in DarkRP.

Then make a new file in lua/autorun. Also you shouldn’t be editing core DarkRP files.

Honestly, who really cares, It really doesn’t matter.
Core files shouldn’t be edited if your a six yearold who wants to add custom jobs.

[editline]13th July 2014[/editline]

[ERROR] addons/adverts/lua/autorun/adverts.lua:35: attempt to call global ‘GetCanVarString’ (a nil value)

  1. func - addons/adverts/lua/autorun/adverts.lua:35
  2. unknown - lua/includes/modules/net.lua:32

GetConVarString

Actually, it’s because it’s easier to update and it prevents a lot of “new” people from messing up the gamemode and then complain about a broken gamemode.

[ERROR] addons/adverts/lua/autorun/adverts.lua:35: attempt to call global ‘GetconVarString’ (a nil value)

  1. func - addons/adverts/lua/autorun/adverts.lua:35
  2. unknown - lua/includes/modules/net.lua:32

Lua is Case Sensitive.

Wow, I’m stupid, the system only says “No hint!” It doesn’t utilize the above messages.

Oh shit. I was an idiot with something up there… I’m sorry. I fixed it along with the misspelling. See if it works now…

Thanks everyone! I think I’ve cashed out all of my idiot tokens for the day.

Don’t feel bad or ashamed about asking questions. We all started somewhere and we didn’t learn everything overnight. Many of us are still learning new things daily; just keep at it and keep trying :slight_smile:

Well, It’s like instantly repeating though i changed all the timers to 1200…

if (SERVER) then
util.AddNetworkString(“SendHints”);

local hintDelay = 1200;

local function Hints()
	net.Start("SendHints"); //send the message to display the hint.
	net.Broadcast();
end


hook.Add("Initialize", "SendHints", function() //hook into initialze to create a server timer that will be ran on all clients at the same time.
	Hints();

	timer.Create("SendHints", hintDelay, 1200, function()
		Hints(); //execute the function.
	end)
end)

else

//Definitions
local hintsRussian = {

}
local hintsEnglish = {
	"Purge is un-active!";
	"Purge is active!";
}



net.Receive("SendHints", function()

	local isrus = GetConVarString("gmod_language") == "ru";
	local msg = "No hint!";
	if (isrus) then
		local ran = math.random(1, #hintsRussian);
		msg = hintsRussian[ran];
	else
		local num = math.random(1, #hintsEnglish);
		msg = hintsEnglish[num];
	end

	chat.AddText(Color( 50, 255, 50 ), "[Purge] ", Color( 255, 255, 255 ), msg ); //show the message;
end)

end

[editline]13th July 2014[/editline]

Well, It’s like instantly repeating though i changed all the timers to 1200…

if (SERVER) then
util.AddNetworkString(“SendHints”);

local hintDelay = 1200;

local function Hints()
net.Start(“SendHints”); //send the message to display the hint.
net.Broadcast();
end

hook.Add(“Initialize”, “SendHints”, function() //hook into initialze to create a server timer that will be ran on all clients at the same time.
Hints();

timer.Create(“SendHints”, hintDelay, 1200, function()
Hints(); //execute the function.
end)
end)

else

//Definitions
local hintsRussian = {

}
local hintsEnglish = {
“Purge is un-active!”;
“Purge is active!”;
}

net.Receive(“SendHints”, function()

local isrus = GetConVarString(“gmod_language”) == “ru”;
local msg = “No hint!”;
if (isrus) then
local ran = math.random(1, #hintsRussian);
msg = hintsRussian[ran];
else
local num = math.random(1, #hintsEnglish);
msg = hintsEnglish[num];
end

chat.AddText(Color( 50, 255, 50 ), "[Purge] ", Color( 255, 255, 255 ), msg ); //show the message;
end)

end