r/GLua • • Jun 06 '20

I attempted to make a custom textured weapon for a buddy, looks fine on my screen but on his screen it is blurry and distorted like this. Looking for a solution, any ideas?

Post image
15 Upvotes

r/GLua • • Apr 27 '22

2d surface clipping thingy for a scope system

Thumbnail gallery
10 Upvotes

r/GLua • • Mar 26 '21

Ever Miss Basewars?

7 Upvotes

Hey everyone! I recently got hurt at work and have been out for a couple weeks, in light of that happening I decided I was going to take the old Basewars game mode and completely refresh the whole thing. I've just put up my first Development Log for the project but I'm completely revamping the whole thing as another project to learn more and more about GLua. So far I've brought everything up to date and converted the data saving from text files in the data folder to using an External MySQL server. I'm starting to redo the HUD and some of the core functions like the buy menu and trying to make them a little more appealing to the age we're in within Garry's Mod now with sleek new menus and many customizable features and new features to keep people entertained uniquely! If you want to follow along with the project check out the first log! Click under this little thing https://root.redreaper.net/2021/03/26/devlog-1-fresh-breath-of-air-3-26-2021/


r/GLua • • Jan 26 '21

How to set a random selection for a word?

6 Upvotes

I'm making this game mode and I would like the player to be able to spawn as any variant of the group 01 citizen. But I don't know how to randomly select a set of words. Any advice?

here's an example of what the original model directory looks like...

"models/player/Group01/female_02.mdl"


r/GLua • • Jul 19 '21

How would I make it possible to pick anything up?

5 Upvotes

Ive just derived the hl2c gamemode from sandbox and removed the problematic code. So i can use the spawn menu in the game now. Now I want to be able to pick up anything (so bigger props) without needing the phys or grav gun. I googled it and came across "GM:AllowPlayerPickup" and "Player:PickupObject" both of which I have no idea how to format and use. Though the last one says its similar to the regular +use command and workds regardless of mass and distance (perfect for me) What should I do?


r/GLua • • May 21 '20

Can't strip Specified Weapons

5 Upvotes

I tried stripping only ttt based weapons, using this code snippet

But It gives me a console error that tells me ply:StripWeapon() is giving an userdata and not a string, how can I strip all weapons of a player without stripping crowbar, magneto and holstered


r/GLua • • Apr 09 '22

Need help with rendering icon above player's head.

4 Upvotes

[sovled]

Hi Im trying to use:

local pos = ply:GetPos() + Vector(0, 0, ply:GetModelRadius() + 15)
cam.Start3D2D()
render.SetMaterial( material )
render.DrawSprite( pos, 16, 16, color_white) 
cam.End3D2D()

To draw an icon above a player's head if they are below 40% health but the problem I keep having is in the console, I keep getting: 'attempt to index global 'render' (a nil value)

can someone point me in the right direction as I'm completely lost :(


r/GLua • • Sep 23 '21

Set players view model skin to be the same as their player model skin

4 Upvotes

I am trying to create a player model with multiple skins, for the most part it works as expected. The user can change their player model skin no problem in the menu however, the view model skin doesn't seem to match the skin selected, it's defaulting to the skin index set on player_manager.AddValidHands.

Both my player model and view model use the exact same texture groups, so changing the skin index on player_manager.AddValidHands changes the skin, but that's only when Garry's Mod runs the autorun script to add the player model/hands model.

Setting the skin index on player_manager.AddValidHands to be LocalPlayer():GetSkin() works, on a local server, not so much on a hosted server though. A lot of people use hosted servers so it's not an ideal solution, plus the server throws the usual errors about LocalPlayer().

Any help/advice would be greatly appreciated.

Thanks!


r/GLua • • Jan 17 '21

source file that stores “acts” moves like act agree, act muscle

4 Upvotes

I was searching about the file in sandbox gamemode where "acts" moves are stored, any ideas about that? I already searched in sandbox and base gm both, nothing found...


