• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
Any good snippets for attaching a client side model entity to a DModelPanel? There's only one I've found and didn't seem to work properly.
[QUOTE=LordNoodles;52020635]Any good snippets for attaching a client side model entity to a DModelPanel? There's only one I've found and didn't seem to work properly.[/QUOTE] I believe it's just [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DModelPanel/SetEntity]DModelPanel:SetEntity[/url](your_cs_ent)
How can I get a list of all the banned players? (Writing a ban system) There seems to be no methods in regards to the default gmod ban system in relation to this, am I going to have to read the cfg file manually and do it that way?
[QUOTE=DahDestroyer;52022831]How can I get a list of all the banned players? (Writing a ban system) There seems to be no methods in regards to the default gmod ban system in relation to this, am I going to have to read the cfg file manually and do it that way?[/QUOTE] Don't know if there's an easier way, but if you do end up parsing the file, you shouldn't do it by yourself. There's already [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/KeyValuesToTable]util.KeyValuesToTable[/url] to do it for you.
[QUOTE=LordNoodles;52020635]Any good snippets for attaching a client side model entity to a DModelPanel? There's only one I've found and didn't seem to work properly.[/QUOTE] The only real way to do this is to created them in: [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DModelPanel/PostDrawModel]DModelPanel:PostDrawModel[/url] My thread for reference: [url]https://facepunch.com/showthread.php?t=1528946[/url]
Jesus, don't create a new entity every frame! Why not use the function I said before?
How would I go about ensuring that a HUD element stays the same place on the screen of the user no matter the resolution that play at? I've already eliminated all subtractions and additions, using only division and multiplication for my placement, but that doesn't suffice. The progress bar in the picture below is centered at 1280, but not 1600 (the "Crafting: XXX" is centered): [IMG]http://i.imgur.com/LFTShS8.png[/IMG] This is my code: [lua] local prevTime = CurTime() local w, h = ScrW(), ScrH() hook.Add( "HUDPaint", "DrawProgress:HUDPaint", function() draw.SimpleTextOutlined( "Crafting: " .. wep.name, "fp_header3", w / 2, h / 1.9, Color( 255, 255, 255 ), 1, 1, 1, Color( 0, 0, 0 ) ) draw.RoundedBox( 2, w / 2.9, h / 1.83, 400, 50, Color( 0, 0, 0, 200 ) ) draw.RoundedBox( 2, w / 2.87, h / 1.81, ( ( CurTime() - prevTime ) / wep.time ) * 385, 40, Color( 85, 153, 16, 255 ) ) draw.SimpleTextOutlined( math.floor( ( ( CurTime() - prevTime ) / wep.time ) * 100 ) .. "%", "gc_header1", w / 2, h / 1.73, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color( 0, 0, 0, 150 ) ) end ) [/lua]
Any way to get the entity currently being held by the player? There's [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/IsPlayerHolding]Entity:IsPlayerHolding[/url] so I can loop over ents.GetAll() but it doesn't give me the player holding the entity.
[QUOTE=Fillipuster;52024016]How would I go about ensuring that a HUD element stays the same place on the screen of the user no matter the resolution that play at? I've already eliminated all subtractions and additions, using only division and multiplication for my placement, but that doesn't suffice. The progress bar in the picture below is centered at 1280, but not 1600 (the "Crafting: XXX" is centered): [IMG]http://i.imgur.com/LFTShS8.png[/IMG] This is my code: [lua] local prevTime = CurTime() local w, h = ScrW(), ScrH() hook.Add( "HUDPaint", "DrawProgress:HUDPaint", function() draw.SimpleTextOutlined( "Crafting: " .. wep.name, "fp_header3", w / 2, h / 1.9, Color( 255, 255, 255 ), 1, 1, 1, Color( 0, 0, 0 ) ) draw.RoundedBox( 2, w / 2.9, h / 1.83, 400, 50, Color( 0, 0, 0, 200 ) ) draw.RoundedBox( 2, w / 2.87, h / 1.81, ( ( CurTime() - prevTime ) / wep.time ) * 385, 40, Color( 85, 153, 16, 255 ) ) draw.SimpleTextOutlined( math.floor( ( ( CurTime() - prevTime ) / wep.time ) * 100 ) .. "%", "gc_header1", w / 2, h / 1.73, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color( 0, 0, 0, 150 ) ) end ) [/lua][/QUOTE] Align the elements using percentages to specify the position. get the screen width via [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/ScrW]ScrW[/url] and the screen height via [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/ScrH]ScrH[/url] and position things as a percent of that, like the bar left is (ScrW * 0.5) - (barWidth * ScrW) barWidth is a percent of the screen, say 0.1 (10%) or whatever you want. Then the layout is relative to the resolution, on a hire resolution things are bigger, but occupy the same amount of screen space. At lower resolutions they have less pixels but still the same screen space. This is just one way to do it. Hope this helps. [editline]28th March 2017[/editline] Also use variables for most of the numbers, it makes the code easier to read, magic numbers are not good.
[QUOTE=Fantym420;52024099]Align the elements using percentages to specify the position. get the screen width via [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/ScrW]ScrW[/url] and the screen height via [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/ScrH]ScrH[/url] and position things as a percent of that, like the bar left is (ScrW * 0.5) - (barWidth * ScrW) barWidth is a percent of the screen, say 0.1 (10%) or whatever you want. Then the layout is relative to the resolution, on a hire resolution things are bigger, but occupy the same amount of screen space. At lower resolutions they have less pixels but still the same screen space. This is just one way to do it. Hope this helps. [editline]28th March 2017[/editline] Also use variables for most of the numbers, it makes the code easier to read, magic numbers are not good.[/QUOTE] Nice! But wouldn't I achieve the same results using only devision? Multiplying by <1 numbers seems to me like it's just division... Correct me if I'm stupid :P
[QUOTE=Fillipuster;52024134]Nice! But wouldn't I achieve the same results using only devision? Multiplying by <1 numbers seems to me like it's just division... Correct me if I'm stupid :P[/QUOTE] yes, multiplying by a decimal is the same as dividing 10 * 0.5 = 5 10 / 2 = 5 1 / 2 = 0.5
[QUOTE=Fillipuster;52024134]Nice! But wouldn't I achieve the same results using only devision? Multiplying by <1 numbers seems to me like it's just division... Correct me if I'm stupid :P[/QUOTE] If you only use multiplication, nobody has to wonder about order of operations or anything like that. With division, you might need parenthesis and whatnot. So it's better to just stick with multiplication
[QUOTE=Shenesis;52024104]if it's a prop you're talking about I think you're shit out of luck. Otherwise if it's for a SENT I did this: [lua] function ENT:Think() if (self.m_HeldBy) then if (!IsValid(self.m_HeldBy) or !self.m_HeldBy:Alive() or !self:IsPlayerHolding()) then self.m_HeldBy = nil end end end function ENT:Use(ply) if (self:IsPlayerHolding()) then return end ply:PickupObject(self) self.m_HeldBy = ply end [/lua][/QUOTE] It is indeed a prop I need, or any entity regardless of class. I ended up doing this: [lua]for _, heldent in pairs(ents.GetAll()) do if heldent:IsPlayerHolding() then -- my code return end end[/lua] This is pretty much only used clientside so at leats I'll know the only player that could be holding it is the only player in the game (Entity(1)), but I do wish this could work in multiplayer and I really need to know WHICH player is holding an entity - or much better, get the entity the player is holding from the player directly. I'll probably make a request for this soon. Thank you for trying to help regardless :)
I'm trying to create categories for my DarkRP server, but it just doesn't work, even if I appear to have done everything correctly. Code is below, any help would be appreciated! [CODE]timer.Simple(4, function() print("Loading upgradeable money printers") DarkRP.createEntity("Storage upgrade", { ent = "storage_upgrade", model = "models/props_lab/reciever01a.mdl", price = 200, max = 3, cmd = "buystorageupgrade" category = "Printers" }) DarkRP.createEntity("Amount upgrade", { ent = "amount_upgrade", model = "models/props_lab/reciever01d.mdl", price = 100, max = 6, cmd = "buyamountupgrade11" category = "Printers" }) DarkRP.createEntity("Diamond money printer", { ent = "diamond_tomasmoneyprinter", model = "models/props_c17/consolebox01a.mdl", price = 8000, max = 3, cmd = "buydiamondmoneyprinter" category = "Printers" }) DarkRP.createEntity("Emerald money printer", { ent = "emerald_tomasmoneyprinter", model = "models/props_c17/consolebox01a.mdl", price = 10000, max = 3, cmd = "buyemeraldmoneyprinter" category = "Printers" }) DarkRP.createEntity("Gold money printer", { ent = "gold_tomasmoneyprinter", model = "models/props_c17/consolebox01a.mdl", price = 1000, max = 3, cmd = "buygoldmoneyprinter" category = "Printers" }) DarkRP.createEntity("Ruby money printer", { ent = "ruby_tomasmoneyprinter", model = "models/props_c17/consolebox01a.mdl", price = 3000, max = 3, cmd = "buyrubyprinter" category = "Printers" }) DarkRP.createEntity("Ink", { ent = "ink_upgrade", model = "models/props_lab/jar01b.mdl", price = 100, max = 6, cmd = "buyprinterink" category = "Printers" }) DarkRP.createEntity("Paper", { ent = "paper_upgrade", model = "models/props/cs_office/paper_towels.mdl", price = 100, max = 6, cmd = "buyprinterpaper" category = "Printers" }) DarkRP.createEntity("Fire Extinguisher", { ent = "fire_extinguisher", model = "models/props/cs_office/fire_extinguisher.mdl", price = 150, max = 6, cmd = "buyfireextinguisher" category = "Printers" }) end)[/CODE] And the categories.lua file [CODE]DarkRP.createCategory{ name = "Printers", -- The name of the category. categorises = "entities", -- What it categorises. MUST be one of "jobs", "entities", "shipments", "weapons", "vehicles", "ammo". startExpanded = true, -- Whether the category is expanded when you open the F4 menu. color = Color(0, 107, 0, 255), -- The color of the category header. canSee = function(ply) return true end, -- OPTIONAL: whether the player can see this category AND EVERYTHING IN IT. sortOrder = 10, -- OPTIONAL: With this you can decide where your category is. Low numbers to put it on top, high numbers to put it on the bottom. It's 100 by default. } DarkRP.createCategory{ name = "Heavy", -- The name of the category. categorises = "shipments", -- What it categorises. MUST be one of "jobs", "entities", "shipments", "weapons", "vehicles", "ammo". startExpanded = true, -- Whether the category is expanded when you open the F4 menu. color = Color(0, 107, 0, 255), -- The color of the category header. canSee = function(ply) return true end, -- OPTIONAL: whether the player can see this category AND EVERYTHING IN IT. sortOrder = 10, -- OPTIONAL: With this you can decide where your category is. Low numbers to put it on top, high numbers to put it on the bottom. It's 100 by default. }[/CODE]
[QUOTE=aeromantis;52024390]I'm trying to create categories for my DarkRP server, but it just doesn't work, even if I appear to have done everything correctly. Code is below, any help would be appreciated! [B]Some code.[/B] And the categories.lua file [B]More code.[/B] [/QUOTE] I think the guys over at the [URL="http://forum.darkrp.com/forums/darkrp-modding-questions-help.5/"]DarkRP Forums[/URL] can provide better help than us :)
[QUOTE=aeromantis;52024390]A whole lotta stuff[/QUOTE] Does nobody read the stickied, READ ME FIRST threads? [quote]KEEP DARKRP QUESTIONS TO THIS THREAD: [url]http://facepunch.com/showthread.php?t=1249475[/url][/quote] I'm not saying it's [I]forbidden[/I] to post here about it, but it'd be nice if you tried that place first
[QUOTE=aeromantis;52024390]I'm trying to create categories for my DarkRP server, but it just doesn't work, even if I appear to have done everything correctly. Code is below, any help would be appreciated! And the categories.lua file [/QUOTE] 1: why is it in a timer 2: you're missing commas in the createEntity tables
[QUOTE=JasonMan34;52024154]If you only use multiplication, nobody has to wonder about order of operations or anything like that. With division, you might need parenthesis and whatnot. So it's better to just stick with multiplication[/QUOTE] This is like 6th grade math: division and multiplication have the same degree in the order of operations, and is solved from left-to-right. In Lua, you might be able to get away with substituting division for multiplication, but in languages where floating point inaccuracies are a present concern, the one you choose matters. [editline]28th March 2017[/editline] I prefer to just use the simplest and most concise when choosing operations. Num / 2 is simpler (and easier to understand at first glance) than Num * 0.5 imo.
[QUOTE=code_gs;52024828]This is like 6th grade math: division and multiplication have the same degree in the order of operations, and is solved from left-to-right. In Lua, you might be able to get away with substituting division for multiplication, but in languages where floating point inaccuracies are a present concern, the one you choose matters. [editline]28th March 2017[/editline] I prefer to just use the simplest and most concise when choosing operations. Num / 2 is simpler (and easier to understand at first glance) than Num * 0.5 imo.[/QUOTE] I figure he's talking about the fact multiplication is commutative, as such you don't have to worry about the way you order things. Though I agree that it's more of what's simpler and more concise.
Does anyone here happen to know how people embed images into their Chat boxes? I believe most use a RichText box but other than that there doesn't really seem to be much information surrounding embedding materials into them.
[QUOTE=NeatNit;52024061]Any way to get the entity currently being held by the player? There's [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/IsPlayerHolding]Entity:IsPlayerHolding[/url] so I can loop over ents.GetAll() but it doesn't give me the player holding the entity.[/QUOTE] [url]http://wiki.garrysmod.com/page/GM/DrawPhysgunBeam[/url] Gives you the entity clientside not sure about serverside.
Hello. I currently am attempting to write miscellaneous addons for my own garrysmod server. Currently, no matter what, certain addons do not seem to load or work whatsoever. I have a file located in /addons/addon_name/lua/autorun/server/sv_addon.lua in the .lua file at the top I put [code]timer.Create("ello", 5, 0, function() for k, ply in pairs( player.GetAll() ) do ply:ChatPrint( "Hello World" ) end end)[/code] Yet, nothing errors nor does it actually print in my chat. ULX and uLib seem to load just fine, as well as other addons such as the "jihadi bomb." Can anyone explain to me what the possible issue is here? I am running ubuntu 14.04.5 LTS (trusty) via SteamCMD. Thanks! edit: I moved my addon from the "addon" folder and into the "garrysmod/lua/autorun" directory and it is now working. What?
[QUOTE=Lilyxfce;52025997]Hello. I currently am attempting to write miscellaneous addons for my own garrysmod server. Currently, no matter what, certain addons do not seem to load or work whatsoever. I have a file located in /addons/addon_name/lua/autorun/server/sv_addon.lua in the .lua file at the top I put :snip: Yet, nothing errors nor does it actually print in my chat. ULX and uLib seem to load just fine, as well as other addons such as the "jihadi bomb." Can anyone explain to me what the possible issue is here? I am running ubuntu 14.04.5 LTS (trusty) via SteamCMD. Thanks! [/QUOTE] I'd suggest changing the file name to something a bit more unqiue, it could possibly be conflicting with another addon. If that doesn't work try putting a print statement at the top of the file and check if it prints out anything when you load it. [editline]28th March 2017[/editline] [QUOTE] I moved my addon from the "addon" folder and into the "garrysmod/lua/autorun" directory and it is now working. What?[/QUOTE] Did you restart your game after you created the addon folder? iirc you have to for the addon to be noticed.
[QUOTE=bigdogmat;52026055]I'd suggest changing the file name to something a bit more unqiue, it could possibly be conflicting with another addon. If that doesn't work try putting a print statement at the top of the file and check if it prints out anything when you load it. [editline]28th March 2017[/editline] Did you restart your game after you created the addon folder? iirc you have to for the addon to be noticed.[/QUOTE] It is not conflicting. There is no other addon. I already put a print statement at the top. It does not run. I have restarted the server and changed the map multiple times already.
I've heard multiplications in Lua are a bit faster than divisions, so personally I use them as much as possible. Micro optimization by micro optimization, my code shall be the fastest. :smug:
[QUOTE=Tenrys;52026722]I've heard multiplications in Lua are a bit faster than divisions, so personally I use them as much as possible. Micro optimization by micro optimization, my code shall be the fastest. :smug:[/QUOTE] I'm pretty sure they're JIT'd to be the same.
[QUOTE=Rocket;52027850]I think multiplications are better in this situation because we're talking about percentages. If something is five percent of the screen, it makes more sense to multiply it by 0.05 than to divide it by twenty.[/QUOTE] If you want to make it explicit that it's a fraction, (1/20) or (5/100) would be clearer and will compile to 0.05 anyway.
It's commutative, at this point it's just a personal preference. I prefer decimals over fractions myself, but either works just fine.
Probably not the best place to put it, but I was hoping someone would know so I could get a quick answer. How can I add/remove items from my inventory with itemstore using code? Tried looking at the API but couldn't really understand it
What's itemstore?
Sorry, you need to Log In to post a reply to this thread.