• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=Sean Bean;52484853]Is there anyway to open the options dialog in-game? Something similar to [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/RunGameUICommand]RunGameUICommand[/url]("OpenOptionsDialog") maybe?[/QUOTE] [CODE]RunConsoleCommand("gamemenucommand", "openoptionsdialog")[/CODE] This works for me.
[QUOTE=ThatLing;52484862][CODE]RunConsoleCommand("gamemenucommand", "openoptionsdialog")[/CODE] This works for me.[/QUOTE] I had no idea gamemenucommand was even a thing, thanks.
[lua] if (SERVER) then timer.Create( "timecheckerformaprr", 45, 0, function() maprrchecker() end ) function maprrchecker() print(os.date( "%I:%M %p" )) if os.date( "%I:%M %p" ) == "5:40 AM" then print('TIME MATCHED!') changeMapOrWhatever() end end end [/lua] any idea what im doing wrong or why its not working? even if osdate print shows exact thing as im comparing to it never really triggers. I just want to restart map early in morning every 24h any better solutions for this?
[QUOTE=bigdogmat;52483930]include doesn't work like that in Lua, it's a separate environment. You can either define the function as a global, put it into a global table, or return it in the file, e.g. [/QUOTE] Alright, thanks, I'll use a global table. [editline]19th July 2017[/editline] [QUOTE=Ramirex5;52484975] any idea what im doing wrong or why its not working? even if osdate print shows exact thing as im comparing to it never really triggers. I just want to restart map early in morning every 24h any better solutions for this?[/QUOTE] You could try [CODE]if tostring(os.date( "%I:%M %p" )) == "5:40 AM" then[/CODE] instead, only thing I can think of is that os.date returns something other than a string that means it's never equal. Also, you should probably just calculate the number of seconds until your desired time and set a timer for that amount, checking every 45s seems wasteful. os.time() without any arguments will give you the current unix time (seconds since Thursday, 1 January 1970) If you divide that number by the number of seconds in a day (86400) and round it up, you can get the unix time for midnight tomorrow. If you want to restart the map at midnight UTC then just use that value, otherwise just add hours and minutes onto that time until you get the restart time you want. Then all you need to do is take the current time away from this time to get the number of seconds to wait until restarting. I haven't tested this code but something like this should work: [CODE] local currentTime = os.time() local tomorrowMidnight = math.ceil(os.time() / 86400) local offset = 2 * 86400 --2 hours (02:00AM UTC) local restartTime = tomorrowMidnight + offset local timeToWait = restartTime - currentTime timer.Simple(timeToWait, function() print("Map is restarting!") RestartMap() end) [/CODE] Obviously you don't need to separate everything out into different variables, I just wanted to make the code more clear.
Does anyone know a good Capture The Point gamemode so i can use it as a base? My gLua skill is still quite bad and I have to scratch it because the code is so messy, inefficient and really UgLy
Will the variable "myTable" be this: [CODE] { "apple", "potato" } [/CODE] ... if ... [CODE] local myTable = string.ToTable( file.Read("lols.txt") ) [/CODE] ... and this is lols.txt [CODE] myTable = { "apple", "table" } [/CODE]
Can somebody tell what options I have for a simple persistence layer? I've heard of a mysql addon for gmod i.e.
[code] function SetSpectator(ply, obs) if obs == 1 then ply:Spectate( OBS_MODE_ROAMING ) ply:SetNoTarget(true) elseif obs == 0 then ply:UnSpectate() ply:SetNoTarget(false) ply:Spawn() end print(ply:Team()) print(ply:GetObserverMode()) end function GM:PlayerInitialSpawn(ply) if ply:Team() == 0 then SetSpectator(ply, 1) else SetSpectator(ply, 0) end end [/code] Spectator mode isn't working. Players join the server, are on the correct team, but I can walk around, jump, and crouch. The only difference is my screen bounces around like my character is having a seizure as I walk around, and I'm not making footstep noises. print(ply:Team()) returns as 0, so the team is correct. print(ply:GetObserverMode()) returns as 6, so it's being set correctly. [b][update][/b] Players are still visible when joining the server and have the same problems as above (mode: Roaming, team = 0) [b][solution][/b] Added "GAMEMODE:PlayerSpawnAsSpectator()" to GM:PlayerSpawn().
Does anyone know how Pointshop item sorting works? I want to sort the items by the ITEM.AllowedUserGroup table. Right now it looks like this: [IMG]http://puu.sh/wOcIt/892eb0e2c5.jpg[/IMG]
I'm trying to help some guy with a SENT, but for some reason no matter what I do, the entity's model is always error.mdl on the client. This is init.lua: [CODE] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( "shared.lua" ) function ENT:SpawnFunction( ply, tr, ClassName ) if !tr.Hit then return end local SpawnPos = tr.HitPos + tr.HitNormal * 16 local ent = ents.Create( ClassName ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end function ENT:Intialize() self:SetModel( "models/props_interiors/VendingMachineSoda01a.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self:PhysWake() self:SetUseType( SIMPLE_USE ) end [/CODE] I've been trying for too long. Please send help.
Move the Initialize method to shared. Do a SERVER check for the SetUseType call.
[QUOTE=code_gs;52488367]Move the Initialize method to shared. Do a SERVER check for the SetUseType call.[/QUOTE] It's still an error. Test it in game, I have no idea why
You spelled "In[B]i[/B]tialize" incorrectly :) Also, PhysicsInit calls SetSolid internally.
- snip -
[QUOTE=code_gs;52488406]You spelled "In[B]i[/B]tialize" incorrectly :) Also, PhysicsInit calls SetSolid internally.[/QUOTE] I WANT TO DIE RIGHT HERE RIGHT NOW GIVE ME THE GUN IT'S TIME
Is there a way I can add stuff to a texture/material with the surface.* functions?
[QUOTE=meharryp;52488528]Is there a way I can add stuff to a texture/material with the surface.* functions?[/QUOTE] No, but you might be able to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/GetRenderTarget]GetRenderTarget[/url] somehow Does anyone know a way to check if the x, y and z components of a vector are the same? [editline]20th July 2017[/editline] Found it: [CODE] if(x == y && x == z && y == z) then -- etc [/CODE]
[QUOTE=MPan1;52488532]No, but you might be able to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/GetRenderTarget]GetRenderTarget[/url] somehow Does anyone know a way to check if the x, y and z components of a vector are the same? [editline]20th July 2017[/editline] Found it: [CODE] if(x == y && x == z && y == z) then -- etc [/CODE][/QUOTE] Really? Could have sworn I've seen someone overwrite a texture and add stuff to it before. Anyway to make stuff drawn with cam.Start3D2D respect the lighting?
[QUOTE=meharryp;52488921]Really? Could have sworn I've seen someone overwrite a texture and add stuff to it before. Anyway to make stuff drawn with cam.Start3D2D respect the lighting?[/QUOTE] I thought they did it without using Start3D2D... I remember something as well but I can't find it
Can someone tell me why this code in sv_player_extension.lua doesn't work: [CODE] if PS.Config.PointsOverTime then timer.Create('PS_PointsOverTime_' .. self:UniqueID(), PS.Config.PointsOverTimeDelay * 60, 0, function() if !IsValid(self) then return end if ply:IsUserGroup( "vip" ) then self:PS_GivePoints(PS.Config.PointsOverTimeAmountVip) else self:PS_GivePoints(PS.Config.PointsOverTimeAmount) end self:PS_Notify("You've been given ", PS.Config.PointsOverTimeAmount, " ", PS.Config.PointsName, " for playing on the server!") end) end [/CODE] I have added this to my sh_config.lua: [CODE] PS.Config.PointsOverTimeAmountVip = 60 [/CODE] there are no errors in my server console or my client console.
You should be getting an error, ply is undefined. You should be using self. Also, use SteamID instead of UniqueID.
[QUOTE=code_gs;52490037]You should be getting an error, ply is undefined. You should be using self. Also, use SteamID instead of UniqueID.[/QUOTE] Changing to self somehow broke my TTT gamemode. [editline]20th July 2017[/editline] Fixed completely. Sorry if I wasted your time and thanks for the help.
[QUOTE=meharryp;52488921]Really?[/QUOTE] x IS y x IS z ----------------------------------------- If x,y and x,z are identical, then it must follow that y is the same as z
[QUOTE=Rory;52490177]x IS y x IS z ----------------------------------------- If x,y and x,z are identical, then it must follow that y is the same as z[/QUOTE] Just to note, this is called the Transitive property in math terms. It's essentially the basis of algebraic deduction.
How would one disable gravity for a set of named props in TTT using lua_run like in sandbox you can just right click like so and its really cool: [url]http://i.imgur.com/l4CM94v.jpg[/url] Basically for a map set in space where traitors can disable gravity (also does this have a huge networking cost?)
[QUOTE=Rocketsurgery;52491343]How would one disable gravity for a set of named props in TTT using lua_run like in sandbox you can just right click like so and its really cool: [url]http://i.imgur.com/l4CM94v.jpg[/url] Basically for a map set in space where traitors can disable gravity (also does this have a huge networking cost?)[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/PhysObj/EnableGravity]PhysObj:EnableGravity[/url] [URL="https://github.com/MysteryPancake/Gravity-Editor"](At least based on my ancient awful addon)[/URL] [CODE] local props = ents.FindByClass("prop_*") for _, v in pairs(props) do if(v:GetPhysicsObject():IsValid()) then for i=0,v:GetPhysicsObjectCount()-1 do v:GetPhysicsObjectNum(i):EnableMotion(true) v:GetPhysicsObjectNum(i):Wake() end end end [/CODE] [editline]21st July 2017[/editline] [URL="https://github.com/Facepunch/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/lua/autorun/properties/gravity.lua#L43-L50"]It's what the gravity option does as well I think[/URL] [editline]21st July 2017[/editline] Or [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetGravity]Entity:SetGravity[/url]
How do I convert a vector to a table? [editline]21st July 2017[/editline] Nevermind
[QUOTE=MPan1;52491670]How do I convert a vector to a table? [editline]21st July 2017[/editline] Nevermind[/QUOTE] For anyone else who stumbles upon the same question: [code]local VECTOR = FindMetaTable("Vector") function VECTOR:ToTable() return {self[1], self[2], self[3]} end[/code]
[QUOTE=code_gs;52491742]For anyone else who stumbles upon the same question: [code]local VECTOR = FindMetaTable("Vector") function VECTOR:ToTable() return {self[1], self[2], self[3]} end[/code][/QUOTE] Don't you mean {self.x, self.y, self.z}? Also, a vector can just be used as a table, can't it? [editline]21st July 2017[/editline] [QUOTE=meharryp;52488921]Really? Could have sworn I've seen someone overwrite a texture and add stuff to it before. Anyway to make stuff drawn with cam.Start3D2D respect the lighting?[/QUOTE] Not sure why MPan said no while simultaneously giving you the function that makes it possible. That and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/PushRenderTarget]render.PushRenderTarget[/url], and you can go nuts. Just don't forget to use cam.Start2D, cam.End2D and render.PopRenderTarget. [editline]21st July 2017[/editline] Example of vanilla gmod doing the same thing: [url]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/cl_viewscreen.lua#L5-L6[/url]
[QUOTE=NeatNit;52491839]Don't you mean {self.x, self.y, self.z}? Also, a vector can just be used as a table, can't it?[/QUOTE] You can also index vectors with numbers. It's actually slightly more efficient since you're not using a string key. You cannot substitute Vector objects with a table in C functions, but it's useful to change the userdata into a table when just doing pure math in Lua.
Sorry, you need to Log In to post a reply to this thread.