• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=bobbleheadbob;47168819][lua] local hasjumped = false hook.Add("CreateMove","swag",function(ply,cmd) if cmd:KeyDown(IN_JUMP) and ply:OnGround() then if not hasjumped then --do shit hasjumped = true end else //when the player lets go of the space bar hasjumped = false end end) [/lua][/QUOTE] Ah thank you, I had to make changes because it would still trigger if you land [code] if cmd:KeyDown(IN_JUMP) and ply:OnGround() then if not JumpLatch then print("faggot") JumpLatch = true end elseif not cmd:KeyDown(IN_JUMP) then JumpLatch = false end [/code] Thank you
[psyduck] There is far too much math going on in this thread. Either way, nice job, all! I'm out of ideas for my arrow. Need more.
@ROFLBURGER, you should be handling this in a shared environment. Here's a predicted example. The only reason you needed your hasjumped boolean check for the jump itself is because of improper use of predicted functions. You'll still need something similar for landings though (a networked boolean). [code] local META = FindMetaTable "Player" function META:GetStamina() return self:GetDTFloat( 12 ) -- Come the next update, NWVars can be used rather than a seemingly 'random' index end function META:SetStamina( stamina ) self:SetDTFloat( 12, stamina ) end hook.Add( "StartCommand", "", function( ply, cmd ) if cmd:KeyDown( IN_JUMP ) and ply:OnGround() then if ply:GetStamina() < 20 then cmd:RemoveKey( IN_JUMP ) -- Player can't jump with less than 20 stamina else ply:SetStamina( math.max( 0, ply:GetStamina() - 20 ) ) -- Decrement by 20 stamina per jump end end end ) hook.Add( "PlayerTick", "", function( ply ) ply:SetStamina( math.min( 100, ply:GetStamina() + FrameTime() * 5 ) ) -- Increment by 5 stamina per second print( ply:GetStamina() ) end ) [/code] Maybe limit SetStamina calling so it only runs when necessary.
Bobboblehead, you the man. [t]http://cloud-4.steamusercontent.com/ugc/529508221222659821/9410F1647AA79ED5B07A07D12EB3C7C7786E3EA7/1024x576.resizedimage[/t] I did a basic particle effect to show where the bullet's travelling. I did some slight code modification and I'll be organizing my code a bit differently, but it totally works. This is with a distance of 512 units.
[QUOTE=wauterboi;47169383]Bobboblehead, you the man. [t]http://cloud-4.steamusercontent.com/ugc/529508221222659821/9410F1647AA79ED5B07A07D12EB3C7C7786E3EA7/1024x576.resizedimage[/t] I did a basic particle effect to show where the bullet's travelling. I did some slight code modification and I'll be organizing my code a bit differently, but it totally works. This is with a distance of 512 units.[/QUOTE] That looks like that bullet is either extremely slow, or very heavy... or gravity is through the roof. Assuming the white glows with green dots in them are the particle effect. [editline]19th February 2015[/editline] Perhaps a noob question, but what map is that?
[QUOTE=WalkingZombie;47169594]That looks like that bullet is either extremely slow, or very heavy... or gravity is through the roof. Assuming the white glows with green dots in them are the particle effect. [editline]19th February 2015[/editline] Perhaps a noob question, but what map is that?[/QUOTE] The velocity slows down to reach where I want it to. 512 units isn't very far from the player. The map is gm_excess_island
The doors are buggy AF in my gamemode. I want to redo the system. Suggestions? table.Insert and such are buggy.
[QUOTE=buu342;47170412]The doors are buggy AF in my gamemode. I want to redo the system. Suggestions? table.Insert and such are buggy.[/QUOTE] table.insert ain't buggy, but apparently your system is. How can we help when we have no idea what your "system" does and is meant to do?
[QUOTE=Willox;47170424]table.insert ain't buggy, but apparently your system is. How can we help when we have no idea what your "system" does and is meant to do?[/QUOTE] I was asking for any alternatives. What I was doing was getting the creator's nick, and then adding it to a table which contained the entity's id. This makes errors with Nick() being a nil value for others though.
[QUOTE=buu342;47170480]I was asking for any alternatives. What I was doing was getting the creator's nick, and then adding it to a table which contained the entity's id. This makes errors with Nick() being a nil value for others though.[/QUOTE] I don't think that's caused by Gmod.. Post your code
[QUOTE=Hoffa1337;47170489]I don't think that's caused by Gmod.. Post your code[/QUOTE] Door entity: [lua] function ENT:Think() if self.SetNW == false then if IsValid(self:GetOwner()) && self:GetOwner():Nick() != nil then self.SetNW = true if !self.OwnersByID[self:EntIndex()] then self.OwnersByID[self:EntIndex()] = {} end //print(self:GetOwner():Nick()) if !table.HasValue(self.OwnersByID[self:EntIndex()], self:GetOwner():Nick()) then table.insert(self.OwnersByID[self:EntIndex()], self:GetOwner():Nick()) end end end end net.Receive( "AddOwner", function( length, client ) ent = net.ReadEntity() ply = net.ReadString() table.insert(ent.OwnersByID[ent:EntIndex()], ply) end ) [/lua] Door Menu Code: [lua] local firep = vgui.Create( "DButton" ) firep:SetPos( padding+6, padding+26 ) firep:SetParent( ps ) firep:SetText( "Set Door Owners" ) firep:SetSize( w - 36, 128 ) firep.DoClick = function() local menu = DermaMenu() menu.found = false for k,v in pairs(player.GetAll()) do if not table.HasValue(trace.Entity.OwnersByID[trace.Entity:EntIndex()], v:Nick()) then menu.found = true menu:AddOption(v:Nick(), function() net.Start( "AddOwner" ) net.WriteEntity( trace.Entity ) net.WriteString( v:Nick() ) net.SendToServer() table.insert(trace.Entity.OwnersByID[trace.Entity:EntIndex()], v:Nick()) end) end end if not menu.found then menu:AddOption("There are no other players available.", function() end) end menu:Open() end [/lua] I think I might just screw using Nick() completely.
I dont know how to get a players name and steam icon on my HUD and also i would like code for the speed you are going at like on BHOP servers and Deathrun servers Thanks im using the Main Deathrun that you get on NitrousGaming. This is a tiny bit of the code( this is where i would like it placed) : [lua] [QUOTE] function draw.AAText( text, font, x, y, color, align ) draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,math.min(color.a,120)), align ) draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,math.min(color.a,50)), align ) draw.SimpleText( text, font, x, y, color, align ) end local clamp = math.Clamp local hx, hw, hh, border = 5, 204, 30, 2 local keys = {} local draw_keys = false function GM:HUDPaint( ) local ply = LocalPlayer() local ob = ply:GetObserverTarget() if ob and IsValid(ob) and ob:IsPlayer() and ob:Alive() then draw.AAText( ob:Nick(), "Deathrun_SmoothBig", ScrW()/2, 5, Color(255,255,255,255), TEXT_ALIGN_CENTER) ply = ob draw_keys = true else draw_keys = false end if not keys[ply] then keys[ply] = {} end local hy = ScrH() - 50 draw.RoundedBox( 0, 100, hy, hw, hh, Color( 44, 44, 44, 175 ) ) draw.RoundedBox( 0, 100 + border, hy + border, hw - border*2, hh - border*2, Color( 180, 80, 80, 255 ) ) local thp = ply:Alive() and ply:Health() or 0 local hp = thp if hp > 0 then hp = ( hw - border*2 ) * ( math.Clamp(ply:Health(),0,100)/100) draw.RoundedBox( 0, hx + border, hy + border, hp, hh - border*2, Color( 80, 180, 60, 255 ) ) end draw.AAText( tostring( thp > 999 and "dafuq" or math.max(thp, 0) ), "Deathrun_SmoothBig", hx + 100, hy - 3, Color(255,255,255,255), TEXT_ALIGN_LEFT ) surface.SetFont( "Deathrun_SmoothBig" ) local rt = string.ToMinutesSeconds(self:GetRoundTime()) local ttw, _ = surface.GetTextSize( rt ) local tw = hw/2 + 5 draw.WordBox( 4, tw - ttw/14, hy - 45, rt, "Deathrun_SmoothBig", Color( 44, 44, 44, 20[T]0 ), Color( 255, 255, 255, 255 ) ) [/QUOTE]
[QUOTE=BeeftBadgerr;47170551]I dont know how to get a players name and steam icon on my HUD and also i would like code for the speed you are going at like on BHOP servers and Deathrun servers Thanks im using the Main Deathrun that you get on NitrousGaming. This is my script so far : [SUB][/QUOTE] For the name, use [url]http://wiki.garrysmod.com/page/Player/Nick[/url]. For the speed, use [url]http://wiki.garrysmod.com/page/Entity/GetVelocity[/url]. And for our sanity, use [lua] and not [sub].
Quick question. If I looped a colour table which was laid out like: [code] r = 188 b = 83 a = 255 g = 83 [/code] When Im looping through it with [code] for k,v in pairs(color) do end [/code] How would I make a value the colors in that table? I tried col = v.r,v.g,v.b and it says 'attempt to index a number value'.
[QUOTE='[CLRP]extra;47170730']Quick question. If I looped a colour table which was laid out like: [code] r = 188 b = 83 a = 255 g = 83 [/code] When Im looping through it with [code] for k,v in pairs(color) do end [/code] How would I make a value the colors in that table? I tried col = v.r,v.g,v.b and it says 'attempt to index a number value'.[/QUOTE] All colors must be created with the color function. [lua] for k, v in pairs(color) do local newCol = Color(color.r,color.g,color.b,color.a) end [/lua]
[QUOTE=Feihc;47170772]All colors must be created with the color function. [lua] for k, v in pairs(color) do local newCol = Color(color.r,color.g,color.b,color.a) end [/lua][/QUOTE] -snip- nevermind. Thanks :)
How can I do UpdateTransmitState for players? I want some players to always be transmitted and others not and I can only see this working for scripted entities.
if I did [code] for k,v in pairs(Gangs) [/code] how would I sort them in order of: v.members?
[QUOTE='[CLRP]extra;47171110']if I did [code] for k,v in pairs(Gangs) [/code] how would I sort them in order of: v.members?[/QUOTE] You can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/SortedPairsByMemberValue]Global.SortedPairsByMemberValue[/url]
[QUOTE=Willox;47171120]You can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/SortedPairsByMemberValue]Global.SortedPairsByMemberValue[/url][/QUOTE] Wow thanks :D
How do I fix this? [CODE] function ENT:PhysicsCollide(colData) self.weld = constraint.Weld(self, colData.HitEntity, 0, 0, 0, true, false) end [/CODE] | v [IMG]http://i.imgur.com/iIeBJ6i.png[/IMG] why garry :(
[QUOTE=VIoxtar;47171430]How do I fix this? [CODE] function ENT:PhysicsCollide(colData) self.weld = constraint.Weld(self, colData.HitEntity, 0, 0, 0, true, false) end [/CODE] | v [IMG]http://i.imgur.com/iIeBJ6i.png[/IMG] why garry :([/QUOTE] Don't weld in ENT:PhysicsCollide. What you could do is freeze the entity and then create the weld in 1 second timer.
[QUOTE=Robotboy655;47171461]Don't weld in ENT:PhysicsCollide. What you could do is freeze the entity and then create the weld in 1 second timer.[/QUOTE] Thanks for replying. I really want my SENT to snap onto any object immediately upon impact, so freezing and timers are not really an option for a flowy interaction. Any recommendations? E: A 0 timer works. :P
[QUOTE=VIoxtar;47171430]How do I fix this? [CODE] function ENT:PhysicsCollide(colData) self.weld = constraint.Weld(self, colData.HitEntity, 0, 0, 0, true, false) end [/CODE] | v [IMG]http://i.imgur.com/iIeBJ6i.png[/IMG] why garry :([/QUOTE] @Robotboy: A whole second later? why not just the next frame? [CODE] function ENT:PhysicsCollide(colData) if( !self.Welded ) then self.Welded = true local hitobj = colData.HitEntity -- move our weld to the next frame timer.Simple( 0, function() if( IsValid( self ) && IsValid( hitobj ) ) then -- make sure we're still valid self.weld = constraint.Weld(self, hitobj, 0, 0, 0, true, false) end end ) end end [/CODE] Try something like that
[QUOTE=Hoffa1337;47171494]@Robotboy: A whole second later? why not just the next frame?[/QUOTE] Just an example, obviously you'd tweak the value to your needs.
[QUOTE=wauterboi;47169651]The velocity slows down to reach where I want it to. 512 units isn't very far from the player. The map is gm_excess_island[/QUOTE] Wouldn't you want it to actually hit "where you want it"? 512 units is 32 US Standard feet, while that bullet drops way too fast to travel that far straight. Thanks for telling me the map name :smile:
Having problems with this code not displaying the GUI when I use the context menu button: [lua] include( "shared.lua" ) surface.CreateFont("Scanlines", { font = "Roboto", size = 60, weight = 500, antialias = true, shadow = true, }) hook.Add( "HUDPaint", "drawsometext", function() draw.DrawText( TopMsg, "Scanlines", ScreenScale(320), 0, GAMEMODE:GetTeamColor(LocalPlayer()), TEXT_ALIGN_CENTER ) draw.DrawText( team.GetScore(LocalPlayer():Team()), "Scanlines", ScrW() - ScreenScale(50), ScrH() - ScreenScale(30), GAMEMODE:GetTeamColor(LocalPlayer()), TEXT_ALIGN_CENTER ) end ) MsgN(GM.Test) function filterByPattern(tbl, pattern) local t = {} -- table to store the indices local i = 0 while true do i = string.find(s, pattern) -- find 'next' newline if i == nil then -- nothing else table.insert(t, i) end end return t end frame = vgui.Create( "DFrame" ) frame:Center() frame:SetSize( ScrW(), ScrH() ) frame:SetTitle( "Player Model" ) frame:SetDraggable( true ) frame:SetWorldClicker( true ) frame:Close() frame:SetDeleteOnClose( false ) DList = vgui.Create( "DListView", frame ) DList:SetMultiSelect( false ) DList:SetPos(0,41) DList:SetSize(ScrW(), ScrH() - 40) DList:AddColumn( "Name" ) DList:AddColumn( "File" ) TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of frame TextEntry:SetPos( 0,0 ) TextEntry:SetSize( ScrW(), 40 ) TextEntry:SetText( "Type a playermodel name..." ) TextEntry.OnValueChange = function( val ) local models = player_manager.AllValidModels() local goodMdls = filterByPattern(".*"..val..".*") for nm, file in pairs(goodMdls) do DList:AddLine(nm, file) end end function plrMdlGui() frame:Show() end function noPlrMdlGui() frame:Hide() end hook.Add("OnContextMenuOpen", "plrMdlGui", plrMdlGui) hook.Add("OnContextMenuClose", "noPlrMdlGui", noPlrMdlGui) [/lua] Error [lua] [ERROR] lua/includes/extensions/client/panel.lua:579: Tried to use invalid object (type Panel) (Object was NULL or not of the right type) 1. SetVisible - [C]:-1 2. Show - lua/includes/extensions/client/panel.lua:579 3. Call - gamemodes/shooter/gamemode/cl_init.lua:63 4. unknown - gamemodes/base/gamemode/cl_spawnmenu.lua:72 5. unknown - lua/includes/modules/concommand.lua:69 [ERROR] lua/includes/extensions/client/panel.lua:583: Tried to use invalid object (type Panel) (Object was NULL or not of the right type) 1. SetVisible - [C]:-1 2. Hide - lua/includes/extensions/client/panel.lua:583 3. v - gamemodes/shooter/gamemode/cl_init.lua:67 4. Call - lua/includes/modules/hook.lua:84 5. unknown - gamemodes/base/gamemode/cl_spawnmenu.lua:73 6. unknown - lua/includes/modules/concommand.lua:69 [/lua]
[QUOTE=figgycity50;47172375]Having problems with this code not displaying the GUI when I use the context menu button: Error [lua] [ERROR] lua/includes/extensions/client/panel.lua:579: Tried to use invalid object (type Panel) (Object was NULL or not of the right type) 1. SetVisible - [C]:-1 2. Show - lua/includes/extensions/client/panel.lua:579 3. Call - gamemodes/shooter/gamemode/cl_init.lua:63 4. unknown - gamemodes/base/gamemode/cl_spawnmenu.lua:72 5. unknown - lua/includes/modules/concommand.lua:69 [ERROR] lua/includes/extensions/client/panel.lua:583: Tried to use invalid object (type Panel) (Object was NULL or not of the right type) 1. SetVisible - [C]:-1 2. Hide - lua/includes/extensions/client/panel.lua:583 3. v - gamemodes/shooter/gamemode/cl_init.lua:67 4. Call - lua/includes/modules/hook.lua:84 5. unknown - gamemodes/base/gamemode/cl_spawnmenu.lua:73 6. unknown - lua/includes/modules/concommand.lua:69 [/lua][/QUOTE] Note the "NULL PANEL" error. Is this gamemode based off sandbox? I think the context menu is only available in sandbox.
[QUOTE=bobbleheadbob;47172382]Note the "NULL PANEL" error. Is this gamemode based off sandbox? I think the context menu is only available in sandbox.[/QUOTE] Ohh right it's because my gamemodeis based on base. Is there a way to simply show it when the button is pressed in base? It's just I don't want the physgun etc. in my gamemode.
[QUOTE=figgycity50;47172425]Ohh right it's because my gamemodeis based on base. Is there a way to simply show it when the button is pressed in base? It's just I don't want the physgun etc. in my gamemode.[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerBindPress]GM/PlayerBindPress[/url] hook. I forget the convar for the context menu, type "bind c" in the console and it will tell you the command.
Sorry, you need to Log In to post a reply to this thread.