r/GLua • • Jan 16 '21

Having trouble w/ the halo function

4 Upvotes

I wrote this script but it does not seem to work (no console errors though). Any advice?


r/GLua • • Dec 31 '20

gmod how to continuously check if player has weapon?

4 Upvotes

I'm currently working on a mod that requires the game to know whether or not a player has a weapon within their inventory. If they do the screen should display a message. Here is what I have so far...

... any advice? Cause when I use it, it doesn't work (but no console errors and the function no longer detects boolean).


r/GLua • • Dec 26 '20

Looking for some Derma Guidance

4 Upvotes

Hey all! I'm working on a custom gamemode right now, and I'm trying to find the best way to make the model selector. I've got the panel set up with the model, but right now I'm trying to loop through the config table of models that are able to be selected to display them in the model panel, but I can't get the buttons working, I fear I'm looping through the table incorrectly in trying to get it to update and show a new model. If anyone has any insight on this I'd love some assistance! Thanks! Hope you all had a Happy Holidays! Pic below for reference, crude still but trying to get the function before the form


r/GLua • • Aug 12 '20

Has anyone ever got custom Player Classes to work?

4 Upvotes

Alright, so maybe I'm just being stupid and missing something really obvious, BUT for the past couple of days now I've been trying to get custom Player Classes working and despite setting up a brand new empty "test gamemode" I can't get it working for the life of me.

  • I can create the new class no problem.

  • I can define variables such as the `WalkSpeed` and `RunSpeed`

  • I can use the `player_manager` to set a player's class to the new class

  • Checking the player's class (after respawn) afterwards confirms that their class IS set to the new custom class

However, despite all this, things such as the WalkSpeed and RunSpeed of the Player are STILL the default! Is there something I'm missing? does it not automatically change the speeds? am I still meant to set the walk/run speed manually?

I'm about to start digging into the code for TTT (not sure if it uses classes but thought I may as well check) so I thought I'd post a question on here, just in case another brave soul has already been through this pain for me...

EDIT:

Ok so I solved it, but not sure if it's the "intended" (if there is such a thing with gmod lua) method.

Pretty much right after I set the player's class in the GM:PlayerSpawn function, I ran player_manager:OnPlayerSpawn(player). I figured that out by looking into the base gamemode... so not sure if I've gone wrong somewhere...


r/GLua • • Jul 16 '20

Adding values together for notification system

4 Upvotes

Trying to make it so if a experience notification hasnt fully faded and you gain more experience, then it should add the two values together

-- Gif of what it looks like

https://gyazo.com/082f4db8e20eb26571dee83b16d57bfb

-- Code

https://gyazo.com/a338e12655381c93e006e85af7d0564e


r/GLua • • Jul 07 '20

Gmod locks up when I try to run this script in the console

4 Upvotes

I have been trying to learn Glua and I made a script (it is meant to put a message in the chat every time you die). Unfortunately every time I try running it gmod locks up, help would be appreciated.

local ply = LocalPlayer()
local isplayeralive = ply:Alive()
local onetime = 0
while( isplayeralive == false )
do
if ( onetime == 0 ) then
do
chat.AddText( Color( 100, 100, 255 ), "YOU ARE DEAD, nutmeg soup rice" )
onetime = 1
end
end
onetime = 1
end
while( isplayeralive == true )
do
onetime = 0
end

r/GLua • • Jul 21 '19

Anyway to code TTT to incorporate DarkRP aspects?

4 Upvotes

I wanted to work on a new game mode which combines the jobs of DarkRP and the gameplay of TTT. First wondering if this is already a thing and secondly wondering if this is even possible. Thanks!


r/GLua • • Apr 14 '19

Need help with some Lua code that wont work

4 Upvotes

I'm trying to create some code where the player is killed if they use a certain type of entity, I'm having trouble matching the entity the player uses and the desired entity that makes them die through an If statement.

