• Problems That Don't Need Their Own Thread v5
    3,706 replies, posted
  • [IMG]https://u.nya.is/sldwzj.png[/IMG] [B]Welcome to Problems That Don't Need Their Own Thread v5![/B] Have a small problem in your Lua code that keeps nagging you, but you feel like it's not worth making a thread for? Well then you've come to the right place! Reply to this thread with your problems and we might just be able to help you out! [B]How to go about posting your issue[/B] - Give a good description on the issue - What have you tried doing to solve the issue? (make a post if you've already tried everything you can) - Post the necessary code for someone to help you solve the issue (wrap it in [noparse][code]...[/code][/noparse] tags) - Post any other information that can be helpful for solving the issue (any errors) - Any media that could better display the issue Don't ask for help when it's not your own code, contact the creator instead! [B]Useful sources[/B] [B]Official Garry's Mod Wiki:[/B] [url=http://wiki.garrysmod.com/page/Main_Page]wiki.garrysmod.org[/url] [B]Old Garry's Mod Wiki. Has more examples:[/B] [url=https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4875.html]maurits.tv (long url)[/url] [B]Garry's Mod GitHub (The Lua files of Garry's Mod):[/B] [url=https://github.com/garrynewman/garrysmod]github.com/garrynewman/garrysmod[/url] [B]Previous Threads: [/B] v1: [url]http://facepunch.com/showthread.php?t=1348923[/url] v2: [url]http://facepunch.com/showthread.php?t=1411111[/url] v3: [url]https://facepunch.com/showthread.php?t=1458227[/url] v4: [url]https://facepunch.com/showthread.php?t=1508566[/url]
  • [QUOTE=Netheous;51644229][IMG]http://i.imgur.com/6UbeTwE.png[/IMG][/QUOTE] [img]http://i.imgur.com/q6K03K1.png[/img] He literally just copy+pasted my old thread, but ok.
  • [QUOTE=Author.;51644231][img]http://i.imgur.com/q6K03K1.png[/img] He literally just copy+pasted my old thread, but ok.[/QUOTE] Didn't realize for mega threads that having it be unique was a necessity. Typically they just exist to serve a purpose, and it doesn't matter who created it. If it bothers you that much that I created it before you did, then a mod can just close mine and use yours. I promise I won't lose sleep.
  • I'm trying to create a bomb entity that explodes on contact with the world and props only. I'm currently using ENT:Touch, but world doesn't seem to register. What should I do differently? Edit: Fixed.
  • [CODE]-- watchlist function Initialize() if not file.IsDir( "watchlist", "data" ) then file.CreateDir("watchlist", "data") end end hook.Add( "Initialize", "InitializeWatch", Initialize ) hook.Add( "PlayerSay", "ecksdee", function( ply, text, public ) text = string.lower( text ) -- lowercase local watchlistfile = "watchlist/watchlistfile.txt" if ( text == "/watchlistadd" ) && ply:IsUserGroup( "god" ) or ply:IsUserGroup( "superadmin" ) or ply:IsUserGroup( "senioradmin" ) or ply:IsUserGroup( "admin" ) or ply:IsUserGroup( "moderator" ) then local rulebreaker = (string.sub( text, 15 )) if file.Exists( watchlistfile, "data" ) then file.Append( watchlistfile, rulebreaker ) ply:ChatPrint( "You succsessfully added the rulebreaker to the watchlist" ) else file.Write( watchlistfile, rulebreaker ) ply:ChatPrint( "You succsessfully added the rulebreaker to the watchlist" ) end elseif ( text == "/watchlistread" ) && ply:IsUserGroup( "god" ) or ply:IsUserGroup( "superadmin" ) or ply:IsUserGroup( "senioradmin" ) or ply:IsUserGroup( "admin" ) or ply:IsUserGroup( "moderator" ) then local contents = file.Read( watchlistfile, "data" ) ply:ChatPrint(contents) else ply:ChatPrint( "Insufficient rank to perform this action" ) return "" end end ) [/CODE] The following errors occur with this code. -No matter what you type, it will spurt out 'You succsessfully added the rulebreaker to the watchlist' twice. It only adds data to the file if you type /watchlistadd , however it still spurts it out twice -It's not reading it and putting it in chat, its just spurting out the ''You succsessfully added the rulebreaker to the watchlist' twice again.
  • [QUOTE=Sazzer401;51644409][CODE]-- watchlist function Initialize() if not file.IsDir( "watchlist", "data" ) then file.CreateDir("watchlist", "data") end end hook.Add( "Initialize", "InitializeWatch", Initialize ) hook.Add( "PlayerSay", "ecksdee", function( ply, text, public ) text = string.lower( text ) -- lowercase local watchlistfile = "watchlist/watchlistfile.txt" if ( text == "/watchlistadd" ) && ply:IsUserGroup( "god" ) or ply:IsUserGroup( "superadmin" ) or ply:IsUserGroup( "senioradmin" ) or ply:IsUserGroup( "admin" ) or ply:IsUserGroup( "moderator" ) then local rulebreaker = (string.sub( text, 15 )) if file.Exists( watchlistfile, "data" ) then file.Append( watchlistfile, rulebreaker ) ply:ChatPrint( "You succsessfully added the rulebreaker to the watchlist" ) else file.Write( watchlistfile, rulebreaker ) ply:ChatPrint( "You succsessfully added the rulebreaker to the watchlist" ) end elseif ( text == "/watchlistread" ) && ply:IsUserGroup( "god" ) or ply:IsUserGroup( "superadmin" ) or ply:IsUserGroup( "senioradmin" ) or ply:IsUserGroup( "admin" ) or ply:IsUserGroup( "moderator" ) then local contents = file.Read( watchlistfile, "data" ) ply:ChatPrint(contents) else ply:ChatPrint( "Insufficient rank to perform this action" ) return "" end end ) [/CODE] The following errors occur with this code. -No matter what you type, it will spurt out 'You succsessfully added the rulebreaker to the watchlist' twice. It only adds data to the file if you type /watchlistadd , however it still spurts it out twice -It's not reading it and putting it in chat, its just spurting out the ''You succsessfully added the rulebreaker to the watchlist' twice again.[/QUOTE] Because of the way you wrote your if statements, if checking the text fails it goes to your "or" statements, which pass if you're that user group.
  • Hello all, i need your help if possible [b]Context[/b] : When i connect to my server and look at the emitter no problem, i play etc ... but when i click disconnect button later or i type retry command on the console, my gmod crash instantaneously with no error. [lua] include("shared.lua") AddCSLuaFile() function ENT:Draw() end function ENT:Initialize() self.Emit = ParticleEmitter(self:GetPos()) self:InitializeAsClientEntity() end function ENT:Think() for i = 1, 10 do local part = self.Emit:Add(self.Material, self:GetPos()) if part then part:SetVelocity(Vector(math.random(-180, 180), math.random(-180, 180), 90):GetNormal() * 80) part:SetStartAlpha(100) part:SetEndAlpha(100) part:SetDieTime(15) part:SetLifeTime(0) part:SetStartSize(1) part:SetEndSize(1) part:SetRoll(math.random(0, 360)) part:SetRollDelta(math.random(-10, 10)) part:SetAirResistance( 100 ) part:SetGravity(Vector(0, 0, -10)) end --self.Emit:Finish() -- CRASH end --self.Emit:Finish() -- CRASH Seems to cause a RunTime Error if part then part:SetNextThink(CurTime() + 1) end end function ENT:OnRemove() if self.Emit then self.Emit:Finish() self.Emit = nil end end [/lua] if i comment all code line, no crash but no emitter
  • How do you know that it's the Emitter in particular that is crashing you anyway?
  • Trying to create a panel in the bottom left of the screen with the player's current model as the modelpanel. (zoomed in on their face) I keep trying to fiddle with what I've got here but it doesnt work (sometimes I manage to get it to work but its buggy and stops working when i reload the server) [lua] BGPanel = vgui.Create( "DPanel" ) BGPanel:SetPos( 32, 100 ) BGPanel:SetSize( 200, 200 ) BGPanel:SetBackgroundColor( Color( 0, 0, 0, 255 ) ) local icon = vgui.Create( "DModelPanel", BGPanel ) icon:SetSize( BGPanel:GetSize() ) local pmodel = LocalPlayer():GetModel() icon:SetModel( pmodel ) local eyepos = icon.Entity:GetBonePosition( icon.Entity:LookupBone( "ValveBiped.Bip01_Head1" ) ) eyepos:Add( Vector( 0, 0, 2 ) ) icon:SetLookAt( eyepos ) icon:SetCamPos( eyepos-Vector( -12, 0, 0 ) ) icon.Entity:SetEyeTarget( eyepos-Vector( -12, 0, 0 ) ) [/lua]
  • [QUOTE=Natahster;51646511]Trying to create a panel in the bottom left of the screen with the player's current model as the modelpanel. (zoomed in on their face) I keep trying to fiddle with what I've got here but it doesnt work (sometimes I manage to get it to work but its buggy and stops working when i reload the server) [lua] BGPanel = vgui.Create( "DPanel" ) BGPanel:SetPos( 32, 100 ) BGPanel:SetSize( 200, 200 ) BGPanel:SetBackgroundColor( Color( 0, 0, 0, 255 ) ) local icon = vgui.Create( "DModelPanel", BGPanel ) icon:SetSize( BGPanel:GetSize() ) local pmodel = LocalPlayer():GetModel() icon:SetModel( pmodel ) local eyepos = icon.Entity:GetBonePosition( icon.Entity:LookupBone( "ValveBiped.Bip01_Head1" ) ) eyepos:Add( Vector( 0, 0, 2 ) ) icon:SetLookAt( eyepos ) icon:SetCamPos( eyepos-Vector( -12, 0, 0 ) ) icon.Entity:SetEyeTarget( eyepos-Vector( -12, 0, 0 ) ) [/lua][/QUOTE] Try and load it in the InitPostEntity hook.
  • [QUOTE=Promptitude;51647004]Try and load it in the InitPostEntity hook.[/QUOTE] Thanks man that ended up working. Any clue on how to make it so the icon updates with the player's color and its set to that? Right now its just the default color of the model I'm giving it
  • Any way going about changing fogstart/fogend/farz settings per client? Seems as if the env_fog_controller is only available via the server.
  • [QUOTE=Mrkrabz;51647855]Any way going about changing fogstart/fogend/farz settings per client? Seems as if the env_fog_controller is only available via the server.[/QUOTE] there is [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/CalcView]GM:CalcView[/url], but it's kind of weird how you are supposed to use it.
  • [url]http://wiki.garrysmod.com/page/GM/SetupWorldFog[/url] [url]http://wiki.garrysmod.com/page/GM/SetupSkyboxFog[/url] And render.*Fog* functions.
  • I take it FogZ is different to FarZ? Seems to just change the fog distance rather than the actual clipping distance (FarZ). Fog distance/colour etc are working with that however.
  • Hi, I am looking for a function that is being called when mapchange is triggered, so I can save all stats and things for players. Like GM:PlayerDisconnected, but with mapchange.
  • [QUOTE=papi;51648323]Hi, I am looking for a function that is being called when mapchange is triggered, so I can save all stats and things for players. Like GM:PlayerDisconnected, but with mapchange.[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ShutDown]GM:ShutDown[/url]
  • [QUOTE=sannys;51648331][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ShutDown]GM:ShutDown[/url][/QUOTE] Thank you very much!!
  • [QUOTE=papi;51648336]Thank you very much!![/QUOTE] Careful though, as I'm not sure if it's called on server crash.
  • [QUOTE=Promptitude;51648367]Careful though, as I'm not sure if it's called on server crash.[/QUOTE] As the server crashes, the lua instance crashes too, therefore that will NEVER be called on a server crash. Thats why i would recommend (if you're using this to save data), put a timer or something that will save the data each like, 5 minutes or so in the server
  • [QUOTE=geferon;51648398]As the server crashes, the lua instance crashes too, therefore that will NEVER be called on a server crash. Thats why i would recommend (if you're using this to save data), put a timer or something that will save the data each like, 5 minutes or so in the server[/QUOTE] Thank you, timer is in place, I just keep changing the map while testing, and it occurred to me that that is something that was not addressed yet :)
  • You might be saving via sql right? Just weite plain files in data every x minutes, when shutdown runs, perform the savings and then delete all files When game boots, verify if those files exists and then perform saving if those exists and delete them That fixes cases where server crashes
  • Hi guys, I need to resize an image (in function of the USER screen) but resizing an image cause some pretty weird result, I know it's a common problem but do you know how to fix that ? [QUOTE][IMG]http://puu.sh/thwCO/3160ce2941.jpg[/IMG][/QUOTE]
  • [QUOTE=gonzalolog;51649003]You might be saving via sql right? Just weite plain files in data every x minutes, when shutdown runs, perform the savings and then delete all files When game boots, verify if those files exists and then perform saving if those exists and delete them That fixes cases where server crashes[/QUOTE] That is a good idea, thank you very much! Will consider this option as well. I am saving stuff every 10 seconds into database, so the maximum rollback is 10 seconds.
  • [QUOTE=guigui30110;51649016]Hi guys, I need to resize an image (in function of the USER screen) but resizing an image cause some pretty weird result, I know it's a common problem but do you know how to fix that ?[/QUOTE] could you post the code?
  • [QUOTE=MPan1;51650530]could you post the code?[/QUOTE] [CODE] -- CODE local img_charac = vgui.Create( "DImage", PersoPANEL ) img_charac:SetTall((1/1.5)*ScrH()) img_charac:SetWide((1/1.5)*ScrH()/1080*987) --Weird values is to trying to conserve the ratio of the image -- MORE CODE [/CODE] the original image is like that : [url]http://puu.sh/thVxH/4b639fc275.png[/url]