• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
How does lua garbage collection work? If I have a huge table, and I want to deallocate the memory associated with that. Can I just do: MyTable[ indexThatHasHugeTableValue ] = nil Yes?
Yes.
Is it possible to create a fake player and set its unique id to a custom one you want? I am just trying to make it easier on me to use functions on player that are not on the server. So essentially a fake player entity. I don't want it to spawn just need it to be used in code.
[QUOTE=bran92don;45878151]Is it possible to create a fake player and set its unique id to a custom one you want? I am just trying to make it easier on me to use functions on player that are not on the server. So essentially a fake player entity. I don't want it to spawn just need it to be used in code.[/QUOTE] Not sure if this is what you mean but you could create a generic object with the methods you need. [lua]local FakePlayer = { SteamID = function() return "STEAM_0:1:1233456" end, Nick = function() return "Terry" end, } print(FakePlayer:SteamID())[/lua] You would just need to fill it with all the functions you need. [quote]I am just trying to make it easier on me to use functions on player that are not on the server.[/quote]What functions are you trying to call?
[QUOTE=wh1t3rabbit;45878169]Not sure if this is what you mean but you could create a generic object with the methods you need. [lua]local FakePlayer = { SteamID = function() return "STEAM_0:1:1233456" end, Nick = function() return "Terry" end, } print(FakePlayer:SteamID())[/lua] You would just need to fill it with all the functions you need. What functions are you trying to call?[/QUOTE] I was trying to call some functions that use sql in darkrp. Originally I was just gonna hard code my own functions to just work by entering in a id but then I saw how he did the sql file structure in there for the wallet and decided it just be best to do it with a fake player. So now I am just gonna call player:addMoney() which should only need the uniqiueId I think
Anyone know what I can do to stop this occuring? [t]http://cloud-4.steampowered.com/ugc/541877809705759174/0007C4B019BB071B78AD2F78EFE22BAB4DF9CC64/[/t] Some props are drawing through a cam.Start3D2D(). It's being called in PostDrawOpaqueRenderables, so maybe I need a different hook?
Is there a way of changing the width of a prop, the only function I can find of relevance on the wiki is: [url]http://wiki.garrysmod.com/page/Entity/EnableMatrix[/url] but that's only clientside so hitboxes would be unaffected?
[QUOTE=PaellaPablo;45878996]Some props are drawing through a cam.Start3D2D(). It's being called in PostDrawOpaqueRenderables, so maybe I need a different hook?[/QUOTE] Yeah, use PostDrawTranslucentRenderables instead.
I don't know too much about detouring and shit, but if I detour a function at menu state, then join a server, is my detour still active? Also, when is everything in the autorun/client on the client ran and is it even ran on the client or only if it's a listen server?
I'm pretty sure menu state is totally unrelated to client state, so no, your detour won't be ported.
Does anyone know any good sites or tutorials that can explain net.Recieve / net.Send to me? I have tried mauritis and the gmod wiki with no luck :/
I've seen it done before, but I'm trying to figure out how to re-render the map on the client.
[QUOTE=bluebull107;45885887]Does anyone know any good sites or tutorials that can explain net.Recieve / net.Send to me? I have tried mauritis and the gmod wiki with no luck :/[/QUOTE][URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]http://wiki.garrysmod.com/page/Net_Library_Usage[/URL]
Im so lost here, this used to work and I even checked my old gamemode code and some GM13 tut's but it's all the same. The following doesn't draw to the screen using the surface library. [code] include( 'shared.lua' ) ---Local Vars--- local ply = LocalPlayer() --local HP = LocalPlayer():Health() -- Commented out because this function now returns NULL for some reason. Damnit garry. --local ARM = LocalPlayer():Armor() -- Commented out because this function now returns NULL for some reason. Damnit garry. ---------------- ---Font Creation--- surface.CreateFont( "DFont", { font = "Arial", size = 13, weight = 500, antialias = true, } ) ------------------- ---Remove default HUD--- function GM:HUDShouldDraw(vhud) for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo", })do if vhud == v then return false end end end ------------------------ ---Custom HUD--- hook.Add("HUDPaint", "coolhud", function() surface.SetFont( "Default" ) -- Instead of using my font called DFont I am trying 'default' to see if me CreateFont was the issue. surface.SetTextColor( 255, 255, 255 ) surface.SetTextPos( 400, 400 ) surface.DrawText( "Test text on the screen." ) end) ---------------- [/code] EDIT: Changing [code] hook.Add("HUDPaint", "coolhud", function() [/code] to [code] hook.Add("PostDrawHUD", "coolhud", function() [/code] works but only after gamemode is loaded and the .lua is refreshed. Before the refresh I get this error. [code] [ERROR] gamemodes/varsgroth/gamemode/cl_init.lua:5: Tried to use a NULL entity! 1. Health - [C]:-1 2. unknown - gamemodes/varsgroth/gamemode/cl_init.lua:5 Couldn't Load Init Script: 'varsgroth/gamemode/cl_init.lua' [/code]
That's because you define a variable to LocalPlayer on load of the script while the player entity isn't yet valid.
[QUOTE=ms333;45887601]That's because you define a variable to LocalPlayer on load of the script while the player entity isn't yet valid.[/QUOTE] [code] hook.Add("PostDrawHUD", "coolhud", function() if IsValid(LocalPlayer()) then surface.SetFont( 'DFont' ) surface.SetTextColor( 50, 20, 150 ) surface.SetTextPos( 20, 20 ) surface.DrawText( "HP: "..tostring(LocalPlayer():Health()).." | ARM: "..tostring(LocalPlayer():Armor()) ) end end) [/code] fixes everything
Upon destruction of a city scanner (npc_cscanner), some parts of it are created and thrown about. I've tried setting the spawnflag 512 on spawn which should fade the corpse away (according to this: [URL]https://developer.valvesoftware.com/wiki/Npc_cscanner[/URL]), but it doesn't seem to happen. They aren't entities, so I can't really target them in any way? How would I be able to either remove them or prevent them from spawning?
[QUOTE=ms333;45887949]Corpse Fading[/QUOTE] I also need to know about this, since the fade KV doesn't seem to work half the time on my NPCs.
What would cause "self" to be nil in a custom SWEP function? I have to use Global functions because SWEP one are not working... No lua errors other than that [code] function SWEP:Example() local ply = self.Owner end
[QUOTE=Exho;45889798]What would cause "self" to be nil in a custom SWEP function? I have to use Global functions because SWEP one are not working... No lua errors other than that [code] function SWEP:Example() local ply = self.Owner end[/QUOTE] Well we aint be anything with that part of your code , do you mind uploading your code to pastebin and share the goodness with us , you probably tried to edit a weapon that already had a base settled
[QUOTE=Exho;45889798]What would cause "self" to be nil in a custom SWEP function? I have to use Global functions because SWEP one are not working... No lua errors other than that [code] function SWEP:Example() local ply = self.Owner end[/QUOTE] Example() must be called with ":" if you use a "." self won't be passed. (self:Example() or SWEP:Example() or myWep:Example())
-snip snap snoop-
Why does [url]http://wiki.garrysmod.com/page/Global/MsgC[/url] print twice to console when in [B]function GM:Initialize()[/B] ?
[QUOTE=BlackMadd;45891255]Why does [url]http://wiki.garrysmod.com/page/Global/MsgC[/url] print twice to console when in [B]function GM:Initialize()[/B] ?[/QUOTE] That function is shared. Is the file shared? It'll call once on the client and once on the server.
[QUOTE=Drak_Thing;45891221]Example() must be called with ":" if you use a "." self won't be passed. (self:Example() or SWEP:Example() or myWep:Example())[/QUOTE] Oh so for variables its just "self.Swag" and functions it is "self:ObtainStuff"? I thought it was a period for both
[QUOTE=Exho;45891682]Oh so for variables its just "self.Swag" and functions it is "self:ObtainStuff"? I thought it was a period for both[/QUOTE] No. The colon is a shortcut, the following 2 lines are identical un functionality. [lua]Obj.Method(Obj) Obj:Method()[/lua]
[QUOTE=EvacX;45891706]No. The colon is a shortcut, the following 2 lines are identical un functionality. [lua]Obj.Method(Obj) Obj:Method()[/lua][/QUOTE] what if my function has arguments? can I still do this?
Yes. ":" just passes self as the first argument. [lua] function SWEP:MyFunction( arg1, arg2 ) print(arg1) -- this will equal "test1" print(arg2) -- this will equal "test2" print(self) -- this will be the SWEP table end SWEP:MyFunction( "test1", "test2") [/lua] If you didn't use ":", self will be nil. This is common when "overloading" panel functions [lua] local someVguiElement.Paint = function( self, w, h ) end [/lua] Since we use the period operator, we have to include "self" ourselves. But you can still call: "someVguiEelement:Paint( w, h )" and self will get passed
[QUOTE=Drak_Thing;45891748]This is common when "overloading" panel functions [lua] local someVguiElement.Paint = function( self, w, h ) end [/lua][/QUOTE] That's invalid, you can't localize a table entry.
Not to mention that it's not even supposed to be a table Correct way to write that would be [code] local someVguiElement = vgui.Create("SomeVGUIElement") someVguiElement.Paint = function(self, w, h) print("Width is " .. w .. " pixels") end [/code]
Sorry, you need to Log In to post a reply to this thread.