• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
[QUOTE=MPan1;49622381]This is probably a simple question, but how can I hook to a weapon's reload function? I want some code to run whenever any weapon gets reloaded, but not just for SWEPS, for default weapons as well. Is there some kind of way to do this? Also, by 'reload', I mean when the user reloads the ammo of the weapon, not the actual script for the weapon, if any. I probably have to do some sort of dodgy check in a Tick/Think hook, but I thought I may as well ask in case there's a better way.[/QUOTE] Nothing direct. Some digging in the SDK shows, possibly, weapon:GetSaveTable( ).m_bInReload , which would cover all engine weapons and any scripted weapon that uses DefaultReload. As with anything, if someone goes out of their way to handle the reload themselves, it wouldn't work. This is from the 2013 sdk so it might not be in gmod.
Was Entity:SetFoward removed? Looking for someway to "push" a entity forward in hammer units. I swear I thought the old way was SetForward(units).. Any?
-snip, posted to wrong thread-
[QUOTE=Jordanlol;49622525]Was Entity:SetFoward removed? Looking for someway to "push" a entity forward in hammer units. I swear I thought the old way was SetForward(units).. Any?[/QUOTE] In the SetupMove hook you can mess with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/CMoveData/SetForwardSpeed]CMoveData:SetForwardSpeed[/url]
Not looking to change ForwardSpeed, I am saying the Entitys Velocity.
[QUOTE=Jordanlol;49622676]Not looking to change ForwardSpeed, I am saying the Entitys Velocity.[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetVelocity]Entity:SetVelocity[/url]? Also, a question from me: These two lines were from weapon_fists.lua: [CODE] local SwingSound = Sound( "WeaponFrag.Throw" ) local HitSound = Sound( "Flesh.ImpactHard" ) [/CODE] Is there a list somewhere with more sounds like those ones? I'm looking for a metal-kind of sound [B]EDIT: [/B][URL="https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexb907.html"]Found it[/URL] [editline]28th January 2016[/editline] Actually, another question: How could I 'bump' the player's viewmodel a bit? I want it to look like a player is thrusting their viewmodel forward into something, but I don't really know how to do that. Should I use the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/CalcViewModelView]GM/CalcViewModelView[/url] hook?
[QUOTE=Jordanlol;49622676]Not looking to change ForwardSpeed, I am saying the Entitys Velocity.[/QUOTE] [code] ent:SetVelocity( ent:GetAngles():Forward() * speed ) [/code]
[QUOTE=Jordanlol;49622676]Not looking to change ForwardSpeed, I am saying the Entitys Velocity.[/QUOTE] Entity:GetVeloticty():Length() ?
i got an entity, and i want it that once it touches someone, it'll register that the owner of the entity has killed the person. using PhysicsCollide, but how do i use it to kill the other player. I am guessing that i might need to use Entity:Fire("kill","",0) but unsure how to use it to register that player A killed player B.
[QUOTE=Kogitsune;49620493][code]listview.VBar:SetScroll( 0 )[/code] Should do the trick.[/QUOTE] Jep, thank you!
I am so confused, does GM:CreateClientsideRagdoll and GM:CreateEntityRagdoll not work at all for players? I am using Player:CreateRagdoll on GM:DoPlayerDeath, I'm trying to manipulate bones on that ragdoll, but even after trying the hooks above, and even sending the ragdoll over the network, I can't get the client to recognize that a ragdoll was created. I tried setting the ragdoll to client sided by calling Entity:SetShouldServerRagdoll with false as well. Why can't I get this to work?
I have a problem thats getting on my nerves. I have this piece of code: [CODE]cvars.AddChangeCallback( "stealth_music", function( convar_name, value_old, value_new ) if (value_new == 0 and alertmusic:IsPlaying()) then alertmusic:Stop() print("stopping music") end print(value_new) print(alertmusic:IsPlaying()) end)[/CODE] The problem is that it ignores the IF block. Even tho it prints "0 true" in console, it wont stop the music, nor it prints the message. I don't know whats wrong with it.
[QUOTE=MaxShadow;49626210]I have a problem thats getting on my nerves. I have this piece of code: [CODE]cvars.AddChangeCallback( "stealth_music", function( convar_name, value_old, value_new ) if (value_new == 0 and alertmusic:IsPlaying()) then alertmusic:Stop() print("stopping music") end print(value_new) print(alertmusic:IsPlaying()) end)[/CODE] The problem is that it ignores the IF block. Even tho it prints "0 true" in console, it wont stop the music, nor it prints the message. I don't know whats wrong with it.[/QUOTE] The values are given as strings. 0 is not equal to "0".
Oh, I didn't know they were given as strings. Thanks man, I'll keep that in mind the next time something refuses to work for no apparent reason.
[QUOTE=MaxShadow;49626313]Oh, I didn't know they were given as strings. Thanks man, I'll keep that in mind the next time something refuses to work for no apparent reason.[/QUOTE] Next time consult the wiki before posting: [url]http://wiki.garrysmod.com/page/cvars/AddChangeCallback[/url] It states there that the arguments are strings.
I'm trying to make a DTextEntry into a search bar -- when hitting enter any panel entry without the text parented to it will be removed. Ignore the scaleX and scaleH functions, those are what I use to scale derma properly. [code] DermaPanel = vgui.Create("DFrame") DermaPanel:SetSize(scaleX(1300), scaleH(750)) DermaPanel:SetVisible(true) DermaPanel:Center() DermaPanel:SetTitle("") DermaPanel:ShowCloseButton(false) DermaPanel:MakePopup() DermaPanel.Paint = function() draw.RoundedBox(0, 0, 0, DermaPanel:GetWide(), DermaPanel:GetTall(), Color(240, 240, 240, 255)) draw.RoundedBox(0, 0, 0, DermaPanel:GetWide(), scaleH(30), Color(41, 128, 185, 255)) end local DComboBox = vgui.Create( "DComboBox", DermaPanel ) DComboBox:SetPos( scaleX(657), scaleH(40) ) DComboBox:SetSize( scaleX(1300 / 2 - 30), 25 ) DComboBox:SetValue( "Brand" ) DComboBox:AddChoice( "A" ) DComboBox:AddChoice( "B" ) DComboBox:AddChoice( "C" ) DComboBox.OnSelect = function( panel, index, value ) print( value .." was selected!" ) end local Carzz = vgui.Create("DScrollPanel", DermaPanel) Carzz:Dock( FILL ) Carzz:DockMargin( 17, 50, 0, 0 ) Carzz:SetSize( DermaPanel:GetWide(), DermaPanel:GetTall() - ScreenScale(16)) local num = 0 local ShopItemss = vgui.Create( "DIconLayout", Carzz ) ShopItemss:SetSize( Carzz:GetWide(), Carzz:GetTall() ) ShopItemss:SetPos( 2, 2 ) ShopItemss:SetSpaceY( scaleH(10) ) ShopItemss:SetSpaceX( scaleX(10) ) for i=1, 6 do num = num + 1 local BackgroundThing = ShopItemss:Add( "DPanel" ) BackgroundThing:SetSize(411, 130) BackgroundThing.Paint = function() draw.RoundedBoxEx( 0, 0, 0, BackgroundThing:GetWide(), BackgroundThing:GetTall(), Color(10, 10, 10, 100) , true, true, true, true) end ShopItemss[num] = BackgroundThing Text = vgui.Create( "DPanel", BackgroundThing ) Text:SetSize(100, 100) Text:SetDisabled(true) Text.Paint = function() draw.SimpleText(i, "CloseCaption_Bold", scaleX(50), scaleH(90), Color(0, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) end end local TextEntry = vgui.Create( "DTextEntry", DermaPanel ) -- create the form as a child of frame TextEntry:SetPos( 25, 40 ) TextEntry:SetSize( 1300 / 2 - 30, 25 ) TextEntry:SetText( "Search" ) TextEntry.OnEnter = function( self ) for k, v in pairs(ShopItemss) do end end [/code] Current results (which makes sense, but I'm a bit confused): [code] bad argument #1 to 'pairs' (table expected, got userdata) [/code] I can't seem to loop the item text for checking the value of the TextEntry with string.find. Anyone have any ideas?
you're trying to loop through a panel, store the backgroundthings in a separate table and loop through that
[QUOTE=PortalGod;49629058]you're trying to loop through a panel, store the backgroundthings in a separate table and loop through that[/QUOTE] That would make alot of sense, kinda works now although I'm running into one more issue; [code] function PopulateCars() table.Empty(Shit) local Carzz = vgui.Create("DScrollPanel", DermaPanel) Carzz:Dock( FILL ) Carzz:DockMargin( 17, 50, 0, 0 ) Carzz:SetSize( DermaPanel:GetWide(), DermaPanel:GetTall() - ScreenScale(16)) local num = 0 local ShopItemss = vgui.Create( "DIconLayout", Carzz ) ShopItemss:SetSize( Carzz:GetWide(), Carzz:GetTall() ) ShopItemss:SetPos( 2, 2 ) ShopItemss:SetSpaceY( scaleH(10) ) ShopItemss:SetSpaceX( scaleX(10) ) for k, v in pairs(VEHICLE_DATABASE) do num = num + 1 local BackgroundThing = ShopItemss:Add( "DPanel" ) BackgroundThing:SetSize(411, 130) BackgroundThing.Text = v.Name BackgroundThing.Paint = function() draw.RoundedBoxEx( 0, 0, 0, BackgroundThing:GetWide(), BackgroundThing:GetTall(), Color(10, 10, 10, 100) , true, true, true, true) end table.insert(Shit, BackgroundThing) Model = vgui.Create( "DModelPanel", BackgroundThing ) Model:SetSize(scaleX(411), scaleX(130)) Model:Dock(FILL) Model:SetModel(v.Model) Model:SetFOV(50) Model:SetCamPos(Vector(500, 0, 90)) Model:SetLookAt(Vector(0, -5, 70)) Model:SetDirectionalLight(BOX_RIGHT, Color(255, 255, 255, 255)) Model:SetDirectionalLight(BOX_LEFT, Color(255, 255, 255, 255)) Model:SetAmbientLight(Vector(-64, -64, -64)) Model:SetColor(Color(255, 255, 255)) Model:SetMouseInputEnabled(false) Model:AlignLeft(scaleX(15)) Model:AlignTop(scaleH(920)) function Model:LayoutEntity(Entity) return end Text = vgui.Create( "DPanel", BackgroundThing ) Text:SetSize(scaleX(411), scaleH(130)) Text.Paint = function() draw.SimpleTextOutlined( v.Name, "BoardFont4", scaleX(411/2 - 10), scaleH(105), Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(0,0,0,255) ) end end end PopulateCars() local TextEntry = vgui.Create( "DTextEntry", DermaPanel ) -- create the form as a child of frame TextEntry:SetPos( 25, 40 ) TextEntry:SetSize( 1300 / 2 - 30, 25 ) TextEntry:SetText( "Search" ) TextEntry.OnChange = function( self ) for k, v in pairs(Shit) do if TextEntry():GetValue() == "" or TextEntry():GetValue() == nil then PopulateCars() end if !string.find(string.lower(v.Text), string.lower(TextEntry:GetValue())) then v:Remove() end end end [/code] When hitting backspace I get: [code] bad argument #1 to 'lower' (string expected, got nil) [/code] Maybe I'm just dumb, but the textbox shouldn't be nil if there's still text inside it.
[QUOTE=kpjVideo;49629313] When hitting backspace I get: [code] bad argument #1 to 'lower' (string expected, got nil) [/code] Maybe I'm just dumb, but the textbox shouldn't be nil if there's still text inside it.[/QUOTE] Try printing the Shit table and the v table in the loop. Is it just when you are pressing backspace at all, or when the text box is empty and you start pressing backspace? It might just go to nil if it's empty, so use the if statement you have above.
Hey, Is there any tutorial how to use file.Write with png? Im loading url with png, no idea what to do next...
[QUOTE=SteppuFIN;49630944]Hey, Is there any tutorial how to use file.Write with png? Im loading url with png, no idea what to do next...[/QUOTE] ...what? What are you trying to do, and why do you think it requires the use of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/file/Write]file.Write[/url]?
how do i fix low res font?
Is there anyway/hooks to hide all derma windows for a few frames without closing them or drawing over them?
I'm still trying to understand how LUA handles tables. I have a bit of experience with C and Java, but LUA is so simplified, that sometimes it gets confusing. When I do something like this: [CODE]mytable.posvar = self.GetPos()[/CODE] It creates a global table with the name "mytable". But if I do this: [CODE]ent = net.ReadEntity() ent.posvar = ent.GetPos() ent = net.ReadEntity() ent.posvar = ent.GetPos()[/CODE] It creates a global table with the name of the entity, each time it reads the entity, and then inserts a field with the key "posvar" and value ent.GetPos(), no? So how it works? It creates tables with literal names unless that name is already asigned to a variable? And suppose I want to get my new created tables from the enviroment (_G), how is it named? "ent" stores an entity... Does it convert the entire entity into a string and then assigns that string to the table name? What happens if I do this: [CODE]mytable.testvar = self.GetPos() mytable = 10[/CODE]
You can't just assign a property to a nil, you have to initialize the var before, as table if do you want to index it [lua] mytable = {} mytable.pos = Vector(1,1,1) MsgN(mytable.pos) //Will print Vector(1,1,1) mytable.pos.tar = 0 //Will print an error about indexing a non table mytable.pos = {} mytable.pos.tar = 0 MsgN(mytable.pos.tar) //Will print 0 mytable = 3 MsgN(mytable.pos) //Will print 3 [/lua]
[QUOTE=roastchicken;49631599]...what? What are you trying to do, and why do you think it requires the use of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/file/Write]file.Write[/url]?[/QUOTE] Let me put it this way, i want to "download" image from internet to data folder. How would i achieve that? I fetch the page, but i dont know what to do with the result so it would be in data folder. Don't ask why do i need this :v:.
[QUOTE=SteppuFIN;49632375]Let me put it this way, i want to "download" image from internet to data folder. How would i achieve that? I fetch the page, but i dont know what to do with the result so it would be in data folder. Don't ask why do i need this :v:.[/QUOTE] I've never done this before but you can use: [url]https://wiki.garrysmod.com/page/util/Base64Encode[/url] On the http request and file.Write it to a file. Then, on a HTML panel you can use: [url]https://en.m.wikipedia.org/wiki/Data_URI_scheme[/url] On the image's src.
It seems im doing it right, but for some reason the file doesnt get created, debugging then the whole code, thanks!
How do I remove an entity from another function? for example if I have an entity on function 1 and I want to remove said entity using function 2
[QUOTE=keeperman;49633003]How do I remove an entity from another function? for example if I have an entity on function 1 and I want to remove said entity using function 2[/QUOTE] Using function arguments. Example: [CODE]function test1() local ent = someentity test2(ent) end function test2(entity) entity:Remove() end[/CODE]
Sorry, you need to Log In to post a reply to this thread.