I'm very new to coding in LUA, and I'm trying to start with a racing gamemode.
For this I would like a timer to count upwards, but every tutorial I find it only shows how to make one counting down.
I have just a skeleton gamemode, with cl_init, init, shared.
It would be a big help to me if you could explain a simple timer like that.
Thanks in advance! <3
[lua]starttime = CurTime( ) // Put this when you start the timer
time = CurTime( ) - starttime; // Put this where you output the time
print( "The time is now at: " .. tostring( time ) )[/lua]
Thanks for your reply, but I don't quite get LUA yet, how would I print the time every tick or second?
This is what I have atm:
[B]init.lua[/B]
[CODE]AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function GM:PlayerConnect( name, ip )
print("Player: " .. name .. ", has joined the game.")
end
function GM:PlayerInitialSpawn( ply )
print("Player: " .. ply:Nick() .. ", has spawned.")
starttime = CurTime( )
end
function GM:PlayerAuthed( ply, steamID, uniqueID )
print("Player: " .. ply:Nick() .. ", has gotten authed.")
end
time = CurTime( ) - starttime;
print( "The time is now at: " .. tostring( time ) )[/CODE]
[lua]
local time = CurTime(); //Current time the server has been up
time = time + 2; //This means 2 seconds from now
function GM:Think();
if ( CurTime() >= time ) then //If the current time is past the 'time' var
print( "Hello World!" );
time = CurTime() + 2; //This will make "Hello World" print every '2' seconds
end
end[/lua]
[QUOTE=Annoyed Tree;40431269][lua]
local time = CurTime(); //Current time the server has been up
time = time + 2; //This means 2 seconds from now
function GM:Think();
if ( CurTime() >= time ) then //If the current time is past the 'time' var
print( "Hello World!" );
time = CurTime() + 2; //This will make "Hello World" print every '2' seconds
end
end[/lua][/QUOTE]
Aah, thank you very much for posting, I had to remove some semicolons but it works perfectly, I'll figure it out from here :3
Sorry, you need to Log In to post a reply to this thread.