1. Post #401
    samm5506's Avatar
    July 2008
    637 Posts
    Making a slapping weapon from the watch weapon I made for Elevator: Source, then this happened..

    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 28Winner Winner x 1 (list)

  2. Post #402
    PROUD BRONY 4LYFE
    Drakehawke's Avatar
    February 2009
    3,312 Posts
    because you can use prepared statements and if one of the modules breaks (and never gets updated, such as tmysql which hasn't been updated since July for Linux) I can just change a single line and none of my code will break

    Edited:



    this

    and ~~ prepared statements ~~
    They aren't true prepared statements though
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  3. Post #403
    Dennab
    October 2012
    323 Posts
    Seven Swords stuffs

    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Winner Winner x 14Artistic Artistic x 8Lua King Lua King x 1 (list)

  4. Post #404
    werewolf0020's Avatar
    October 2009
    5,667 Posts
    that is some fucking sexy stuff
    Reply With Quote Edit / Delete Windows 8 Venezuela Show Events Friendly Friendly x 2Agree Agree x 2 (list)

  5. Post #405
    Gold Banana
    Banana Lord.'s Avatar
    May 2010
    6,531 Posts
    They aren't true prepared statements though
    it serves its purpose though
    Reply With Quote Edit / Delete Windows 8 United States Show Events Agree Agree x 2 (list)

  6. Post #406
    Nazuu's Avatar
    June 2009
    17 Posts
    Finally, a realistic kick that does not explode the enemy.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events Agree Agree x 6Funny Funny x 3 (list)

  7. Post #407
    LITTLE PREB FAGGOT
    ollie's Avatar
    January 2012
    890 Posts


    GM13 MySQL TTT Pointshop with weapons and roles.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events Optimistic Optimistic x 1Winner Winner x 1Dumb Dumb x 1Funny Funny x 1 (list)

  8. Post #408
    foxcock
    Bletotum's Avatar
    June 2008
    6,873 Posts
    That looks fantastic. I assume you've made it easy for yourself to put it on either side of the screen? (My visual opinion is that it would look better on the left.)
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  9. Post #409
    garry's Avatar
    September 2001
    12,368 Posts
    Optimised the internals of the userdata system, FPS in a timedemo went from 127 to 140, which isn't that significant but the demo wasn't very heavy Lua-wise - so I'm guessing it will scale a lot.

    I moved the timer function to engine code. Nothing changed - still completely compatible. This should please everyone that was moaning about timers taking down their whole gamemode. They act like they did with pcall now - and get removed when they error (and when they error they tell you the timer name and where it was created/adjusted).

    Hook next - I expect to see a hefty performance boost from that.
    Reply With Quote Edit / Delete Windows 7 Show Events Winner Winner x 33Lua Helper Lua Helper x 2Artistic Artistic x 1Dumb Dumb x 1 (list)

  10. Post #410
    Get your own DarkRP Server!
    FPtje's Avatar
    January 2006
    5,591 Posts
    Optimised the internals of the userdata system, FPS in a timedemo went from 127 to 140, which isn't that significant but the demo wasn't very heavy Lua-wise - so I'm guessing it will scale a lot.

    I moved the timer function to engine code. Nothing changed - still completely compatible. This should please everyone that was moaning about timers taking down their whole gamemode. They act like they did with pcall now - and get removed when they error (and when they error they tell you the timer name and where it was created/adjusted).

    Hook next - I expect to see a hefty performance boost from that.
    Haha, great job, thanks. I knew you'd fix it eventually!
    You're right, this seems to be the better option.
    Reply With Quote Edit / Delete Windows 8 Netherlands Show Events Funny Funny x 1 (list)

  11. Post #411
    LITTLE PREB FAGGOT
    ollie's Avatar
    January 2012
    890 Posts
    That looks fantastic. I assume you've made it easy for yourself to put it on either side of the screen? (My visual opinion is that it would look better on the left.)
    Thanks. :)
    It was actually a lua job, i made it for Q4-Bi's TTT server. I just tried it on the right side of the screen and I think it fitted nicely.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  12. Post #412
    Dragon Dildoes
    Dennab
    April 2009
    4,432 Posts
    Optimised the internals of the userdata system, FPS in a timedemo went from 127 to 140, which isn't that significant but the demo wasn't very heavy Lua-wise - so I'm guessing it will scale a lot.

    I moved the timer function to engine code. Nothing changed - still completely compatible. This should please everyone that was moaning about timers taking down their whole gamemode. They act like they did with pcall now - and get removed when they error (and when they error they tell you the timer name and where it was created/adjusted).

    Hook next - I expect to see a hefty performance boost from that.
    Might aswell introduce them in a OO way?

    Like, use the current system, add the oo system, and after a while, remove the old system.

    Edited:

    Also nice to see that you pay attention to performance after all!
    Reply With Quote Edit / Delete Windows 7 Germany Show Events Agree Agree x 1 (list)

  13. Post #413
    King of the Oil Refinery
    Tobba's Avatar
    December 2008
    6,212 Posts
    Oh dear
    If hook gets moved to C++ I'm gonna have to do something rediclously hacky, oh well

    Edited:

    But yes, it should be a lot faster, so go for it
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Informative Informative x 1Funny Funny x 1Dumb Dumb x 1 (list)

  14. Post #414
    I hide under your bed
    Dennab
    July 2011
    1,877 Posts
    Because i'm such a motherfucking boss i went and remade the default flashlight in Lua.





    Pros:

    - All done in Lua, using an env_projectedtexture.
    - Customizable color, length, radius, flashlight texture, shadow settings.

    Cons:

    - It's all fucking serverside because ents.Create doesn't exist on the client anymore.
    - IT'S ALL FUCKING SERVERSIDE. I dunno what the performance hit of 20 projected textures all being used at once would be but i'd hazard a guess that it will shit all over your FPS.

    If possible it would be nice to be able to create these on the client. Why did ents.Create get removed from clientside anyhow?
    Reply With Quote Edit / Delete Windows XP Canada Show Events Winner Winner x 6Funny Funny x 2Lua King Lua King x 1 (list)

  15. Post #415
    garry's Avatar
    September 2001
    12,368 Posts
    Was annoying me, so I added the ability to force texture filtering. I enabled it by default between 3d2d camera calls, but will add a binding so it can be done at will (including when rendering html).









    Reply With Quote Edit / Delete Windows 7 Show Events Winner x 34Friendly x 2Lua King x 2Optimistic x 1Lua Helper x 1Late x 1Dumb x 1 (list)

  16. Post #416
    PENISCORP DIRECTOR
    Gran PC's Avatar
    August 2007
    3,110 Posts
    If you set the owner of the projected texture to the player it will use cheap shadows unless LocalPlayer() == owner (cheap shadows means no shadows).
    Reply With Quote Edit / Delete Windows 7 Spain Show Events Winner Winner x 1Informative Informative x 1 (list)

  17. Post #417
    I hide under your bed
    Dennab
    July 2011
    1,877 Posts
    If you set the owner of the projected texture to the player it will use cheap shadows unless LocalPlayer() == owner (cheap shadows means no shadows).
    I've disabled dynamic shadows on this flashlight using keyvalues because they make my gamemode unfair. Dynamic shadows are the reason i've had to go and replace the default flashlight altogether. I made a request thread for a function that lets us disable these shadows on a per-entity basis but no dice.



    You can see here that it's really easy to spot something invisible that casts shadows if you use the default flashlight. So far this custom flashlight is the only way i've managed to make those shadows disappear.
    Reply With Quote Edit / Delete Windows XP Canada Show Events Friendly Friendly x 1Agree Agree x 1 (list)

  18. Post #418
    PENISCORP DIRECTOR
    Gran PC's Avatar
    August 2007
    3,110 Posts
    20 projected textures with no shadows should be ok I suppose.
    Reply With Quote Edit / Delete Windows 7 Spain Show Events Informative Informative x 1 (list)

  19. Post #419
    CapsAdmin's Avatar
    August 2005
    3,934 Posts
    Optimised the internals of the userdata system
    Can you explain this? I'm curious.

    I've experimented a lot with userdata implementations and ended up using light userdata as a key and a table instead of full userdata.

    pseduo code:

    function Push(pointer, meta)	
    	REGISTRY[pointer] = REGISTRY[pointer] or setmetatable({__ptr = pointer}, meta)
    end
    
    function Get(pos)
    	local obj = STACK[pos]
    	
    	return cast(obj.__ptr)
    end
    

    This means when you push entities to lua it won't create any new userdata if it has already been pushed once. It will just reuse.

    When I'm done with the entity I just remove the table from the registry and set its metatable to a NULL one.
    Reply With Quote Edit / Delete Windows 7 Norway Show Events

  20. Post #420
    garry's Avatar
    September 2001
    12,368 Posts
    Can you explain this? I'm curious.

    I've experimented a lot with userdata implementations and ended up using light userdata as a key and a table instead of full userdata.

    pseduo code:

    function Push(pointer, meta)	
    	REGISTRY[pointer] = REGISTRY[pointer] or setmetatable({__ptr = pointer}, meta)
    end
    
    function Get(pos)
    	local obj = STACK[pos]
    	
    	return cast(obj.__ptr)
    end
    

    This means when you push entities to lua it won't create any new userdata if it has already been pushed once. It will just reuse.

    When I'm done with the entity I just remove the table from the registry and set its metatable to a NULL one.
    Yeah the entity system already does that.

    The issue I had was that when I was pushing userdata I was allocating and pushing a pointer.. so when it came to look up the type I was pushing the meta table and getting the typeid which was stored on it.

    So instead of doing that stupid shit I store a generic struct as the userdata, which has the typeid and a data pointer.

    This is a bit of a speed up because pretty much every call to an entity, or vector, or whatever, looks at the type.. so instead of pushing a table, looking up a member blah blah blah. It just converts the userdata and looks at the type id.
    Reply With Quote Edit / Delete Windows 7 Show Events Informative Informative x 8 (list)

  21. Post #421
    diaoyudao shi ZHONGGUO de
    Disseminate's Avatar
    December 2007
    4,040 Posts
    flashlight
    How'd you get it to maintain the player's angles? I tried using a projectedtexture in my gamemode but when I set the player to be the parent not only is it laggy, but it just faces Angle(0, 0, 0) for everyone not in first person.

    ie. if I'm looking at another player's flashlight, it faces 0 0 0. If I'm looking at my own flashlight from 3rd person, it faces 0 0 0. If I'm looking at my own flashlight from 1st person, it's correct, if laggy.

    A clientside alternative would be the shit.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Agree Agree x 4 (list)

  22. Post #422
    I hide under your bed
    Dennab
    July 2011
    1,877 Posts
    function meta:LuaFlashlight( on )
    
    	if on then
    	
    		local c = Color( 255, 255, 200 ) 
    		local b = 4 // brightness
    		local size = 50
    		
    		if self:GetLoadout( 3 ) == UTIL_LIGHT then
    		
    			b = 6
    			size = 55
    		
    		end
    		
    		self.FlashlightEnt = ents.Create( "env_projectedtexture" )
    		self.FlashlightEnt:SetParent( self )
    		self.FlashlightEnt:SetLocalPos( Vector(0,0,64) )
    		self.FlashlightEnt:SetLocalAngles( Angle(0,0,0) )
    		self.FlashlightEnt:SetKeyValue( "enableshadows", 0 )
    		self.FlashlightEnt:SetKeyValue( "farz", 512 ) // distance of light
    		self.FlashlightEnt:SetKeyValue( "nearz", 12 ) //12
    		self.FlashlightEnt:SetKeyValue( "lightfov", size ) // size of light
    		
    		self.FlashlightEnt:SetKeyValue( "lightcolor", Format( "%i %i %i 255", c.r * b, c.g * b, c.b * b ) )
    		self.FlashlightEnt:Spawn()
    		self.FlashlightEnt:Input( "SpotlightTexture", NULL, NULL, "effects/Flashlight001.vmt" )
    		
    		self:EmitSound( "items/flashlight1.wav", 50, 110 )
    		
    	else
    	
    		if IsValid( self.FlashlightEnt ) then
    		
    			self.FlashlightEnt:Remove()
    			
    			self:EmitSound( "items/flashlight1.wav", 50, 90 )
    		
    		end
    	
    	end
    
    end
    Reply With Quote Edit / Delete Windows XP Canada Show Events Friendly Friendly x 6Useful Useful x 1Winner Winner x 1Lua King Lua King x 1 (list)

  23. Post #423
    Gold Member
    MDave's Avatar
    April 2010
    631 Posts
    Was annoying me, so I added the ability to force texture filtering.


    Wow, just wow. I literally jumped out of my chair when I saw this!
    Reply With Quote Edit / Delete Windows 7 Hungary Show Events Agree Agree x 5Funny Funny x 1Informative Informative x 1 (list)

  24. Post #424
    Gold Member
    find me's Avatar
    May 2008
    931 Posts
    Because i'm such a motherfucking boss i went and remade the default flashlight in Lua.





    Pros:

    - All done in Lua, using an env_projectedtexture.
    - Customizable color, length, radius, flashlight texture, shadow settings.

    Cons:

    - It's all fucking serverside because ents.Create doesn't exist on the client anymore.
    - IT'S ALL FUCKING SERVERSIDE. I dunno what the performance hit of 20 projected textures all being used at once would be but i'd hazard a guess that it will shit all over your FPS.

    If possible it would be nice to be able to create these on the client. Why did ents.Create get removed from clientside anyhow?
    Maybe instead of an fps expensive flashlight, just make the flashlight twitch and burn out when you get within a certain distance from the invisible dude. That would make things way more scary.
    Or even when they flash the light on the invisible dude, then you could have it burn out so they get to see him for a second then he is gone and that player loses his light.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Winner Winner x 12Funny Funny x 2Agree Agree x 1Zing Zing x 1 (list)

  25. Post #425
    RP-01's Avatar
    December 2008
    84 Posts
    How'd you get it to maintain the player's angles? I tried using a projectedtexture in my gamemode but when I set the player to be the parent not only is it laggy, but it just faces Angle(0, 0, 0) for everyone not in first person.

    ie. if I'm looking at another player's flashlight, it faces 0 0 0. If I'm looking at my own flashlight from 3rd person, it faces 0 0 0. If I'm looking at my own flashlight from 1st person, it's correct, if laggy.

    A clientside alternative would be the shit.
    How about you're using the players EyeAngles() to determine the correct angle for the env_projectedtexture-entity?
    Reply With Quote Edit / Delete Windows 7 Germany Show Events Late Late x 1 (list)

  26. Post #426
    I hide under your bed
    Dennab
    July 2011
    1,877 Posts
    Maybe instead of an fps expensive flashlight, just make the flashlight twitch and burn out when you get within a certain distance from the invisible dude. That would make things way more scary.
    Or even when they flash the light on the invisible dude, then you could have it burn out so they get to see him for a second then he is gone and that player loses his light.
    Currently your flashlight runs on battery power, so you can't keep it on forever. The problem is, with 20+ players there will be times where every player has their flashlight on. In this case, it would be smarter to just have clientside flashlights.

    But i am at the mercy of what garry decides to do with gmod lua so if he decides to allow certain ents to be spawnable clientside then i'm making this code clientside.
    Reply With Quote Edit / Delete Windows XP Canada Show Events

  27. Post #427
    Gold Member
    Divran's Avatar
    April 2008
    2,624 Posts
    gb-radial converted to gmod 13:
    https://dl.dropbox.com/u/15312597/lu...0gmod%2013.zip
    I take no credit for this mod. I only updated it to gmod 13.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Useful Useful x 2Informative Informative x 1 (list)

  28. Post #428
    taste the salty dong
    Remscar's Avatar
    September 2009
    1,822 Posts
    function meta:LuaFlashlight( on )
    
    	if on then
    	
    		local c = Color( 255, 255, 200 ) 
    		local b = 4 // brightness
    		local size = 50
    		
    		if self:GetLoadout( 3 ) == UTIL_LIGHT then
    		
    			b = 6
    			size = 55
    		
    		end
    		
    		self.FlashlightEnt = ents.Create( "env_projectedtexture" )
    		self.FlashlightEnt:SetParent( self )
    		self.FlashlightEnt:SetLocalPos( Vector(0,0,64) )
    		self.FlashlightEnt:SetLocalAngles( Angle(0,0,0) )
    		self.FlashlightEnt:SetKeyValue( "enableshadows", 0 )
    		self.FlashlightEnt:SetKeyValue( "farz", 512 ) // distance of light
    		self.FlashlightEnt:SetKeyValue( "nearz", 12 ) //12
    		self.FlashlightEnt:SetKeyValue( "lightfov", size ) // size of light
    		
    		self.FlashlightEnt:SetKeyValue( "lightcolor", Format( "%i %i %i 255", c.r * b, c.g * b, c.b * b ) )
    		self.FlashlightEnt:Spawn()
    		self.FlashlightEnt:Input( "SpotlightTexture", NULL, NULL, "effects/Flashlight001.vmt" )
    		
    		self:EmitSound( "items/flashlight1.wav", 50, 110 )
    		
    	else
    	
    		if IsValid( self.FlashlightEnt ) then
    		
    			self.FlashlightEnt:Remove()
    			
    			self:EmitSound( "items/flashlight1.wav", 50, 90 )
    		
    		end
    	
    	end
    
    end
    Change your avatar and i'll buy you a new title.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 5Funny Funny x 4 (list)

  29. Post #429
    samm5506's Avatar
    July 2008
    637 Posts
    I made a simple library for editing the new skypaint entity, and some spawnmenu options. It's up on workshop now.



    You can grab the code here, go make some cool stuff. I expect to see some audio visualizers in a few days. I left in a FadeTo function which could be abused for cool purposes too.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Lua King x 11Artistic x 6Friendly x 2Optimistic x 1Useful x 1 (list)

  30. Post #430
    Conna is finally become inter-national dick. Conna 애미뒤진 씹새끼^^
    rebel1324's Avatar
    December 2008
    1,735 Posts
    env_projectiletexture is that expensive?
    Reply With Quote Edit / Delete Windows XP Korea, Republic of Show Events Agree Agree x 3Optimistic Optimistic x 1 (list)

  31. Post #431
    foxcock
    Bletotum's Avatar
    June 2008
    6,873 Posts
    twoski, you can create a clientsidemodel instead
    run something on the client to move each player's flashlight clientsidemodel entity infront of their respected players, and use this entity as a basis for the flashlight
    Reply With Quote Edit / Delete Windows 7 United States Show Events Disagree Disagree x 1 (list)

  32. Post #432
    I hide under your bed
    Dennab
    July 2011
    1,877 Posts
    Change your avatar and i'll buy you a new title.
    compromises must be made i suppose

    twoski, you can create a clientsidemodel instead
    run something on the client to move each player's flashlight clientsidemodel entity infront of their respected players, and use this entity as a basis for the flashlight
    how exactly would a clientside prop emit light? they are basically the same as a prop_physics but without a physics mesh. I am asking for the ability to create entities other than physics props on the client.

    env_projectiletexture is that expensive?
    Projected Texture, you mean. But yes, they seem to be... my framerate started dipping when i was messing around with several of them in sandbox (the lamp entity in sandbox uses them).

    I made a simple library for editing the new skypaint entity, and some spawnmenu options. It's up on workshop now.

    This should have been in vanilla gmod tbh.
    Reply With Quote Edit / Delete Windows XP Canada Show Events Agree Agree x 4Funny Funny x 2 (list)

  33. Post #433
    foxcock
    Bletotum's Avatar
    June 2008
    6,873 Posts
    oh, I see
    I thought your issue was having a clientside entity other than using the players themselves

    also I completely missed this post
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1 (list)

  34. Post #434

    February 2009
    466 Posts
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 13Winner Winner x 2Optimistic Optimistic x 1Disagree Disagree x 1 (list)

  35. Post #435
    Map in a box's Avatar
    July 2009
    7,142 Posts
    She's happy so I'm happy
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 7Agree Agree x 1Optimistic Optimistic x 1 (list)

  36. Post #436
    So since GLON was removed, and I don't like JSON, I created my own 'database system' that saves shit to .txt files, reads info from the files and organizes them into ready tables to use.

    This is a major breakthrough for me, because I did this with no proper knowledge on how databases are coded and/or work. It's also slow as shit, but I don't give a fuck.

    It takes 35 seconds to process this:

    stealth_p228=1:2,2:2,3:2,4:2,5:1
    stealth_deagle=1:2,2:2,3:4,4:1,5:1
    stealth_fiveseven=1:3,2:2,3:2,4:4,5:1
    stealth_glock18=1:5,2:2,3:2,4:1
    stealth_usp=1:2,2:1,5:1,4:3,3:2

    into this:

    stealth_p228:
    		up:
    				1:
    						l	=	2
    						n	=	1
    				2:
    						l	=	2
    						n	=	2
    				3:
    						l	=	2
    						n	=	3
    				4:
    						l	=	2
    						n	=	4
    				5:
    						l	=	1
    						n	=	5
    stealth_deagle:
    		up:
    				1:
    						l	=	2
    						n	=	1
    				2:
    						l	=	2
    						n	=	2
    				3:
    						l	=	4
    						n	=	3
    				4:
    						l	=	1
    						n	=	4
    				5:
    						l	=	1
    						n	=	5
    stealth_fiveseven:
    		up:
    				1:
    						l	=	3
    						n	=	1
    				2:
    						l	=	2
    						n	=	2
    				3:
    						l	=	2
    						n	=	3
    				4:
    						l	=	4
    						n	=	4
    				5:
    						l	=	1
    						n	=	5
    stealth_usp:
    		up:
    				1:
    						l	=	2
    						n	=	1
    				2:
    						l	=	1
    						n	=	2
    				3:
    						l	=	1
    						n	=	5
    				4:
    						l	=	3
    						n	=	4
    				5:
    						l	=	2
    						n	=	3
    stealth_glock18:
    		up:
    				1:
    						l	=	5
    						n	=	1
    				2:
    						l	=	2
    						n	=	2
    				3:
    						l	=	2
    						n	=	3
    				4:
    						l	=	1
    						n	=	4
    

    100000 times.

    I did some benchmarks and apparently it takes 7 seconds to read the file 100000 times and 28 seconds to organize the table.

    JSON's output is 562 symbols and mine is 173 symbols, but it only takes JSON 10 seconds to decode all that.

    Edit: Welp, this was an interesting test, and I'll stick to JSON, because I realized that I can do the same with JSON, but much faster.
    Reply With Quote Edit / Delete Windows 7 Lithuania Show Events Funny Funny x 7Friendly Friendly x 1Lua Helper Lua Helper x 1Dumb Dumb x 1 (list)

  37. Post #437
    Gold Member
    Divran's Avatar
    April 2008
    2,624 Posts
    Did you try any of the other glon replacements that people here on facepunch have made? Like von http://www.facepunch.com/showthread.php?t=1194008
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  38. Post #438
    Did you try any of the other glon replacements that people here on facepunch have made? Like von http://www.facepunch.com/showthread.php?t=1194008
    Yeah, but I forgot what it was called. :X
    Thanks for that though.

    On another note, I think I'm gonna use this thing I made to encode on the server, send it to the client, and decode it there in order to network less stuff. (726 bytes vs 173)
    Reply With Quote Edit / Delete Windows 7 Lithuania Show Events

  39. Post #439
    I still use this. It's based on garry's keyvaluestotable and tabletokeyvalues:

    function Deserialize(sIn)
    	SRL = nil
    
    	RunString(sIn)
    
    	return SRL
    end
    
    local allowedtypes = {}
    allowedtypes["string"] = true
    allowedtypes["number"] = true
    allowedtypes["table"] = true
    allowedtypes["Vector"] = true
    allowedtypes["Angle"] = true
    allowedtypes["boolean"] = true
    local function MakeTable(tab, done)
    	local str = ""
    	local done = done or {}
    
    	local sequential = table.IsSequential(tab)
    
    	for key, value in pairs(tab) do
    		local keytype = type(key)
    		local valuetype = type(value)
    
    		if allowedtypes[keytype] and allowedtypes[valuetype] then
    			if sequential then
    				key = ""
    			else
    				if keytype == "number" or keytype == "boolean" then 
    					key ="["..tostring(key).."]="
    				else
    					key = "["..string.format("%q", tostring(key)).."]="
    				end
    			end
    
    			if valuetype == "table" and not done[value] then
    				done[value] = true
    				if type(value._serialize) == "function" then
    					str = str..key..value:_serialize()..","
    				else
    					str = str..key.."{"..MakeTable(value, done).."},"
    				end
    			else
    				if valuetype == "string" then 
    					value = string.format("%q", value)
    				elseif valuetype == "Vector" then
    					value = "Vector("..value.x..","..value.y..","..value.z..")"
    				elseif valuetype == "Angle" then
    					value = "Angle("..value.pitch..","..value.yaw..","..value.roll..")"
    				else
    					value = tostring(value)
    				end
    
    				str = str .. key .. value .. ","
    			end
    		end
    	end
    
    	if string.sub(str, -1) == "," then
    		return string.sub(str, 1, #str - 1)
    	else
    		return str
    	end
    end
    
    function Serialize(tIn, bRaw)
    	if bRaw then
    		return "{"..MakeTable(tIn).."}"
    	end
    
    	return "SRL={"..MakeTable(tIn).."}"
    end
    
    Reply With Quote Edit / Delete Windows 7 Show Events

  40. Post #440
    Gold Member
    Delremos's Avatar
    June 2007
    150 Posts
    I just tried making something to parse what you put up for shits and giggles. The file reading really kills me, took me around 23 seconds to read the file 100,000 times.

    Without reading the file though, it only takes around 2 seconds to parse it 100,000 times.

    local input = [[stealth_p228=1:2,2:2,3:2,4:2,5:1stealth_deagle=1:2,2:2,3:4,4:1,5:1
    stealth_fiveseven=1:3,2:2,3:2,4:4,5:1
    stealth_glock18=1:5,2:2,3:2,4:1
    stealth_usp=1:2,2:1,5:1,4:3,3:2]]
    
    
    local function parse( input )
    	local out = {}
    
    
    	for name, data in input:gmatch( "(.-)=([^\n]+)" ) do
    		out[ name ] = {
    			up = {}
    		}
    
    
    		local index = 1
    		for n, l in data:gmatch( "(.-):([^,]+),?" ) do
    			out[ name ][ "up" ][ index ] = {
    				l = l,
    				n = n
    			}
    			index = index + 1
    		end
    	end
    
    
    	return out
    end
    
    
    local starttime = SysTime()
    for i=1, 100000 do
    	parse( input )
    end
    local endtime = SysTime()
    
    
    print( "COMPLETED!", endtime - starttime )
    
    
    print( "Output:" )
    PrintTable( parse( input ) )

    Reply With Quote Edit / Delete Windows 7 Australia Show Events