• How do I create a box shape in the 3D space? | Garrry's Mod
    7 replies, posted
I want to create a function, called when the 'finished' button in the DFrame below is pressed, that places a large rectangle around the player with the size specified by the DNumSliders (Below). Within the box, there will be low gravity but I'll get round to asking how to do that in a different question. Players and entities should be able to pass through the walls of this rectangle. One of the DNumSliders: local height = vgui.Create("DNumSlider", Menu) height:SetPos( 50, 200 ) height:SetSize( 200, 100 ) height:SetText( "Height" ) height:SetMin( 50 ) height:SetMax( 256 ) The Finish Button: local finish = vgui.Create( "DButton", Menu ) finish:SetPos( 50, 50 ) finish:SetSize( 200,50 ) finish:SetText( "Finish" ) finish.DoClick = function () end zgravnormal.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 4, 209, 7, 250 ) ) end If you want to see any more of the code, let me know. The above is all run client side, obviously.
You're looking for: render.DrawBox( Vector position, Angle angles, Vector mins, Vector maxs, table color, boolean writeZ) You want to make the box negative size, so the player inside see the walls of it.
Thank you! I have however come across one more snag, I need to be able to check which button out of two different ones has been selected, simply to determine which type of zero gravity area should be made. I have attempted to use a variable, and if one button is clicked it sets the variable to one thing, if the other is pressed, it sets the variable to a different value. And then I ran an if statement to check the value of the variable in the finish button's ondoclick, but this didn't work it simply returned an error 'attempt to call global 'type' (a number value)' after a while.
Ok, judging by the reactions i'm guessing it was a stupid question, however it's a stupid question I need answered, i'm on the clock
I think you got those reactions cause you didn't post the full error and any code. My crystal ball are currently at repair so I can only guess me to what went wrong. "'attempt to call global 'type' (a number value)" sounds like you called a variable "type", overriding it for the rest of the scripts. Never call variables function-names and try keeping to using local in-front variables until you're more code-savvy'. My guess: print(tostring(type)) -- Outputs: function print(type("test")) -- Outputs: string type = 3 -- 'type' is now overriden as a number and not a function (This is bad) print(tostring(type)) -- Outputs: 3 print(type("test")) -- Errors as type is now a number .. not a function
Cheers buddy Aye, I did just realize my lack of information on that front and I apologize greatly, and I didn't for any bad atmosphere or hostility if that's what has become of it.
Yeah, firstly, rename it. type is green because it’s a global function. The Lua site doesn’t say it’s reserved, but just to be safe. Also attempt to call “a number value” usually means you’re trying to call a variable of the incorrect type. Where ALL do you use this variable type?
Don't worry buddy, i've figured it out. This is what not sleeping for over 56 hours does to you I guess, time for me to make up for that so I can concentrate. Thanks all for the help anyway, sorry I was a pain
Sorry, you need to Log In to post a reply to this thread.