Problems That Don't Need Their Own Thread v5

https://u.nya.is/sldwzj.png

Welcome to Problems That Don’t Need Their Own Thread v5!

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!

How to go about posting your issue

  • 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]

...

[/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!

Useful sources

Official Garry’s Mod Wiki: wiki.garrysmod.org
Old Garry’s Mod Wiki. Has more examples: maurits.tv (long url)
Garry’s Mod GitHub (The Lua files of Garry’s Mod): github.com/garrynewman/garrysmod

**Previous Threads: **
v1: http://forum.facepunch.com/showthread.php?t=1348923
v2: http://forum.facepunch.com/showthread.php?t=1411111
v3: http://forum.facepunch.com/showthread.php?t=1458227
v4: http://forum.facepunch.com/showthread.php?t=1508566

He literally just copy+pasted my old thread, but ok.

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.


-- 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 )



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.

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

Context : 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?

Because when i remove this code, no crash but no emitter :frowning:

Which one will take off? Hm…

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]

Try and load it in the InitPostEntity hook.

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.

there is

GM:CalcView, but it’s kind of weird how you are supposed to use it.

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.

GM:ShutDown