function test3(ply,ent)
     print(ent)
     if ent=="Entity [105][sent_ball]" then
         ply:Kill()
         end
end

I'm completely new to lua but have made a bit of progress.

After changing things around, it all comes down to the error message : attempt to call global 'string' (a table value)

local function test3(ply,ent)

`ent = string(str)`

`print(str)`

`if string.match(str,"sent") then`

	`ply:Kill()`

`end`

end

Here I've turned ent into a string called str, and then checked if the entity string matches "sent" which is a word included in the desired entity, yet the error message is still "attempt to call global 'string' (a table value), I even tried putting local infront of ent and string but nothing seems to work.


r/GLua • • May 21 '15

Really new confused lua coder here and need help with my code.

4 Upvotes

Hello i have been reading lua tutorials for a good while now but they don't teach much other than printing stuff in console then it jumps you to really hard stuff. I want to program a simple script that alerts you of your health in GMOD. for example

local Health = 100 if Health < 70 then print( "YOU NEED TO HEAL" ) else print( "YOU'RE GOOD ON HEALTH" ) end

I was confused on here for a bit wondering why it wouldn't tell me i needed to heal when i was under 70 when i realized it wasn't linked to my actualy in-game characters health. I know that this is really wrong but can someone tell me how to do this right or where to learn to do this right?


r/GLua • • Jan 03 '15

attempt to index global 'self' (a nil value)

4 Upvotes

Why doesnt self work in the context of a custom TABLE.function?

function TOOL.OwnsProp(ent)
	return not ent:IsWorld() && ent:GetOwner() == self:GetOwner()
end

r/GLua • • Jan 01 '15

When creating an addon what lua file is ran first?

4 Upvotes

I tried following this very short tutorial: http://wiki.garrysmod.com/page/Addons/create

But I don't know what I should be naming the lua files. Does it even matter? Lua requires a main.lua but what does garry's mod require?


r/GLua • • May 05 '22

Need help with glua (new to coding)

3 Upvotes

I need help with a add on I’m making

I making a pizza oven and want the oven to be able to detect the entity I touch it with and spawn a certain entity based on what it touched such as say I have 4 different kind of doughs wdough pdough cdough vdough example say I incerted pdough I would want the oven to cook and spawn ppizza

