• Please Help! Advert System
    15 replies, posted
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. [code] 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 [/code] EDIT: Edited code to fix misspelling seen below.
[QUOTE=crazyscouter;45377877]You'll need to do it server-side, and network to the client. See my example below. [code] 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 = GetCanVarString("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); local msg = hintsEnglish[num]; end chat.AddText(Color( 50, 255, 50 ), "[xx] ", Color( 255, 255, 255 ), msg ); //show the message; end) end [/code][/QUOTE] Is there something else I have to do? I put it in my init.lua, but nothing happened.
Well it's shared..
[QUOTE=crazyscouter;45377973]Well it's shared..[/QUOTE] 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.
[QUOTE=crazyscouter;45378069]Then make a new file in lua/autorun. Also you shouldn't be editing core DarkRP files.[/QUOTE] 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] [QUOTE=crazyscouter;45378069]Then make a new file in lua/autorun. Also you shouldn't be editing core DarkRP files.[/QUOTE] [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
GetC[B]o[/B]nVarString
[QUOTE=Frozendairy;45378082]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. [/QUOTE] 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.
[QUOTE=Robotboy655;45378325]GetC[B]o[/B]nVarString[/QUOTE] [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
[QUOTE=Robotboy655;45378325]GetC[B]o[/B]nVarString[/QUOTE] [QUOTE=Frozendairy;45378348][ERROR] addons/adverts/lua/autorun/adverts.lua:35: attempt to call global 'Get[B]c[/B]onVarString' (a nil value) 1. func - addons/adverts/lua/autorun/adverts.lua:35 2. unknown - lua/includes/modules/net.lua:32[/QUOTE] [QUOTE=Robotboy655;45378325]Get[B]C[/B]onVarString[/QUOTE] Lua is Case Sensitive.
[QUOTE=Acecool;45378369]Lua is Case Sensitive.[/QUOTE] 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..
[QUOTE=crazyscouter;45378596]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..[/QUOTE] 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 :-)
[QUOTE=Acecool;45378698]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 :-)[/QUOTE] 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] [QUOTE=crazyscouter;45378596]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..[/QUOTE] 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
Sorry, you need to Log In to post a reply to this thread.