• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
move "return dmginfo" inside the if statement, otherwise you're forcing the gamemode hook for EntityTakeDamage to not run.
[QUOTE=!cake;47150843]It's just my attempt at vector notation using ascii. [ x ] = Vector (x, y) [ y ] I've done barely any of the work to be honest. You've still got to extend it to 3d. And I have no idea if this is what you actually wanted.[/QUOTE] I just need it to drop within the Z axis, so it's fine.
Hey guys. Coding a SENT here, I want to change the way it draws stuff (using renders) via the the SENT's model's LOD. (I don't want to base it purely on distance because players will likely be zooming their views on the SENT from far away). ENT:GetLod() doesn't exist, anyone know how I can do this?
[QUOTE=VIoxtar;47152465]Hey guys. Coding a SENT here, I want to change the way it draws stuff (using renders) via the the SENT's model's LOD. (I don't want to base it purely on distance because players will likely be zooming their views on the SENT from far away). ENT:GetLod() doesn't exist, anyone know how I can do this?[/QUOTE] Do it by distance, and then divide the distance by the amount of times zoomed in. So something that is 1500 units away, being viewed on a x3 zoom, will appear to be 500 units away. Adjust LOD for that distance instead of 1500.
[QUOTE=Revenge282;47152538]Do it by distance, and then divide the distance by the amount of times zoomed in. So something that is 1500 units away, being viewed on a x3 zoom, will appear to be 500 units away. Adjust LOD for that distance instead of 1500.[/QUOTE] I like you. let me check if getfov is actually what i want for zoom
[url="https://www.youtube.com/watch?v=UKRIUiyF0N4"]A long time ago[/url], I used SetNetworkedBool (string, int, float, blah) on players a lot in my addons to keep track of values I placed on them that had to be in-sync between the server and clients. After a while, I had so many values, it lagged and my addon died. The wiki page warns against using SetNetworked and such because they're hacky, while it promotes the NetworkVar functions, to be called in a SetupDataTables hook. I use NetworkVars extensively in my SWEPs. Issue is, I have a few values I need to set on a player that have to be networked not only between sever and his client, but that have to be synced to all other clients as well, and they change somewhat frequently. Also, this isn't a gamemode. It's an addon that can be activated within sandbox. I'm fine with variables being created on all players and just never used if the addon isn't active. Of course I can do usermessages and net.write, and just keep track of clientside table values and serverside table values, but that's a pain so I only use it for infrequent things, like equipment updates. I'm talking about something like when a weapon model appears attached to a player's playermodel (like when the weapon is holstered), think PAC. TL;DR What's the least hacky, most elegant, most [B]reliable[/B] way to network a few integers and a few strings on a player, such that they are set on the server every so often and networked to all clients? I thought about using NetworkVars, and the wiki has a func, PLAYER:SetUpDataTables, but how do I use it? It's not a gamemode hook. I imagine it has to be hooked and run at startup or something
A simple method is to cache the vars you're using preventing them from changing until a few seconds have passed, or simply writing a few net receivers that update data when it changes ( I may release a super lightweight data system that does this later )... Another alternative for your system would be my networking addon ( is in line for another update with the newest autoloader and some other systems ) converts umsgs to net messages, and converts NW vars for the most part to my flag system.. Basically, data is only networked from the server to client if the data changes. Additionally, data can be private so weapons can have private data such as fire-mode, etc and the only way a client can see private data is if a link is established... So, picking up a gun links the client with the gun just like getting into a vehicle links the vehicle with the client. Getting out of the vehicle or dropping the weapon unlinks them. While linked any private data ( for vehicles it is speed, odometer, fuel, battery, etc... for weapons it's fire-mode and a few other options ) that changes gets sent to the linked clients; also on link the existing data is synced and on unlinked it's wiped... My system also allows data to be categorized so addons that use it can use a category name to reduce the likelihood of a collision occurring... Public data is synced to everyone. A full blown net system may be too much for what you're trying to do but it's an option... There are some big updates coming, optimizations to connect the registry, the newer autoloader, etc...
That sounds really awesome, but all I really need is some insight on how to use SetUpDataTables for a player, since I'm only trying to network a few values (like shield, stamina, bleedout, holstered weapons etc). I can't find any global dataTables hook on the wiki. A NET system is what I have now, but it's a total pain in the ass because I have to keep track of whenever the vars change and have updating function calls everywhere they can change. I just wanna use something more encapsulated and less prone to lag/de-synchronization. SetUpDataTables for players seems like the ticket (it's wonderful on SWEPs), but I don't get how to use them and I can't find any examples.
[QUOTE=bobbleheadbob;47148861]They aren't optimized. SendLua uses usermessages and net.WriteTable is slower than the other net functions. That said, at the end of the day, fuck other people and their tiny optimizations. Use whatever code is easiest for you to use and understand. As long as it isn't problematic and it works then you're fine.[/QUOTE] Yeah, I don't know what the stigma is surrounding SendLua. It's very useful for shit that you dont want to set up netmessages for, like printing to player chat.
[QUOTE=ThrowAwayAcct;47153279]That sounds really awesome, but all I really need is some insight on how to use SetUpDataTables for a player, since I'm only trying to network a few values (like shield, stamina, bleedout, holstered weapons etc). I can't find any global dataTables hook on the wiki. A NET system is what I have now, but it's a total pain in the ass because I have to keep track of whenever the vars change and have updating function calls everywhere they can change. I just wanna use something more encapsulated and less prone to lag/de-synchronization. SetUpDataTables for players seems like the ticket (it's wonderful on SWEPs), but I don't get how to use them and I can't find any examples.[/QUOTE] A net system should be contained; you should be able to abuse it and it take care of everything... Mine only sends data if the data has changed ( there are some optimizations that can still be done but right now it's decent )... Basically set up a simple GetX and SetX function; if SetX is called on server, update all only if GetX data is different.. on client net receive you'll want to just call SetX as is and have a way to send all data when the player joins. I'll write something up when I'm back later to serve as a micro net system...
So, I just figured that editing a certain file by adding some html tricks to load lua scripts allows you to bypass the sv_allowcslua set to 0... Is there any way to protect my server against this? Since its a client side thing...
[QUOTE=dexon;47155315]So, I just figured that editing a certain file by adding some html tricks to load lua scripts allows you to bypass the sv_allowcslua set to 0... Is there any way to protect my server against this? Since its a client side thing...[/QUOTE] no
[QUOTE=Willox;47155333]no[/QUOTE] Rip.
[QUOTE=BFG9000;47153334]Yeah, I don't know what the stigma is surrounding SendLua. It's very useful for shit that you dont want to set up netmessages for, like printing to player chat.[/QUOTE] Here you go.. Untested, the only issue you may face is with net.WriteVars... you may need to pass _type in as the first arg although from past experience when referencing a function using net[ ] it seems to act just like : and because the type is the key it should work but it may actually reference net[ TYPE_* ] instead... [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_networking_system/sh_basic_networking_and_data_system.lua.html[/url] remove .html for .lua.. You can use _ent:GetFlag( <string> _flag, <T> _default, <Bool> _private ); or _ent:SetFlag( <string> _flag, <T> _value, <Bool> _private ); where <T> is "generic" and can hold any data type... Just because it can hold functions as value doesn't mean it'll network... You can SetFlag as often as you like, if the data is == then it won't set it... Other data-sets may need to be compared differently... GetFlag can be used as often as you like without fetching any data from the server, it either has the value in the local cache or it uses default.. You can opt to using data:GetFlag or data:SetFlag instead but it takes an entity or EntIndex for the first argument. When the Player ent is created on the server, it'll sync the public data to the client, and any private data associated with the players id in case anything was set... When data changes ( public or private ), and is set on server, it'll broadcast or send to the ent or player. Only PLAYER PRIVATE data is networked in this simplified version so no data-linking but it'd be easy to add... So, if the server needs to know data about an ent you can simply set data private for any entity but as said if the ent is a player then that player will know the data... Hope this works..
[QUOTE=Acecool;47155467]Hope this works..[/QUOTE] [lua]function data:GetID( _ent ) return ( ( isnumber( _id ) ) && _id || ( ( IsValid( _id ) ) && _id:EntIndex( ) || false ); end[/lua] it doesn't you're lucky I have a paper to write, the only criticisms I can come up with at a glance are that typo and using net.WriteTable
[QUOTE=PortalGod;47155506][lua]function data:GetID( _ent ) return ( ( isnumber( _id ) ) && _id || ( ( IsValid( _id ) ) && _id:EntIndex( ) || false ); end[/lua] it doesn't you're lucky I have a paper to write, the only criticisms I can come up with at a glance are that typo and using net.WriteTable[/QUOTE] I just updated the code to add the missing )... Thanks for pointing it out! I use WriteTable to send the full public TABLE to the client; not going to go through each id to send an unknown number to the client because more resources would be wasted using a loop then having to keep using net.Read/WriteVars for each value until one result either errors or comes up nil... WriteTable is correctly used in this context because it is there to sync a table of up to 8196 elements with data to the client; this is a simplified quickly written version based on parts of my net system for the user that wanted a better net system that NWVars...
[QUOTE=Acecool;47155509]I just updated the code to add the missing )... I use WriteTable to send the full public TABLE to the client; not going to go through each id to send an unknown number to the client... WriteTable is correctly used in this context; and this is a simplified quickly written version for the user that wanted a better net system that NWVars...[/QUOTE] I didn't even notice a missing parenthesis, I was talking about the argument being "_ent" and you referencing "_id" there is no correct usage for writetable
[QUOTE=PortalGod;47155522]I didn't even notice a missing parenthesis, I was talking about the argument being "_ent" and you referencing "_id" there is no correct usage for writetable[/QUOTE] Ah, right; thanks again fixed. What would [I]you[/I] use instead of Write/ReadTable when syching a table of unknown length with unknown values to the client? Anything used would require a map to be sent which would be in the form of a table, or a for loop to write the value type and the value... Additionally, if I used a loop to write the ID plus type plus value per entry, it'd add ID n^2 times that it'd need to be both written and read to rebuild the table on the client-side instead of 1 time to denote the key of the table as seen with WriteTable ( I'm thinking of JSON in this example actually which would show the key 1 time; will review WriteTable )... WriteTable writes the typeid and value for each element while other implementations would require the same amount of data ( it could be reduced by only writing the type each time it changes instead of each time but you'd still need to notify the receiving end as to each step )... I'm interested in what you're thinking of.. JSON could work but since entities can be stored as a value it wouldn't work without adding an additional conversion map and altering data before JSON... I stand by my original statement that Write/ReadTable is a good option as it is called once per player per "full" connection to sync data and there is minimal overhead in the form of 8 bit key for each type being used and other solutions would require extensive logic [ more processing power required ], a map [ same data ], the key to be sent with each entry [ more data ], or other problem... I see Read/WriteTable as cost effective in this situation with JSON being another viable option but that would require additional processing which is why I opted for Read/WriteTable.
I'm having a bit of trouble initializing a "data" table (A table named "data") on the client when they join. On the server, PlayerInitialSpawn calls a function on the player which sends a net message to the client. The client receives that and tries to assign the data in the message to the LocalPlayer().Data table. However, I cant seem to find a hook where LocalPlayer() is valid before this net message gets sent. LocalPlayer returns an invalid entity in Initialize, and PostGamemodeLoaded BUT returns the player in InitPostEntity. This is fine, however the net message gets received before InitPostEntity gets called on the client, so I get errors. I'm trying to avoid delaying the net message from the server and I dont particularly want to have something like this in all of my client receives: [lua]if (IsValid(LocalPlayer()) || !istable(LocalPlayer().Data)) then LocalPlayer().Data = {} end[/lua] Does anyone know any hooks or any solutions to this sort of problem?
LocalPlayer( ) is not valid for the first few frames ( PlayerInitialSpawn is called also before LocalPlayer( ) is valid on the client )... Check my net example above, OnEntityCreated should work fine. Additionally, as Entities can be NULL on the client if they've never been introduced into the client PVS, I'd recommend simply using EntIndex as a key in another table outside of any entity ( also shown in my example above )... Another hook you could use is PlayerFullyConnected ( You can either use HUDPaint to detect when the client loads if you don't need the server to trigger something, you can also use the move hooks on client / server as they only start firing when the client is in the server )... [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_hooks/playerfullyconnected/lua/autorun/server/sv_hook_playerfullyconnected_acecool.lua.html[/url]
[QUOTE=Acecool;47155538]What would [I]you[/I] use[/QUOTE] pseudo [lua] local function writetab(tab) local types = {} for k, v in pairs(tab) do local id = TypeID(v) --not sure if typeid is any good tbh if not(types[id]) then types[id] = {} end types[id][#types[id] + 1] = v end net.WriteUInt(table.Count(types), 5) --you probably don't need 32 types --looping twice is bad but it's worth it for type, things in pairs(types) do net.WriteUInt(type, 5) --32 types net.WriteUInt(#things, 8) --256 vars per type for k, v in pairs(things) do net.Write* --probably keep a table of which typeid uses which function end end end local function readtab() local ret = {} for i = 1, net.ReadUInt(5) do local type = net.ReadUInt(5) for j = 1, net.ReadUInt(8) do ret[#ret + 1] = net.Read* --same as write* end end return ret end [/lua] here's a better version of writetable that took me 5 minutes to do if you need a table with named/ordered keys, you should know what type of value to expect and shouldn't use writetable to begin with [editline]16th February 2015[/editline] [QUOTE=Acecool;47155538]I stand by my original statement that Write/ReadTable is a good option as it is called once per player per "full" connection to sync data and there is minimal overhead in the form of 8 bit key for each type being used and other solutions would require extensive logic [ more processing power required ], a map [ same data ], the key to be sent with each entry [ more data ], or other problem... I see Read/WriteTable as cost effective in this situation with JSON being another viable option but that would require additional processing which is why I opted for Read/WriteTable.[/QUOTE] more processing power? lmao writetable writes the key to be sent with each entry, even a "map" would be less data than writetable uses
[QUOTE=PortalGod;47155628]pseudo [lua] local function writetab(tab) local types = {} for k, v in pairs(tab) do local id = TypeID(v) --not sure if typeid is any good tbh if not(types[id]) then types[id] = {} end types[id][#types[id] + 1] = v end net.WriteUInt(table.Count(types), 5) --you probably don't need 32 types --looping twice is bad but it's worth it for type, things in pairs(types) do net.WriteUInt(type, 5) --32 types net.WriteUInt(#things, 8) --256 vars per type for k, v in pairs(things) do net.Write* --probably keep a table of which typeid uses which function end end end local function readtab() local ret = {} for i = 1, net.ReadUInt(5) do local type = net.ReadUInt(5) for j = 1, net.ReadUInt(8) do ret[#ret + 1] = net.Read* --same as write* end end return ret end [/lua] here's a better version of writetable that took me 5 minutes to do if you need a table with named/ordered keys, you should know what type of value to expect and shouldn't use writetable to begin with[/QUOTE] I'll stick to O( n ) best-case ( with recursive calls ) instead of guaranteed O( n^2 ) best-case... Yours doesn't support string keys either... Sure, Read/WriteTable could be improved by your method of organizing the data into specific type-groups then sending the type id, and count to expect but it still detracts from the ability to send string keys, etc... [quote][editline]16th February 2015[/editline] more processing power? lmao writetable writes the key to be sent with each entry, even a "map" would be less data than writetable uses[/QUOTE] Seeing as the key can be anything, that needs to be in there.. I allow different keys to be used, they aren't forced to use strings so that works well instead of forcing it to be one thing ( it's a simple net system; besides it calls Read/Write table to sync the data... with the client.. it isn't being called every frame :-) )
[QUOTE=Acecool;47155695]I'll stick to twice as much data and ignore what you said[/QUOTE] [QUOTE=PortalGod;47155628]if you need a table with named/ordered keys, you should know what type of value to expect and shouldn't use writetable to begin with[/QUOTE]
I know whenever an entity is drawn using ENT:Draw(), but how do I know whenever an entity is NOT drawn? Meaning, how can I run function X when an entity stops being drawn? Or, a better explanation of my problem: I'm coding a SENT called 'MY_SENT'. My goal is to setup a table on every client, called DrawnMY_SENTS, which basically includes all the MY_SENTs' entity indexes that are being currently drawn. Meaning, when a MY_SENT is no longer drawn for the client, it leaves the table, but when a player (say turns a corner) looks at MY_SENT, its entity index gets added to the table (given it wasn't there before of course). Now, I'm already using ENT:Draw() to know when to add the entity index to the table: [CODE] if !table.HasValue(LocalPlayer():GetTable().DrawnMY_SENTS, self:EntIndex()) then table.insert(LocalPlayer():GetTable().DrawnMY_SENTS, self:EntIndex()) end [/CODE] My problem is, I don't know how to check if the entity is not being drawn, because when a player looks away from the SENT and it's no longer being drawn, the ENT:Draw() hook stops running, so I can't use it anymore to take out the value. I'm stuck in finding out if there's a way to do this or not. Would appreciate anyone's help!
[QUOTE=bobbleheadbob;47147429] It's designed to be used as VGUI, and as such it has features which are useless for HUDs (potentially slowing things down). Also if you want to make anything which looks pretty it's simpler to use HUDPaint.[/QUOTE] Do you have a source for this? I use derma for HUDs all the time, you get all the positioning and there is no noticable FPS impact. I find it very hard to position everything manually in HUDPaint. You can use SetPaintedManually/PaintManual to draw the derma in HUDPaint. Derma is awesome for HUDs.
[QUOTE=Kamshak;47157210]Do you have a source for this? I use derma for HUDs all the time, you get all the positioning and there is no noticable FPS impact. I find it very hard to position everything manually in HUDPaint. You can use SetPaintedManually/PaintManual to draw the derma in HUDPaint. Derma is awesome for HUDs.[/QUOTE] First, it's more code, considering every element's :Paint function is overridden if you want it to be not-grey. For each element you have to p:SetPos(); p:SetSize(); p:SetData(); p.Paint = function(w,h). Second, unless you position each one every frame, when a user adjusts their screen resolution the whole thing will be offset until a reload. And third, each panel has a Think hook which is called per frame. It's not like you're breaking a law using panels for your HUD, you're just going against the standard. Derma is designed for menus with user input, and it does a damn good job at that, but it's not the best solution for all your 2-dimensional drawing needs.
[QUOTE=bobbleheadbob;47159237]It's not like you're breaking a law using panels for your HUD, you're just going against the standard. Derma is designed for menus with user input, and it does a damn good job at that, but it's not the best solution for all your 2-dimensional drawing needs.[/QUOTE] Against the standard? For your information HL2's very own hud consists of vgui panels.
Does anyone know of the GLua thing that runs scripts without Garry's Mod running?
[QUOTE=Jvs;47159269]Against the standard? For your information HL2's very own hud consists of vgui panels.[/QUOTE] If you make a HUD in C++ then go for it. The standard for HUD's in Lua is GM:HUDPaint.
[QUOTE=wauterboi;47159450]So I'm running into some weirdness with that. I've solved it and everything, but I don't want my bullet drop to operate off of velocity inputs, but distance. I want it so it'll accept a distance and by the time that distances is met, the bullet has hit the ground. [url]https://en.wikipedia.org/wiki/Projectile_motion#The_maximum_distance_of_projectile[/url] I've been looking at these and trying to figure out which one I'd be able to work with to get where I need to. I'm debating whether I should just look into parabolas. [editline]17th February 2015[/editline] *parabolas on their own - not parabolas tied to gravity or anything. [editline]17th February 2015[/editline] Basically I need to figure out what velocity will get me to reach that distance.[/QUOTE] [url]http://pastebin.com/aNvT9tX2[/url] TL;DR: [code] bulletDropDistance ( 0.5 g ) v&#8320; = -------------------- sqrt ( -------------------------------------- ) cos &#952; ( eyeHeight + bulletDropDistance tan &#952; ) [/code] This would give different initial speeds depending on the pitch you're aiming at. &#952; = 0.25 pi radians = 45 degrees is the pitch that would send the bullet the furthest. Disclaimer: I have no idea if this is right or I've messed up somewhere. EDIT: Oh. You deleted your post. :(
Sorry, you need to Log In to post a reply to this thread.