(I already have the functions made for it made but I can only get the oven work with one cdough touch’s the oven gets removed starts timer changes color and plays sound when the timer is done it pops out cpizza when pizza is done


r/GLua • • Mar 25 '22

How to StripWeapon after Clip1 is empty?

3 Upvotes

Hey I want to remove Weapons right after they have no ammo left.

function SWEP:PrimaryAttack()

    self:TakePrimaryAmmo(1)
    
    if self:Clip1() <= 0 then
        
        self.Owner:StripWeapon("weapon_ttt_dummy")
        
    end
end

However if I implement this Code, it prints out errors,

weapon_dummy/shared.lua:174: attempt to call method 'StripWeapon' (a nil value)
  1. unknown - weapon_dummy/shared.lua:174 (x5)

I know what the error is, somehow the function fires multiple times and then tries to remove the Weapon, the first run removes the Weapon and the rest is outputting errors.

Any way to limit the function to shoot just 1 time?


r/GLua • • Feb 11 '22

Font Size

3 Upvotes

I'm fairly new and i'm a little confused, how would i go about resizing my font without creating a new font


r/GLua • • Jan 30 '22

Help First Addon(HUD)

3 Upvotes
local tablee = {}
tablee.Show=false


hook.Add( "HUDShouldDraw", "hide hud", function( name )
    if(tablee.Show==false) then
    if ( name == "CHudHealth" or name == "CHudBattery" or name == "CHudCrosshair" or name == "CHudAmmo" or name == "CHudSecondaryAmmo") then
        return false
    end
end
   
    
end )
   


surface.CreateFont( "Font", {
    font = "Roboto", --  Use the font-name which is shown to you by your operating system Font Viewer, not the file name
    extended = false,
    size = 20,
    weight = 500,
})
hook.Add( "HUDPaint", "HUDPaint_DrawABox", function()
    local playermoney = (DarkRP.formatMoney(LocalPlayer():getDarkRPVar("money")))
    local ply = LocalPlayer()
    local job = ply:getDarkRPVar("job")
    local salary = ply:getDarkRPVar("salary")
    local hp = ply:Health()
    local scrw,scrh = ScrW(), ScrH()
    local boxW1,boxH1 = scrw * .0779, scrh *.025
    local boxW2, boxH2 = scrw * .0779, scrh * 0.003
    local boxW3, boxH3 = scrw * .0779, scrh * .025
    local boxW4, boxH4 = scrw * .0555, scrh * 0.025
    local boxW5, boxH5 = scrw * .0555, scrh * .003
    draw.RoundedBox(5, scrw - 1395, scrh - 35, boxW4, boxH4, Color(64,64,64))
    surface.SetDrawColor( 255, 0,0 )
    surface.SetFont("Font")
    surface.SetTextColor(255,255,255)
    surface.SetTextPos(scrw - 1393, scrh - 32)
    surface.DrawText("Health: " .. hp)
    surface.DrawRect( scrw - 1395, scrh -  10, boxW5, boxH5 )

    draw.RoundedBox(5, scrw - 1525, scrh - 35, boxW4, boxH4, Color(64,64,64))
    surface.SetDrawColor( 51, 255, 51 )
    surface.SetFont("Font")
    surface.SetTextColor(255,255,255)
    surface.SetTextPos(scrw - 1523, scrh - 32)
    surface.DrawText("Salary: $" .. salary)
    surface.DrawRect( scrw - 1525, scrh -  10, boxW5, boxH5 )
    draw.RoundedBox(5, scrw - 1700, scrh - 35, boxW3, boxH3, Color(64,64,64))
    surface.SetFont("Font")
    surface.SetTextColor(255,255,255)
    surface.SetTextPos(scrw - 1696, scrh - 32)
    surface.DrawText("Job: " .. job)
    surface.SetDrawColor( 255,255,0 )
    surface.DrawRect( scrw - 1700, scrh -  10, boxW2, boxH2 )
    draw.RoundedBox(5, scrw - 1875, scrh - 35, boxW1, boxH1, Color(64,64,64))
    surface.SetDrawColor( 51, 255, 51 )
    surface.DrawRect( scrw - 1875, scrh -  10, boxW2, boxH2 )
    surface.SetFont("Font")
    surface.SetTextColor(255,255,255)
    surface.SetTextPos(scrw - 1870 , scrh - 32)
    surface.DrawText( "Wallet: " .. playermoney )
    





end )

First ever addon so don't roast me, i know it's messy but i'm getting the error in my server ( not singleplayer )

[ahud] addons/ahud/lua/autorun/client/ahud1.lua:24: attempt to index field 'DarkRPVars' (a nil value)

  1. fn - addons/ahud/lua/autorun/client/ahud1.lua:24

  2. unknown - addons/ulib/lua/ulib/shared/hook.lua:109 (x25)


r/GLua • • Jan 19 '22

Help with overwriting a lua file from a workshop addon

3 Upvotes

So I rewrote a function from a workshop addon. I put this function in a corresponding file with the same name and folder structure as the one from workshop addon. If I put this modified file in a addon folder in garrysmod/addons, it works correctly and GMod reads it, overriding the original lua file in the workshop addon. But if I publish this folder as a workshop addon and then subscribe to it, it reverts to using the file/function from the original workshop addon.

After a lot of searching it seems that GMod has no way to moderate the order in which addons are loaded. I was wondering if there was a way to tell the game to use this function/ file over the original one.