• What do you need help with? V3
    6,419 replies, posted
How do I make a player move forward for 5 seconds? I've tried using pl:ConCommand("+walk"), but that doesn't seem to work.
I believe the command is +foward, and -forward to stop them.
[QUOTE=thomasfn;36730152]I believe the command is +foward, and -forward to stop them.[/QUOTE] Oh. Thanks.
Is there an easier way of going about the following; [lua] if (LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType()) < 10) then surface.DrawText("00" .. LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())) elseif (LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType()) > 100) then surface.DrawText("" .. LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())) else surface.DrawText("0" .. LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())) end[/lua] As you can see, I want there to be 2 0's in front of the ammo count if there's less then 10 bullets, and 1 0 if 10+ and 0 0's if 100+. I couldn't have worded that any more horribly sorry guys, hope you get the idea though. I just feel as though there could be a more efficient way of going about it instead of 3 lines of near the same code. Any help is appreciated.
[QUOTE=NintendoEKS;36744010] As you can see, I want there to be 2 0's in front of the ammo count if there's less then 10 bullets, and 1 0 if 10+ and 0 0's if 100+.[/QUOTE] [lua]surface.DrawText(string.format("%03d", LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())))[/lua]
Would you be able to explain what exactly that does? Just so I'm not copy/pasting.
How does one draw and use meshes for physics? I haven't been able to find any documentation.
[QUOTE=NintendoEKS;36745808]Would you be able to explain what exactly that does? Just so I'm not copy/pasting.[/QUOTE] Read up on printf as it will have better documentation then string.format.
Can someone explain to me the difference between SetPData and SetNWInt. Don't they essentially do the same thing? Never-mind figured it out. I have no clue whats wrong with my code. GetMoney should be printing 500 like GetPData("Money") but its just printing nothing and i'm not getting any errors. Anyone mind helping me out? [LUA] local meta = FindMetaTable( "Player" ); function meta:GetMoney() self:GetPData("Money") end function MoneyTest( ply ) print( ply:GetPData("Money") ) print( ply:GetMoney() ) end concommand.Add("TestMoney", MoneyTest ) [/LUA]
How does the scroll bar work? [lua] local Sheet1 = vgui.Create( "DPanelList") Sheet1:SetPos(10,10) Sheet1:SetSize(480,480) local DVScrollBar = vgui.Create( "DVScrollBar", Sheet1 ) DVScrollBar:SetSize( 20, Sheet1:GetTall() - 65) DVScrollBar:SetPos(Sheet1:GetWide() - 35,5) DVScrollBar:SetUp(1,5) DVScrollBar:SetEnabled(true) local x = -1 local y = 0 for i = 1,30 do x = x + 1 if x > 4 then y = y + 1 x = 0 end local TestingPanel = vgui.Create( "DPanel", Sheet1 ) TestingPanel:SetPos( x*87 + 5,y*87 + 5 + DVScrollBar:GetScroll()) TestingPanel:SetSize( 85,85 ) end [/lua] Does nothing when moving scrollbar, because it runs only once?
Is there a method to get a html panels current URL on request? and although highly unlikely, is there a function that exists similar to PHP's $_GET[" "] in Lua so i can extract out data from it?
[QUOTE=101kl;36750160]Is there a method to get a html panels current URL on request? and although highly unlikely, is there a function that exists similar to PHP's $_GET[" "] in Lua so i can extract out data from it?[/QUOTE] [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf83c.html[/url]
[QUOTE=ollie;36750224][URL]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf83c.html[/URL][/QUOTE] Ah. Thanks, didn't notice that. Any ideas on variable extraction? Example being to get the values from variable and variable2 on the following url; mypage.php?variable=value&variable2=value
[QUOTE=101kl;36750713]Ah. Thanks, didn't notice that. Any ideas on variable extraction? Example being to get the values from variable and variable2 on the following url; mypage.php?variable=value&variable2=value[/QUOTE] [lua]local str = "mypage.php?variable=value&variable2=value" local url, varstr = string.match( str, "^(.+)%?(.+)$" ) local _GET = {} for key, value in string.gmatch( varstr, "([^&]+)=([^&]+)" ) do _GET[key] = value end[/lua]
Thanks Divran, that helps a heap! :dance:
[QUOTE=ollie;36750115]How does the scroll bar work? [lua] --code snipped [/lua] Does nothing when moving scrollbar, because it runs only once?[/QUOTE] Read the initial comment block in this: [url]http://luabin.foszor.com/code/addons/derma/lua/vgui/DVScrollBar.lua#8[/url] The one thing I was unsure about is how the panel's y pos gets updated since you are never invalidating the layout of the panel, but it looks like the scrollbar itself will invalidate the parent panel, so make sure your scrollbar is parented to the panel you want to scroll. You may also want to implement a scroll on mousewheel which is very easy to implement if you have the scrollbar already [lua] function PANEL:OnMouseWheeled( dlta ) if ( self.VBar ) then return self.VBar:OnMouseWheeled( dlta ) end end [/lua]
[QUOTE=I Fail At Lua;36747301]Can someone explain to me the difference between SetPData and SetNWInt. Don't they essentially do the same thing? Never-mind figured it out. I have no clue whats wrong with my code. GetMoney should be printing 500 like GetPData("Money") but its just printing nothing and i'm not getting any errors. Anyone mind helping me out? [LUA] local meta = FindMetaTable( "Player" ); function meta:GetMoney() self:GetPData("Money") end function MoneyTest( ply ) print( ply:GetPData("Money") ) print( ply:GetMoney() ) end concommand.Add("TestMoney", MoneyTest ) [/LUA][/QUOTE] Try [LUA] local meta = FindMetaTable( "Player" ); function meta:GetMoney() return tonumber(self:GetPData("Money")) end function MoneyTest( ply ) print( ply:GetPData("Money") ) print( ply:GetMoney() ) end concommand.Add("TestMoney", MoneyTest ) [/LUA]
[QUOTE=Jamies;36753485]Try [LUA] local meta = FindMetaTable( "Player" ); function meta:GetMoney() return tonumber(self:GetPData("Money")) end function MoneyTest( ply ) print( ply:GetPData("Money") ) print( ply:GetMoney() ) end concommand.Add("TestMoney", MoneyTest ) [/LUA][/QUOTE] Oh wow I'm dumb. Thanks man.
I have a map with a single buggy spawnpoint. How can I find the entity so I can kill it? On another, similar note, is there a way to find which player uses a certain map button?
Alright, I figured out the first one. Apparently spawn points are serverside only?
Why my resource.AddFile isn't working? I have my model in addons/addon/models/modelgoeshere.mdl i've tried [lua] resource.AddFile("addons/addon/models/modelgoeshere.mdl) [/lua] and [lua] resource.AddFile("models/modelgoeshere.mdl) [/lua] , neither of those work.
You forgot a quotation mark at the end.
Huh?
[QUOTE=ollie;36792868]Huh?[/QUOTE] [lua]resource.AddFile( "models/modelgoeshere.mdl" )[/lua] You lacked an end quote.
I'm fixing up my (very ancient) gamemode, but when it is uploaded to a server I get the following errors [img]http://puu.sh/J0Jh[/img] Does anybody know what may be causing that?
[QUOTE=TylerB;36793339][lua]resource.AddFile( "models/modelgoeshere.mdl" )[/lua] You lacked an end quote.[/QUOTE] Oh right, but it still doesn't fix anything. No error show up on console, and my material resource.AddFiles do work.
[QUOTE=_NewBee;36794720]I'm fixing up my (very ancient) gamemode, but when it is uploaded to a server I get the following errors [img]http://puu.sh/J0Jh[/img] Does anybody know what may be causing that?[/QUOTE] Delete the contents of garrysmod/cache (on the server) and then restart, let it build a new cache.
[QUOTE=Drakehawke;36795053]Delete the contents of garrysmod/cache (on the server) and then restart, let it build a new cache.[/QUOTE] Tried that, it didn't work.
[url]http://facepunch.com/showthread.php?t=1198371&p=36794016#post36794016[/url] I need a function that will return me of all the folder names in a directory,
I can't seem to get my timer and disconnect hook to work. The timer for some reason makes "Money" nil and the save on disconnect doesn't work either and I can't figure out why. They're both not producing any errors either. [LUA] function meta:SaveMoney( ) -- Works file.Write( "Money/" .. self:FormatSteamID() .. ".txt", tostring( self:GetMoney() ) ) end; timer.Create( "SaveMoney", 20, 0, function( ) for k, v in pairs(player.GetAll() ) do v:SaveMoney() end end) function MoneySaveDisconnect( ply ) ply:SaveMoney( ) timer.Destroy("PayDayTimer" .. ply:UserID() ) end hook.Add( "PlayerDisconnected", "playerdisconnected", MoneySaveDisconnect ) [/LUA] I know ply:SaveMoney() works because I tested it out in a different function.
Sorry, you need to Log In to post a reply to this thread.