How would I go about creating a timer that displays as "Minutes:Seconds". My gamemode at the moment is round based and I'd like to show the player how much time is remaining.
[QUOTE=PencilOnDesk;34792113]How would I go about creating a timer that displays as "Minutes:Seconds". My gamemode at the moment is round based and I'd like to show the player how much time is remaining.[/QUOTE]
[lua]
local minutes = math.Round(time / 60)
local seconds = time - (minutes * 60)
[/lua]
There was some easier way though
[QUOTE=Netheous;34800833][lua]
local minutes = math.Round(time / 60)
local seconds = time - (minutes * 60)
[/lua]
There was some easier way though[/QUOTE]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index09bf.html?title=Os.date[/url]
Use the second argument.
Hi!
How would I measure driven kilometers (odometer)? Is there any function for this or must I make it myself? I would like to make on-screen odometer which starts measuring every time player sits in a car in addition to my speedo.
And while at it, how do you check is variable is declared?
Thanks!
How would one properly synchronize SWEPs? [B]IsFirstTimePredicted()[/B] doesn't seem to work. It messes up my PrimaryFire func. Any ideas?
Edit.
Made a [URL="http://www.facepunch.com/threads/1165351?p=34804867#post34804867"]thread[/URL] about this.
[QUOTE=pennerlord;34801077][url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index09bf.html?title=Os.date[/url]
Use the second argument.[/QUOTE]
Is there anyway you could show me an example?
[QUOTE=Jinx786;34801507]Hi!
How would I measure driven kilometers (odometer)? Is there any function for this or must I make it myself? I would like to make on-screen odometer which starts measuring every time player sits in a car in addition to my speedo.
And while at it, how do you save a var so that is it usable next time function is called? Do you use global instead of local?
Thanks![/QUOTE]
Save current (old) position vector. Make a 1 second interval. Now for each second do:
get current pos. Calculate lenght between current vec and older one and add to a global var. Save current vec as old one. Repeat cycle.
The "global" var can simply be a networked int on an entity. And interval even 5 seconds.
Would write some real code, but I'm on a phone.
[QUOTE=aurum481;34805528]Save current (old) position vector. Make a 1 second interval. Now for each second do:
get current pos. Calculate lenght between current vec and older one and add to a global var. Save current vec as old one. Repeat cycle.
The "global" var can simply be a networked int on an entity. And interval even 5 seconds.
Would write some real code, but I'm on a phone.[/QUOTE]
Oh, I get it now. But how do you get current position? (since wiki is down I cant look there :( )
Entity:GetPos()
[QUOTE=Deadman123;34806548]Entity:GetPos()[/QUOTE]
Thanks!
One thing though. I read about calculating distance between two points:
"As you can see, this requires that you perform a square root. Square roots should be avoided like the plague if you want to write fast code. Only perform a Square Root if you really need to."
And since lua is scripting language ... :S
On a DListView, is it possible coloring the text on it, as of multiple colors?
[QUOTE=Persious;34810620]On a DListView, is it possible coloring the text on it, as of multiple colors?[/QUOTE]
[url]http://www.facepunch.com/threads/1023435?highlight=DListView[/url]
Does that thread solve your question?
Not realy, I've already checked the DListView options, but I haven't found any way of only changing the text color. I guess I can do my own skin tho.
[QUOTE=Jinx786;34806691]Thanks!
One thing though. I read about calculating distance between two points:
"As you can see, this requires that you perform a square root. Square roots should be avoided like the plague if you want to write fast code. Only perform a Square Root if you really need to."
And since lua is scripting language ... :S[/QUOTE]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index6da3.html?title=Vector.Distance[/url]
yes its expensive. But you can lighten up the calculations if you do them only every 5 seconds. Calculate without Z axis if there are no hills.
IDEA:
calculate distance based on velocity and time! But wait... Probably still requires vector root calculation. And is not that reliable like 2 solid points.
So yeah, no way out.
You can try using the entity's velocity to get the speed in km/h.
I'm getting this error:
[CODE][gamemodes\mygm\gamemode\sql.lua:44] 'end' expected (to close 'function' at line 28) near '<eof>'
R[/CODE]
With this piece of code:
[CODE]function DoesPlayerSQLExist(ply)//Line 28
local steamID = ply:SteamID()
Msg(ply:Nick().."'s Steam ID is: "..steamID.."\n Checking SQL record...")
result = sql.Query("SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'")
if(result) then
//Code for opening stats
Msg(ply:Nick().."'s SQL record exists!\n")
if(!result) then
//code for creating record
Msg(ply:Nick().."'s SQL does not exist!\n Creating Record!\n")
else
Msg("Something went wrong checking "..ply:Nick().."'s SQL record\n")
end
end[/CODE]
The error is definitely limited to this piece of code.
[QUOTE=joyenusi;34816712]I'm getting this error:
[CODE][gamemodes\mygm\gamemode\sql.lua:44] 'end' expected (to close 'function' at line 28) near '<eof>'
R[/CODE]
With this piece of code:
function DoesPlayerSQLExist(ply)//Line 28 local steamID = ply:SteamID() Msg(ply:Nick().."'s Steam ID is: "..steamID.."\n Checking SQL record...") result = sql.Query("SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'") if(result) then //Code for opening stats Msg(ply:Nick().."'s SQL record exists!\n") if(!result) then //code for creating record Msg(ply:Nick().."'s SQL does not exist!\n Creating Record!\n") else Msg("Something went wrong checking "..ply:Nick().."'s SQL record\n") end end[/CODE]The error is definitely limited to this piece of code.[/QUOTE]
missing an end[lua]
function DoesPlayerSQLExist(ply)//Line 28
local steamID = ply:SteamID()
Msg(ply:Nick().."'s Steam ID is: "..steamID.."\n Checking SQL record...")
result = sql.Query("SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'")
if(result) then
//Code for opening stats
Msg(ply:Nick().."'s SQL record exists!\n")
end -- <-- Missing End
if(!result) then
//code for creating record
Msg(ply:Nick().."'s SQL does not exist!\n Creating Record!\n")
else
Msg("Something went wrong checking "..ply:Nick().."'s SQL record\n")
end
end
[/lua]
[QUOTE=joyenusi;34816712]I'm getting this error:
[CODE][gamemodes\mygm\gamemode\sql.lua:44] 'end' expected (to close 'function' at line 28) near '<eof>'
R[/CODE]
With this piece of code:
[CODE]function DoesPlayerSQLExist(ply)//Line 28
local steamID = ply:SteamID()
Msg(ply:Nick().."'s Steam ID is: "..steamID.."\n Checking SQL record...")
result = sql.Query("SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'")
if(result) then
//Code for opening stats
Msg(ply:Nick().."'s SQL record exists!\n")
if(!result) then
//code for creating record
Msg(ply:Nick().."'s SQL does not exist!\n Creating Record!\n")
else
Msg("Something went wrong checking "..ply:Nick().."'s SQL record\n")
end
end[/CODE]
The error is definitely limited to this piece of code.[/QUOTE]
[lua]
function DoesPlayerSQLExist(ply)//Line 28
local steamID = ply:SteamID()
Msg(ply:Nick().."'s Steam ID is: "..steamID.."\n Checking SQL record...")
result = sql.Query("SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'")
if(result) then
//Code for opening stats
Msg(ply:Nick().."'s SQL record exists!\n")
end
if(!result) then
//code for creating record
Msg(ply:Nick().."'s SQL does not exist!\n Creating Record!\n")
else
Msg("Something went wrong checking "..ply:Nick().."'s SQL record\n")
end
end
[/lua]
You are missing an end.
Posted second too late.
Edited for post below, end needs to be up a few lines under first if.
I didn't know that two if's in succession both required seperate ends. I just assumed the console was wrong and not me. Thanks a lot!
[QUOTE=Panto;34816116]You can try using the entity's velocity to get the speed in km/h.[/QUOTE]
Entity.GetVelocity returns a vector and to calculate a scalar lenght/power of it you need to use root fucntion with the vector.
What I proposed earlier with 2 vectors is more reliable than velocity * time.
[QUOTE=Persious;34813250]Not realy, I've already checked the DListView options, but I haven't found any way of only changing the text color. I guess I can do my own skin tho.[/QUOTE]
Yeah I was going to mention you're own skin but do you by any chance have a tutorial on how to make your own skin?
Does anyone know a way to detect a collision between two objects? I know you can do it with SENTs using ENT:PhysicsCollide, but if I just have two jeeps that crash into each other, is there a way to detect that?
[QUOTE=aurum481;34815712][url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index6da3.html?title=Vector.Distance[/url]
yes its expensive. But you can lighten up the calculations if you do them only every 5 seconds. [/QUOTE]
While raising the timer countdown time would lighten up the calculations it would also have a huge impact on precision on roads like this: [url]http://shrani.si/f/1p/M0/ZdaaBDn/1/example.png[/url]
Hmm, based on speed, I could try to squeeze something out.
[CODE]
distance = distance + LocalPlayer():GetVelocity():Length() / (1 / timer) * 0.00001905
[/CODE]
This is probably lighter? Im interested how much time does GetVelocity() cost. If I make this calculation 10 times in a second or one square root in a second, is the first option still preferable :S
How can I access ULX's promote and demote command from serverside gamemode code?
[QUOTE=Dorkslayz;34819135]How can I access ULX's promote and demote command from serverside gamemode code?[/QUOTE]
[url]http://ulyssesmod.net/docs/files/lua/ulib/server/ucl-lua.html[/url]
[QUOTE=Jinx786;34818791]While raising the timer countdown time would lighten up the calculations it would also have a huge impact on precision on roads like this: [url]http://shrani.si/f/1p/M0/ZdaaBDn/1/example.png[/url]
Hmm, based on speed, I could try to squeeze something out.
[CODE]
distance = distance + LocalPlayer():GetVelocity():Length() / (1 / timer) * 0.00001905
[/CODE]
This is probably lighter?[/QUOTE]
so we are stuck on this question :v:
[lua]
local distance = 0 --we need this outside the function
local pos1 = LocalPlayer():GetPos() --initial pos so its not nil and we also need this to save outside func
function calcDist()
local pos2 = LocalPlayer():GetPos() --current position vector
local lenght = pos1:Lenght(pos2)
distance = distance + lenght --might want to throw in your unit conversion here
pos1 = pos2 --so we get correct distance next time
end
timer.Create("distancecalculate interval",1,0,calcDist) -- check if interval is 1 second and times repeated = infinity[/lua]
Again, no way for me to check if this works. Look which way is better for you.
Damnit page king
Could someone explain how I could make this camera rotate from a y axis around to move the camera slowly in front of me instead of just snapping to this view?
[lua]
hook.Add("CalcView", "CalcTheView", function(ply, pos, angles, fov)
local view = {}
view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50)
view.angles = (LocalPlayer():EyePos() - view.origin):Angle()
view.fov = fov
return view
end)
hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply)
return true
end
[/lua]
how do i get an int value of player velocity and remove Z (up down)? i just want a value that shows directional velocity (flat surface)
[QUOTE=brandonj4;34828884]Could someone explain how I could make this camera rotate from a y axis around to move the camera slowly in front of me instead of just snapping to this view?
[lua]
hook.Add("CalcView", "CalcTheView", function(ply, pos, angles, fov)
local view = {}
view.origin = LocalPlayer():GetPos()-(LocalPlayer():GetAngles():Forward()*60)+Vector(0,-10,50)
view.angles = (LocalPlayer():EyePos() - view.origin):Angle()
view.fov = fov
return view
end)
hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply)
return true
end
[/lua][/QUOTE]
I haven't worked with CalcView yet, but I think you need this:
[B][URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index95e8.html?title=G.RealTime"]G.RealTime [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B]
[QUOTE=Kwaq;34831556]how do i get an int value of player velocity and remove Z (up down)? i just want a value that shows directional velocity (flat surface)[/QUOTE]
local dir = player:GetVelocity()
dir.z = 0
Sorry, you need to Log In to post a reply to this thread.