• What do you need help with? V3
    6,419 replies, posted
[QUOTE=jrj996;39254719]Just a quick general question, how do you optimize? Like what do you look out for. I want to code a gamemode but in the most efficient way possible.[/QUOTE] Don't have much thought on optimisation while coding it or you'll probably end up losing interest because of the extra time added. That said, you shouldn't write shitty code from the start. Optimisation would be limiting stuff that gets done every tick or draw. Cache drawing stuff (such as polygons), make sure you don't have things that won't change at all inside a tick loop, etc.
[QUOTE=Magenta;39248602]Is self.TrapWeaponStats.spread a Vector?[/QUOTE] Yes, as it says in the code
[QUOTE=fawakabrother;39252403]What is it you want to know more if you give me the information i give you the information you need :)[/QUOTE] The problem is we have nothing to go on. You need to do your own research and try to find the part of code that's causing it. Just look for anything that might have to do with shooting, remove it from the gamemode, and reload the server. If it stops lagging, you've found the problem. Then you can come back and we will help you.
[QUOTE=Ylsid;39255424]Yes, as it says in the code[/QUOTE] Try printing it.
I still need help [url=http://facepunch.com/showthread.php?p=39231764#post39231764]this[/url]. It's been over a day, does nobody know how?
[QUOTE=Magenta;39257474]Try printing it.[/QUOTE] Ah. Seems I was proper stupid and it was forwarding an integer instead of a vector, working fine now. Thanks! What about the pickup problem or the think speed problem? Is there a way to fix those, do you know?
[CODE]Couldn't read type 48Couldn't read type 2 [ERROR] lua/includes/modules/net.lua:92: table index is nil 1. ReadType - lua/includes/modules/net.lua:92 2. ReadTable - lua/includes/modules/net.lua:90 3. func - addons/ulib/lua/ulib/client/cl_util.lua:9 4. unknown - lua/includes/modules/net.lua:31[/CODE] server: [CODE]util.AddNetworkString( "AFK" ) net.Start( AFK ) net.WriteEntity( ply ) net.WriteFloat( time ) net.Broadcast() [/CODE] client: [CODE]net.Receive( "AFK", function( Length ) local ply = net.ReadEntity() local time = net.ReadFloat() ply.AFK_Time = time end)[/CODE] What did i do wrong? First time net library. Top is error in the server.
[QUOTE=RCRad;39259684][CODE]Couldn't read type 48Couldn't read type 2 [ERROR] lua/includes/modules/net.lua:92: table index is nil 1. ReadType - lua/includes/modules/net.lua:92 2. ReadTable - lua/includes/modules/net.lua:90 3. func - addons/ulib/lua/ulib/client/cl_util.lua:9 4. unknown - lua/includes/modules/net.lua:31[/CODE] server: [CODE]util.AddNetworkString( "AFK" ) net.Start( AFK ) net.WriteEntity( ply ) net.WriteFloat( time ) net.Broadcast() [/CODE] client: [CODE]net.Receive( "AFK", function( Length ) local ply = net.ReadEntity() local time = net.ReadFloat() ply.AFK_Time = time end)[/CODE] What did i do wrong? First time net library. Top is error in the server.[/QUOTE] In the serverside code, AFK needs to be a string, not a global. [CODE]util.AddNetworkString( "AFK" ) net.Start( "AFK" ) net.WriteEntity( ply ) net.WriteFloat( time ) net.Broadcast() [/CODE]
I am just now starting to learn how to script in LUA, therefore I hardly know what I am doing and am learning through trial and error. A friend of mine on Steam gave me a practice HUD lua script to work on and I am trying to add a working ammo counter to it. The code that I bolded below is what I have added so far: [CODE]--This hides the default HL2 HUD: local function HUDHide( myhud ) if(myhud == "CHudHealth") or (myhud == "CHudBattery") or (myhud == "CHudAmmo") or (myhud == "CHudSecondaryAmmo") then return false end end hook.Add( "HUDShouldDraw", "HUDHide", HUDHide ) --Creates the text for the new HUD: surface.CreateFont( "myfont", { font = "Arial", size = 50, weight = 500, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false } ) --This draws the custom HUD: local ply, hp, arm, [B]wep, ammo[/B] local function Muh_HUDPaint() ply = LocalPlayer() hp = ply:Health() arm = ply:Armor() [B]wep = ply:GetActiveWeapon() ammo = ply:GetAmmoCount(wep:Clip1())[/B] draw.SimpleText(hp, "myfont", 50, 680, Color(0, 150, 0, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) draw.SimpleText(arm, "myfont", 125, 680, Color(65, 70, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) [B]draw.SimpleText(ammo, "myfont", 1200, 680, Color(255, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT)[/B] end hook.Add("HUDPaint", "Muh_HUDPaint", Muh_HUDPaint)[/CODE] The problem is that the total ammo in the weapon isn't being read correctly and gives me incorrect numbers when there are 1-10 rounds in the magazine. When I have any ammo number higher than 10, it reads it as 0. Any help with an explanation is deeply appreciated.
[QUOTE=Nimhster;39260336]I am just now starting to learn how to script in LUA, therefore I hardly know what I am doing and am learning through trial and error. A friend of mine on Steam gave me a practice HUD lua script to work on and I am trying to add a working ammo counter to it. The code that I bolded below is what I have added so far: [CODE]--This hides the default HL2 HUD: local function HUDHide( myhud ) if(myhud == "CHudHealth") or (myhud == "CHudBattery") or (myhud == "CHudAmmo") or (myhud == "CHudSecondaryAmmo") then return false end end hook.Add( "HUDShouldDraw", "HUDHide", HUDHide ) --Creates the text for the new HUD: surface.CreateFont( "myfont", { font = "Arial", size = 50, weight = 500, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false } ) --This draws the custom HUD: local ply, hp, arm, [B]wep, ammo[/B] local function Muh_HUDPaint() ply = LocalPlayer() hp = ply:Health() arm = ply:Armor() [B]wep = ply:GetActiveWeapon() ammo = ply:GetAmmoCount(wep:Clip1())[/B] draw.SimpleText(hp, "myfont", 50, 680, Color(0, 150, 0, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) draw.SimpleText(arm, "myfont", 125, 680, Color(65, 70, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) [B]draw.SimpleText(ammo, "myfont", 1200, 680, Color(255, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT)[/B] end hook.Add("HUDPaint", "Muh_HUDPaint", Muh_HUDPaint)[/CODE] The problem is that the total ammo in the weapon isn't being read correctly and gives me incorrect numbers when there are 1-10 rounds in the magazine. When I have any ammo number higher than 10, it reads it as 0. Any help with an explanation is deeply appreciated.[/QUOTE] Try GetActiveWeapon() before GetAmmoCount
[QUOTE=Triple-X;39260806]Try GetActiveWeapon() before GetAmmoCount[/QUOTE] I do apologize for I am completely new to this, but I'm not exactly sure what you mean. Could you share an example? I have tried switching them around: [CODE]--This draws the custom HUD: local ply, hp, arm, ammo, wep local function Muh_HUDPaint() ply = LocalPlayer() hp = ply:Health() arm = ply:Armor() ammo = ply:GetAmmoCount(wep:Clip1()) wep = ply:GetActiveWeapon() draw.SimpleText(hp, "myfont", 50, 680, Color(0, 150, 0, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) draw.SimpleText(arm, "myfont", 125, 680, Color(65, 70, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) draw.SimpleText(ammo, "myfont", 1200, 680, Color(255, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT) end hook.Add("HUDPaint", "Muh_HUDPaint", Muh_HUDPaint) [/CODE] But the HUD does not appear and spams this error in the console: [CODE][ERROR] addons/testhud/lua/autorun/client.lua:37: attempt to index upvalue 'wep' (a nil value) 1. v - addons/testhud/lua/autorun/client.lua:37 2. unknown - lua/includes/modules/hook.lua:82[/CODE]
[QUOTE=Nimhster;39261246]I do apologize for I am completely new to this, but I'm not exactly sure what you mean. Could you share an example? I have tried switching them around: [CODE]--This draws the custom HUD: local ply, hp, arm, ammo, wep local function Muh_HUDPaint() ply = LocalPlayer() hp = ply:Health() arm = ply:Armor() ammo = ply:GetAmmoCount(wep:Clip1()) wep = ply:GetActiveWeapon() draw.SimpleText(hp, "myfont", 50, 680, Color(0, 150, 0, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) draw.SimpleText(arm, "myfont", 125, 680, Color(65, 70, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) draw.SimpleText(ammo, "myfont", 1200, 680, Color(255, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT) end hook.Add("HUDPaint", "Muh_HUDPaint", Muh_HUDPaint) [/CODE] But the HUD does not appear and spams this error in the console: [CODE][ERROR] addons/testhud/lua/autorun/client.lua:37: attempt to index upvalue 'wep' (a nil value) 1. v - addons/testhud/lua/autorun/client.lua:37 2. unknown - lua/includes/modules/hook.lua:82[/CODE][/QUOTE] Try this out. I dont do a lot with HUDs but this should work. [CODE]--This draws the custom HUD: local ply, hp, arm, ammo, wep; local function Muh_HUDPaint() local hp = LocalPlayer():Health() local arm = LocalPlayer():Armor() local ammo = LocalPlayer():GetActiveWeapon():Clip1() local wep = LocalPlayer():GetActiveWeapon() draw.SimpleText(hp, "myfont", 50, 680, Color(0, 150, 0, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) draw.SimpleText(arm, "myfont", 125, 680, Color(65, 70, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT) draw.SimpleText(ammo, "myfont", 1200, 680, Color(255, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT) end hook.Add("HUDPaint", "Muh_HUDPaint", Muh_HUDPaint) [/CODE]
[QUOTE=Triple-X;39261403]Try this out. I dont do a lot with HUDs but this should work. [CODE]-code-[/CODE][/QUOTE] It worked; thank you very much!
[QUOTE=Kogitsune;39235042]It's really a problem with the nature of hooks - they are designed to stop the base hook from running if you return something that evaluates to true. CalcView requires you to return the table to make your changes take effect. There's not really anything you can do about it aside from detouring hook.Call, which would reset after map change automatically.[/QUOTE] Actually, I already tried editing hook.Call. Apparently when the hook is called it's called by the engine and not hook.Call; hook.Call must just be a helper function, because it's not getting called when all the various hooks of the game are ran. I was thinking, if the hook system C-side (I'm guessing it's C-side or else garry woulda just used hook.Call, right?) actually uses the hook.GetTable() table, would it be possible to set up a metatable to imitate the CalcView index, and then pass all the info to a handler function? Probably not, if it's C-side. Worth a try though.
I still need help with this. [Quote]How can I make it so, when somebody says something specific in chat (e.g. /somethingspecific hi etc etc etc...) to show up in a derma menu (e.g. !specificmenu) (without the /somethingspecific of course) Also, is it able to make a tab (using DPropertySheet) in a derma menu accessible to only one steamid/person/UserGroup/whatever?[/quote]
t = JB.Characters.Prisoner[prisoner]; [ERROR] gamemodes/jailbreak/gamemode/core/cl_spawnmenu.lua:184: attempt to index field 'Characters' (a nil value) 1. v - gamemodes/jailbreak/gamemode/core/cl_spawnmenu.lua:184 2. unknown - lua/includes/modules/hook.lua:82
What would be the Characters table inside JB is nil. What about it?
Bump, could anybody advice me what to do with the NPC base and the error I posted here: [url]http://www.facepunch.com/showthread.php?t=1160598&p=39252569#post39252569[/url] I really need this fixed.
Why won't [lua] hook.Add("PlayerUse", "JRPlyUse", function(ply, entity) print("test") print(entity) PrintTable(entity) end) [/lua] work? I don't get errors or anything when I use any entity.
[QUOTE=Ylsid;39258066]Ah. Seems I was proper stupid and it was forwarding an integer instead of a vector, working fine now. Thanks! What about the pickup problem or the think speed problem? Is there a way to fix those, do you know?[/QUOTE] Think speed is defaulted to 0.5 seconds for all entities, You have to overwrite it by doing self:NextThink( CurTime() + X ) return true at the end of your think function, Just CurTime() if you want it to think Every frame, You should never let it think for every frame if you can avoid it, But sometimes you need precision. Also, If you mean about how you cant pick it up with Use? No SENTS can be picked up with the Use key, You'll have to make a custom PlayerUse Hook and use the pickup functions for that.
[QUOTE=Loures;39245276]Is there any documentation on the new HTML functions shipped with GM13 and further updates? (I reckon reading about some HTML -> Lua stuffs)[/QUOTE] I was messing around with it awhile ago, here is a sample I did. [html] <html> <head> <link href='http://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Fredoka+One' rel='stylesheet' type='text/css'> <script type="text/javascript">var lua={Run:function(cmd){if(arguments.length==1){console.log("RUNLUA:"+cmd);return}var str="";var arg=1;for(var i=0;i<cmd.length;i++){if(cmd[i]=='%'){i++;if(cmd[i]=='s'){str+="\"";str+=arguments[arg].replace(/"/g,"\\\"");str+="\"";arg++;continue}if(cmd[i]=='i'){str+=arguments[arg];arg++;continue}}str+=cmd[i]}console.log("RUNLUA:"+str)},PlaySound:function(name){lua.Run("surface.PlaySound( %s )",String(name))}}</script> <script type="text/javascript"> function CloseMenu() { lua.Run("SexyMenus.CloseMenu('CB_MAIN');"); } function OpenAimbot() { lua.Run("OpenCB_Aim();"); } </script> <style> a { border: 0;outline: 0;text-decoration: none;color: #444; } body { background-color: whiteSmoke;color: #444;font-family: 'Oxygen', sans-serif; } .topBanner { font-family: 'Fredoka One', cursive;margin: 5px;font-size: 18px;height: 36px; } .title { color: #086A87; } .closeButton { height: 14px;width: 14px;border-radius: 7px;background-color: #086A87;color: white;font-size: 11px;text-align: center; } ._navigation { margin: 5px;margin-top: 15px; } .navButton { background-color: #DDD;border: 1px solid #AAA;border-radius: 5px;margin-right: 15px;padding: 3px; } .navButton:hover { background-color: #AAA; } </style> </head> <body> <div class='topBanner'> <table style='width: 100%;'> <tr> <td style='width: 100%;'><h1 class='title'>cunit is gay</h1></td> <td style='text-align: right;' VALIGN=TOP><a href='#'><div class='closeButton' onclick='CloseMenu();'>X</div></a></td> </tr> </table> </div> <div class='_navigation' style=''> <span class='navButton'>Test</span> <span class='navButton'>Shit</span> <span class='navButton'>Coke</span> </div> </body> </html> [/html] I just had it read from a local webserver as I never looked into adding web files. If using a local webserver, you MUST include everything in one file, AFAIK. Not sure why my google font links worked.
[Quote]How can I make it so, when somebody says something specific in chat (e.g. /somethingspecific hi etc etc etc...) to show up in a derma menu (e.g. !specificmenu) (without the /somethingspecific of course) Also, is it able to make a tab (using DPropertySheet) in a derma menu accessible to only one steamid/person/UserGroup/whatever?[/quote] OK I've figured the second thing out, but can ANYONE help me with the first thing?
Hello im making a Terminal where you can spawn your car, when it creates the ent. i have it with a SetPos. The string i have for the SetPos is: [LUA]CarPos[ 1 ] = Vector(2086.941650, 843.956665, -131.968750)Angle(0,180,0)[/LUA] It seems to spawn the car propperly but the Angle is not right, i dont know why it does that, maybe the setup is wrong? I dont know, please help. Thanks in advance.
[QUOTE=DJarthas;39266306]Hello im making a Terminal where you can spawn your car, when it creates the ent. i have it with a SetPos. The string i have for the SetPos is: [LUA]CarPos[ 1 ] = Vector(2086.941650, 843.956665, -131.968750)Angle(0,180,0)[/LUA] It seems to spawn the car propperly but the Angle is not right, i dont know why it does that, maybe the setup is wrong? I dont know, please help. Thanks in advance.[/QUOTE] If you want both a Vector and an Angle in your variable, you'll have to use a table. [lua] carpos = { [1] = { vec = Vector(2086.941650, 843.956665, -131.968750), ang = Angle(0,180,0) } } local car = ents.Create("yourcar") car:SetPos(carpos[1].vec) car:SetAngle(carpos[1].ang) car:Spawn() car:Activate() [/lua]
[QUOTE=Hyper Iguana;39266362]If you want both a Vector and an Angle in your variable, you'll have to use a table. [lua] carpos = { [1] = { vec = Vector(2086.941650, 843.956665, -131.968750), ang = Angle(0,180,0) } } local car = ents.Create("yourcar") car:SetPos(carpos[1].vec) car:SetAngle(carpos[1].ang) car:Spawn() car:Activate() [/lua][/QUOTE] Makes sense :) Thanks for the quick response
[QUOTE=fawakabrother;39244159]If some one gets this fixed i will pay you 50 euro's on paypal. Hey all! I have the following problem with my server: I have 1 server with the gamemode "jailbreak" but when people starting to shoot each other the server has a strange lag. Its not fps lag or what ever. For example if there are like 5 people in the server and 2 people shooting each other then the other 3 people are like moving on there on when they standing still. A friend of my said: when somebody fires a gun, there is a random chance that this will cause the server to stutter and all players will experience momentary packet loss My download speed is 43 mbps My upload speed is 3.63 mbps I have a xeon procesor dual socket 2011 and 64 GB intern memory ddr3 windows server 2008 R2 64 bit You can see it your self if you want join the server: 83.84.141.141:27016 or see it on this video [URL="http://www.youtube.com/watch?v=Cr_V0mBK4Rw"]http://www.youtube.com/watch?v=Cr_V0mBK4Rw[/URL] [IMG]http://s1.postimage.org/xi4xlptwf/Naamloos.png[/IMG][/QUOTE] Try one at a time: 1. Move affinity of srcds.exe to one core. 2. Up processor priority of srcds.exe to high. 3. Increase sv_maxrate to like 40000 and set sv_minrate to match it.
Yes this is me asking a question. I am running this through console. [code]] lua_openscript menu.lua Running script menu.lua... Start Run [ERROR] lua/menu.lua:3: attempt to index global 'vgui' (a nil value) 1. unknown - lua/menu.lua:3 [/code] And this is the script [lua]print("Start Run") local DermaPanel = vgui.Create("DFrame") DermaPanel:SetPos( 100, 100 ) DermaPanel:SetSize( 300, 200 ) DermaPanel:SetTitle( "My new Derma frame" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() print("End Run")[/lua] Any reason why? First try of g13 lua and i cant get basic derma undercontrol.
[QUOTE=Science;39266766]Yes this is me asking a question. I am running this through console. [code]] lua_openscript menu.lua Running script menu.lua... Start Run [ERROR] lua/menu.lua:3: attempt to index global 'vgui' (a nil value) 1. unknown - lua/menu.lua:3 [/code] And this is the script [lua]print("Start Run") local DermaPanel = vgui.Create("DFrame") DermaPanel:SetPos( 100, 100 ) DermaPanel:SetSize( 300, 200 ) DermaPanel:SetTitle( "My new Derma frame" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() print("End Run")[/lua] Any reason why? First try of g13 lua and i cant get basic derma undercontrol.[/QUOTE] I don't know if you're posting the full code, but the derma has to be inside a function, and then you must run the function/concommand on the player to open the menu. Also vgui is clientside, run it with lua_openscript_cl.
That would make complete sense. Im an idiot. Thank you. [editline]18th January 2013[/editline] I now tried [lua]print("Start Run") function OpenMenu() local DermaPanel = vgui.Create("DFrame") DermaPanel:SetPos( 100, 100 ) DermaPanel:SetSize( 300, 200 ) DermaPanel:SetTitle( data ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() end OpenMenu() print("End Run")[/lua] Only to return [code]] lua_openscript menu.lua Running script menu.lua... Start Run [ERROR] lua/menu.lua:7: attempt to index global 'vgui' (a nil value) 1. OpenMenu - lua/menu.lua:7 2. unknown - lua/menu.lua:18 Unhandled Lua Refresh: [NAME:lua/menu.lua] [TYPE:!UNKNOWN] ] lua_openscript menu.lua Running script menu.lua... Start Run [ERROR] lua/menu.lua:7: attempt to index global 'vgui' (a nil value) 1. OpenMenu - lua/menu.lua:7 2. unknown - lua/menu.lua:18 ] lua_openscript_cl menu.lua [/code]
[QUOTE=Science;39266923]That would make complete sense. Im an idiot. Thank you. [editline]18th January 2013[/editline] I now tried [lua]print("Start Run") function OpenMenu() local DermaPanel = vgui.Create("DFrame") DermaPanel:SetPos( 100, 100 ) DermaPanel:SetSize( 300, 200 ) DermaPanel:SetTitle( data ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() end OpenMenu() print("End Run")[/lua] Only to return [code]] lua_openscript menu.lua Running script menu.lua... Start Run [ERROR] lua/menu.lua:7: attempt to index global 'vgui' (a nil value) 1. OpenMenu - lua/menu.lua:7 2. unknown - lua/menu.lua:18 Unhandled Lua Refresh: [NAME:lua/menu.lua] [TYPE:!UNKNOWN] ] lua_openscript menu.lua Running script menu.lua... Start Run [ERROR] lua/menu.lua:7: attempt to index global 'vgui' (a nil value) 1. OpenMenu - lua/menu.lua:7 2. unknown - lua/menu.lua:18 ] lua_openscript_cl menu.lua [/code][/QUOTE] Notice that it errored when you used lua_openscript and not lua_openscript_cl. The "cl" is for client. The server can't vgui shit. Aaaaanyways.. [url]http://wiki.garrysmod.com/page/gui[/url] What happened to OpenURL?
Sorry, you need to Log In to post a reply to this thread.