Hi, guys! I hope you can help me :v:
I'm new to Lua and I'm making a script for a sort of SchoolRP.
I was able to put the lessons on a box and they change every 6 minutes, but now I have some problems that I don't know what should I do about it:
- I want it to keep repeating forever, but I can't make a while loop or otherwise it will crash my game;
- I want every player to see the same class on the screen, at the same time. Everytime you join the game it starts from the beginning. Is this because I've put the script file on the autorun folder? Should I put it in the /autorun/server folder?
Here's the code if you want to see what I did:
[CODE]AddCSLuaFile( "classes.lua" );
surface.CreateFont( "mystyle", {
font = "Arial",
extended = false,
size = 20,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} );
function classesBox() -- Box thing function
draw.RoundedBox(3, 5, 250, 350, 60, Color(0,0,0,200));
if FreeTime then
draw.SimpleText( "Free Time", "mystyle", 24, 270, color_white )
end
if Wizardry then
draw.SimpleText ( "Class 1 - Wizardry", "mystyle", 24, 270, color_white );
end
if DADF then
draw.SimpleText ( "Class 3 - Defense Against the Dark Forces", "mystyle", 24, 270, color_white );
end
if Challenge then
draw.SimpleText ( "Challenge and Battle Room", "mystyle", 24, 270, color_white );
end
if Astronomy then
draw.SimpleText ( "Astronomy", "mystyle", 24, 270, color_white );
end
if Alchemy then
draw.SimpleText ( "Class 2 - Alchemy Class", "mystyle", 24, 270, color_white );
end
if Lockdown then
draw.SimpleText ( "LOCKDOWN", "mystyle", 24, 270, Color( 255, 0, 0, 255) );
end
if QuidditchTraining then
draw.SimpleText ( "Quidditch Training", "mystyle", 24, 270, color_white );
end
if Occlumency then
draw.SimpleText ( "Class 1 - Study Of Occlumency", "mystyle", 24, 270, color_white );
end
if Metamorphosis then
draw.SimpleText ( "Class 3 - Metamorphosis Class", "mystyle", 24, 270, color_white );
end
if Cafeteria then
draw.SimpleText ( "Grand Hall - Cafeteria Time", "mystyle", 24, 270, color_white );
end
if QuidditchCompetition then
draw.SimpleText ("Quidditch Competition", "mystyle", 24, 270, color_white );
end
if Muggles then
draw.SimpleText ("Class 5 - Study of Muggles", "mystyle", 24, 270, color_white );
end
if Potions then
draw.SimpleText ("Class 5 - Potions Class", "mystyle", 24, 270, color_white );
end
if Botany then
draw.SimpleText ("Study of Botany", "mystyle", 24, 270, color_white );
end
if History then
draw.SimpleText ("Class 4 - History Class", "mystyle", 24, 270, color_white );
end
end
FreeTime=true
timer.Simple( 360, function() FreeTime = false end );
timer.Simple( 360, function() Wizardry = true end );
timer.Simple( 360 * 2, function() Wizardry = false end );
timer.Simple( 360 * 2, function() DADF = true end );
timer.Simple( 360 * 3, function() DADF = false end );
timer.Simple( 360 * 3, function() Challenge = true end );
timer.Simple( 360 * 4, function() Challenge = false end );
timer.Simple( 360 * 4, function() FreeTime = true end );
timer.Simple( 360 * 5, function() FreeTime = false end );
timer.Simple( 360 * 5, function() DADF = true end );
timer.Simple( 360 * 6, function() DADF = false end );
timer.Simple( 360 * 6, function() Astronomy = true end );
timer.Simple( 360 * 7, function() Astronomy = false end );
timer.Simple( 360 * 7, function() FreeTime = true end );
timer.Simple( 360 * 8, function() FreeTime = false end );
timer.Simple( 360 * 8, function() Challenge = true end );
timer.Simple( 360 * 9, function() Challenge = false end );
timer.Simple( 360 * 9, function() Alchemy = true end );
timer.Simple( 360 * 10, function() Alchemy = false end );
timer.Simple( 360 * 10, function() Lockdown = true end );
timer.Simple( 360 * 11, function() Lockdown = false end );
timer.Simple( 360 * 11, function() QuidditchTraining = true end );
timer.Simple( 360 * 12, function() QuidditchTraining = false end );
timer.Simple( 360 * 12, function() Occlumency = true end );
timer.Simple( 360 * 13, function() Occlumency = false end );
timer.Simple( 360 * 13, function() Metamorphosis = true end );
timer.Simple( 360 * 14, function() Metamorphosis = false end );
timer.Simple( 360 * 14, function() Cafeteria = true end );
timer.Simple( 360 * 15, function() Cafeteria = false end );
timer.Simple( 360 * 15, function() Wizardry = true end );
timer.Simple( 360 * 16, function() Wizardry = false end );
timer.Simple( 360 * 16, function() FreeTime = true end );
timer.Simple( 360 * 17, function() FreeTime = false end );
timer.Simple( 360 * 17, function() QuidditchCompetition = true end );
timer.Simple( 360 * 18, function() QuidditchCompetition = false end );
timer.Simple( 360 * 18, function() Muggles = true end );
timer.Simple( 360 * 19, function() Muggles = false end );
timer.Simple( 360 * 19, function() FreeTime = true end );
timer.Simple( 360 * 20, function() FreeTime = false end );
timer.Simple( 360 * 20, function() Challenge = true end );
timer.Simple( 360 * 21, function() Challenge = false end );
timer.Simple( 360 * 21, function() DADF = true end );
timer.Simple( 360 * 22, function() DADF = false end );
timer.Simple( 360 * 22, function() FreeTime = true end );
timer.Simple( 360 * 23, function() FreeTime = false end );
timer.Simple( 360 * 23, function() Alchemy = true end );
timer.Simple( 360 * 24, function() Alchemy = false end );
timer.Simple( 360 * 24, function() Potions = true end );
timer.Simple( 360 * 25, function() Potions = false end );
timer.Simple( 360 * 25, function() Botany = true end );
timer.Simple( 360 * 26, function() Botany = false end );
timer.Simple( 360 * 26, function() History = true end );
timer.Simple( 360 * 27, function() History = false end );
timer.Simple( 360 * 27, function() FreeTime = true end );
timer.Simple( 360 * 28, function() FreeTime = false end );
timer.Simple( 360 * 28, function() Wizardry = true end );
timer.Simple( 360 * 29, function() Wizardry = false end );
timer.Simple( 360 * 29, function() DADF = true end );
timer.Simple( 360 * 30, function() DADF = false end );
timer.Simple( 360 * 30, function() Challenge = true end );
timer.Simple( 360 * 31, function() Challenge = false end );
timer.Simple( 360 * 31, function() FreeTime = true end );
timer.Simple( 360 * 32, function() FreeTime = false end );
timer.Simple( 360 * 32, function() DADF = true end );
timer.Simple( 360 * 33, function() DADF = false end );
timer.Simple( 360 * 33, function() Astronomy = true end );
timer.Simple( 360 * 34, function() Astronomy = false end );
-- I want it to repeat here
hook.Add("HUDPaint", "MyHudName", classesBox)
[/CODE]
I hope you can help me :D
You should look up how to use tables.
[url]https://www.lua.org/pil/2.5.html[/url]
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2584.html[/url] (outdated)
That's not even your problem, your file is client side, and you want to synchronize all players to view the same thing. You need to use the net library to tell the player (when they join) what the current state is, then keep track of when to switch.
On a server-side script:
[CODE]
local lessonstart = curtime()
util.AddNetworkString( "lessontime" )
function GM:PlayerInitialSpawn(ply)
local curlesson = curtime() - lessonstart
net.Start("lessontime")
net.WriteFloat(curlesson)
net.Send(ply)
end
[/CODE]
On a client-side script:
[CODE]
local curlesson
local numlessons = 32
local lessonlength = 360*24
net.Receive( "lessontime", function()
local servertime = net.ReadFloat()
local curlesson = servertime % (numlessons * lessonlength)
print("I joined during the " .. STNDRD(curlesson) .. " lesson!")
end)
[/CODE]
*Code is untested
If you want something to repeat forever, you should use the timer library.
[url]http://wiki.garrysmod.com/page/Category:timer[/url]
Also not using tables in Lua is worse than rape.
Sorry, you need to Log In to post a reply to this thread.