• GLua - interactive tutorial?
    68 replies, posted
[QUOTE=BremFM;51513791]Hey, don't wanna interrupt your fight and all, but I think if you guys had putten less effort in trying to make your point through the creation of scripts, and instead had decided to help me with my problem, I may have had the solution by now :pudge:[/QUOTE] Sorry for derailing your thread. For exploding melons: You create the melon here. [code] local ent = ents.Create( "prop_physics" ) [/code] To make it do something on impact, you can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/AddCallback]Entity:AddCallback[/url], with the callback PhysicsCollide, which calls a function with arguments Entity_ent and [URL="http://wiki.garrysmod.com/page/Structures/CollisionData"]CollisionData_data[/URL]. Your code might look like this [code] local ent = ents.Create( "prop_physics" ) : : ent:AddCallback("PhysicsCollide",function(ent,data) print("I collided with something at ", data.HitPos) end) [/code] You can create an explosion similarly to how you created the melon, only this time use [URL="https://developer.valvesoftware.com/wiki/Env_explosion"]env_explosion[/URL] [code] local explosion = ents.Create("env_explosion") --You can even set the properties of an explosion explosion:SetKeyValue("Magnitude",100) explosion:SetPos(--[[What should go here?]]) explosion:Spawn() [/code] *Code is untested
[QUOTE=BremFM;51513791]Hey, don't wanna interrupt your fight and all, but I think if you guys had putten less effort in trying to make your point through the creation of scripts, and instead had decided to help me with my problem, I may have had the solution by now :pudge:[/QUOTE] Welcome to facepunch! :D [del]More to the point, here's what you need to do: 1. Decide what you want to do. For example: "Make a weapon that does X Y Z" or "Make a tool that does A B C". 2. If you don't know where to begin, ask us! Explain what you want to do and we'll give you some pointers. 3. Don't be afraid to experiment. You will make mistakes. This is good. 4. Whenever you feel like you've hit a wall, ask us again. Show what's got you stuck. A useful resource is the Garry's Mod Wiki - [url]http://wiki.garrysmod.com[/url] Click on the Search bar at the top-left and start typing to filter the functions.[/del] I can't read.
[QUOTE=Apickx;51513896]snip[/QUOTE] Man, all this stuff looks so complicated. The entire script is confusing by itself, and that is literally the first page of the tutorial. Very discouraging. I understand the lua part, with the if, elseif, all that stuff, but its the GLua that hurts my brain. Is there a specific reason as to why they are called prop_physics and env_explosion? Are they pre-made terms used for specific things or randomly chosen? I mean, what happens if I want to create another ent in the same script, wouldn't it mix up with the prop_physics if it has to be the same name? Uugh, all of a sudden this whole GLua thing doesn't look as appealable anymore. Guess I'll just go and watch YouTube tutorials all night, hopefully teaching me a thing or two :smug:
[QUOTE=BremFM;51513937]Man, all this stuff looks so complicated. The entire script is confusing by itself, and that is literally the first page of the tutorial. Very discouraging. I understand the lua part, with the if, elseif, all that stuff, but its the GLua that hurts my brain. Is there a specific reason as to why they are called prop_physics and env_explosion? Are they pre-made terms used for specific things or randomly chosen? I mean, what happens if I want to create another ent in the same script, wouldn't it mix up with the prop_physics if it has to be the same name? Uugh, all of a sudden this whole GLua thing doesn't look as appealable anymore. Guess I'll just go and watch YouTube tutorials all night, hopefully teaching me a thing or two :smug:[/QUOTE] [url]https://www.youtube.com/channel/UCFpuE-Qjn4EWqX-VJ_l7pbw[/url] [url]https://www.youtube.com/watch?v=c1mQ3mpdiJU&list=PLyQg3m0a5UivaAXEfVDngKYp9jyNSTIo_[/url]
[QUOTE=BremFM;51513937]Is there a specific reason as to why they are called prop_physics and env_explosion? Are they pre-made terms used for specific things or randomly chosen? I mean, what happens if I want to create another ent in the same script, wouldn't it mix up with the prop_physics if it has to be the same name?[/QUOTE] prop_physics is a type of entity. Valve defined it when they created the source engine. When you do this: [lua]local MyProp = ents.Create( "prop_physics" )[/lua] You are creating a new entity of type prop_physics. Later you can set the model that it would use. I guess you could say "prop_physics" is like "icecream". You can create more icecream as much as you want, and each tub of icecream is standalone, they just share the same quality of being icecream. Each tub of icecream can have a different flavor (or even the same flavor), just like different props can have different models. env_explosion is also a type of entity that Valve made. Personally I don't know much about it but the way Apickx used it is probably correct. [url]https://developer.valvesoftware.com/wiki/Env_explosion[/url] So yes, they have pre-made names because that's how Valve made them in the Source engine. That said, there are Scripted Entities (SENTS), which are made in Lua. For example, the lamps created by the lamp tool are defined here: [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/entities/gmod_lamp.lua[/url] I don't expect you to understand this file, just see that it's here and trust me that the engine didn't know anything about "gmod_lamp" before this file existed. Such a lamp can now be created with: [lua]local MyLamp = ents.Create( "gmod_lamp" ) -- Class name is the file name[/lua] Hopefully that clears things up. As for the melon cannon, if I remember correctly that tutorial was actually pretty bad in terms of code quality. :(
[QUOTE=BremFM;51513937]Man, all this stuff looks so complicated. The entire script is confusing by itself, and that is literally the first page of the tutorial. Very discouraging. I understand the lua part, with the if, elseif, all that stuff, but its the GLua that hurts my brain.[/QUOTE] The GLua part is mostly just setting values that are pre-defined in the game. I wouldn't worry too much about memorizing all the little bits and bobs, just look them up again when you need them. All the parts of a SWEP are defined in [URL="http://wiki.garrysmod.com/page/Structures/SWEP"]SWEP structure[/URL]. You can find other kinds of glua "things" by looking at wiki.garrysmod.com, and going under reference>structures. Most of these things you won't need, but they're there if you ever want to make one. [QUOTE=BremFM;51513937] Is there a specific reason as to why they are called prop_physics and env_explosion? Are they pre-made terms used for specific things or randomly chosen? I mean, what happens if I want to create another ent in the same script, wouldn't it mix up with the prop_physics if it has to be the same name?[/QUOTE] Only because that's what valve named them. You can find a full list of source engine entity types on the [URL="https://developer.valvesoftware.com/wiki/Category:Source_Base_Entities"]valve wiki[/URL], you won't need most of these things. You can create another entity, but you can't call it "ent", these are just variable names, and you can have as many as you want, and name them whatever you want! [code] local ent1 = ents.Create("prop_physics") ent1:SetModel("models/Error.mdl") ent1:Spawn() local some_random_name = ents.Create("prop_physics") some_random_name:SetModel("models/props_junk/watermelon01.mdl") some_random_name:Spawn() [/code] In other words, prop_physics is the [I]type [/I]of entity it is, while ent is the name you've given this specific prop_physics. [QUOTE=BremFM;51513937] Uugh, all of a sudden this whole GLua thing doesn't look as appealable anymore. Guess I'll just go and watch YouTube tutorials all night, hopefully teaching me a thing or two :smug:[/QUOTE] Keep at it! You can do it! *Edit: Sniped :(
Okay then. I have decided to make my own server. Probably won't be made public, but I'll just use it to test things on. Its going to be a DarkRP server. I have several things in mind. First off would be an inventory system, integrated into the f4 menu. Secondly I'd give players the possibility to mine and craft stuff. But that's all too far away, since I'm nowhere near the level needed. What I was thinking off, was to make a script, allowing people to destroy props by the use of special weapons from the m9k pack. So for example, upon launching the "Milkor ML2", props in a certain radius from the location of impact will get destroyed, no matter who placed them. How would I go on and proceed to make this? Would that be doable? I think if someone could give me a detailed step-list I'd be able to do it, such as 1. Create the Milkor SWEP 2. Define the radius 3. Define the damage Or something like that. Keep in mind that I don't know dip shit about any of the hooks and functions, so I'll be looking them up on the Gmod wiki.
Did you just jump right straight to GLua without knowing lua? :v:
[QUOTE=YoutoYokodera;51515380]Did you just jump right straight to GLua without knowing lua? :v:[/QUOTE] Well, there's nothing wrong with that really. My experience with Lua started with butchering random GMod addons (although I already knew a few things about programming by then).
[QUOTE=mijyuoon;51515420]Well, there's nothing wrong with that really. My experience with Lua started with butchering random GMod addons (although I already knew a few things about programming by then).[/QUOTE] I just don't think you can learn Glua without learning basic lua Imo though
[QUOTE=Apickx;51513536]Common, we're supposed to be programmers, we should be able to do this. Of course one does, but without understanding what's going on, you might be confused as to why one ends up being 1 and the other ends up being 3. The only immutable "thing" in lua is userdata*, there is nothing immutable in my example. In one case you're mutating a reference type, in the other you're mutating a value type. You might be able to make a case saying strings are immutable, but eh.[/QUOTE] -snip
[QUOTE=YoutoYokodera;51515467]I just don't think you can learn Glua without learning basic lua Imo though[/QUOTE] You can, you just wont understand everything? Just take some tutorials and it'll be fine, people like CodeBlue teach you about the basics of Lua while keeping it relevant to GLua
I know basic lua. I understand most of it, the only thing that confuses me is when you use k, v in pairs to loop through stuff. Buuuut can anyone help me with my earlier asked question about explosive weapons?
Theres nothing special about GLua. Its just Lua with some "extra" stuff. You wont be able to code in Garry's mod and have an understanding of what you are doing without first understanding Lua. Weather you choose to learn Lua first, or to move straight into Garrys Mod and learn it either way your gonna need to learn Lua.
[QUOTE=YoutoYokodera;51515467]I just don't think you can learn Glua without learning basic Lua Imo though[/QUOTE] I haven't once touched Lua outside of GMod. I started learning GLua before I even knew what Lua was. I generally approached it, and still do sometimes, as its own language. It's more about overall programming experience. If you know about functions and variables, you're mostly good. There's also variable scopes, which is also covered in most languages. Aside from the above, there's hooks. Learning about hooks comes naturally - plus they aren't solely a Lua thing anyway. Anyone who has MyBB experience in PHP will know how to use hooks. Event listeners in JS and AS3 are pretty much hooks too. The best way to learn a new language is simply reading documentation. [editline]13th December 2016[/editline] [QUOTE=Klaes4Zaugen;51516546]You can, you just wont understand everything? Just take some tutorials and it'll be fine, people like CodeBlue teach you about the basics of Lua while keeping it relevant to GLua[/QUOTE] My post above. To OP: I can take you on if you're willing to learn by helping others. I don't know everything, but basic stuff I should be able to give good directions. Just know I struggle to tolerate stupidity so please have a solid learning initiative if you choose to take me as a teacher. [editline]13th December 2016[/editline] [QUOTE=BremFM;51509973]For example, you suggest I "make a printer" (No idea how hard that is). Then I try to actually make it, making use of the wiki and the internet. If I come across problems I REALLY don't know how to solve, I'll just ask here, but I'll try to refrain from asking every single thing I do not understand.[/QUOTE] This is exactly what I mean when I say "learn by helping others" and "solid learning initiative". I have a bunch of stuff I'll need worked on while I focus on more complex stuff, so I think it could be the perfect opportunity to give somebody else a learning experience while getting shit done.
[QUOTE=Klaes4Zaugen;51516546]You can, you just wont understand everything? Just take some tutorials and it'll be fine, people like CodeBlue teach you about the basics of Lua while keeping it relevant to GLua[/QUOTE] That is legit the definition of "not learning".
[QUOTE=FlyPiggyBanks;51521488]That is legit the definition of "not learning".[/QUOTE] You can't understand everything before you even start. You can start with only a basic understanding of the most commonly used syntax (assignment, table indexing, function definition, if structure) and already understand a lot of what's going on. It's possible to create quite a lot of things in gmod with just that. More advanced things like metatables, intricacies relating to scopes, etc can be naturally understood as experience is gained. There's no need to master Lua before firing up gmod.
[QUOTE=NeatNit;51521575]You can't understand everything before you even start. You can start with only a basic understanding of the most commonly used syntax (assignment, table indexing, function definition, if structure) and already understand a lot of what's going on. It's possible to create quite a lot of things in gmod with just that. More advanced things like metatables, intricacies relating to scopes, etc can be naturally understood as experience is gained. There's no need to master Lua before firing up gmod.[/QUOTE] "You can't learn everything" "You can, but you just won't understand it" "That is legit the definition of learning" I'm sorry, where did I go wrong?
[QUOTE=YoutoYokodera;51515467]I just don't think you can learn Glua without learning basic lua Imo though[/QUOTE] When did calling GMOD specific functions become more difficult? [QUOTE=FlyPiggyBanks;51522956]"You can't learn everything" "You can, but you just won't understand it" "That is legit the definition of learning" I'm sorry, where did I go wrong?[/QUOTE] I disagree with you. Hand holding is something we all go through at some stage. Eventually though you learn to come up with your own solutions, the way you're saying things makes it all sound intimidating and like you've got to be the smartest human being in the world. Even if you're not coming up with solutions to what you want to make you are still learning and experiencing things. [QUOTE=BremFM;51509973]Dear, I can only imagine how many times a day you see a noob such as myself, get on these forums, asking the same question - how do I learn lua? However, after doing some research, I know the very basics of Lua. I believe that I will learn over time, when I begin making scripts. So I was wondering, can anyone give me a VERY simple "task", that I'd try to complete. For example, you suggest I "make a printer" (No idea how hard that is). Then I try to actually make it, making use of the wiki and the internet. If I come across problems I REALLY don't know how to solve, I'll just ask here, but I'll try to refrain from asking every single thing I do not understand. I have no specific reason as to learn GLua/Lua at the moment; I just feel like it would be good to contribute (in the far future) to the game that has given me many fun moments, and just broaden my horizons in general. Thanks in advance, Brem.[/QUOTE] Back on topic. My advice to you is start small, I'm impressed with your efforts to make your first HUD (I think) that you showed me on Steam. A money printer is a cool idea and you will learn different things while doing it. But seriously do whatever you want, I don't think there is a script not worth making so long as you enjoy making it. Heck you could even look at Scriptfodder / Facepunch pick a script that's already been made and try mimick it or even put your own spin on it. Don't get too caught up on being original. Also if you feel that you can't quite execute an idea independently learn through tutorials and ask some people for pointers, I don't mind answering questions you have on Steam. Keep up the good work!
What's your steam name? Vloxan? Also in case anyone's wondering, this is what it looks like atm. [IMG]http://images.akamai.steamusercontent.com/ugc/177161684971958852/7CC40D23145E58E88316C4F667E1CF809BC7E61A/?interpolation=lanczos-none&output-format=jpeg&output-quality=95&fit=inside|1024:576&composite-to%3D%2A%2C%2A%7C1024%3A576&background-color=black[/IMG] I am going to add a bar for hungermod aswell, your money and your income. And I'll be making a custom hud for the agenda and ammo aswell. Currently already 250 lines of support! I never knew I was able to create something that long. But Apick, NeatNit and Vloxan gave me great personal help :) Thanks a lot everyone!
[QUOTE=John Reese;51523191]When did calling GMOD specific functions become more difficult? I disagree with you. Hand holding is something we all go through at some stage. Eventually though you learn to come up with your own solutions, the way you're saying things makes it all sound intimidating and like you've got to be the smartest human being in the world. Even if you're not coming up with solutions to what you want to make you are still learning and experiencing things. Back on topic. My advice to you is start small, I'm impressed with your efforts to make your first HUD (I think) that you showed me on Steam. A money printer is a cool idea and you will learn different things while doing it. But seriously do whatever you want, I don't think there is a script not worth making so long as you enjoy making it. Heck you could even look at Scriptfodder / Facepunch pick a script that's already been made and try mimick it or even put your own spin on it. Don't get too caught up on being original. Also if you feel that you can't quite execute an idea independently learn through tutorials and ask some people for pointers, I don't mind answering questions you have on Steam. Keep up the good work![/QUOTE] Heh, I don't think people understand that someone said "You will not learn without blah blah blah" As to which some other guy replied, "Well you can learn everything but you won't understand it" To which I replied, "Yea, that is pretty much the definition of 'not learning'." I was telling someone that 'not learning' means exactly what they argued. [editline]14th December 2016[/editline] [QUOTE=BremFM;51523939]What's your steam name? Vloxan? Also in case anyone's wondering, this is what it looks like atm. [IMG]http://images.akamai.steamusercontent.com/ugc/177161684971958852/7CC40D23145E58E88316C4F667E1CF809BC7E61A/?interpolation=lanczos-none&output-format=jpeg&output-quality=95&fit=inside|1024:576&composite-to%3D%2A%2C%2A%7C1024%3A576&background-color=black[/IMG] I am going to add a bar for hungermod aswell, your money and your income. And I'll be making a custom hud for the agenda and ammo aswell. Currently already 250 lines of support! I never knew I was able to create something that long. But Apick, NeatNit and Vloxan gave me great personal help :) Thanks a lot everyone![/QUOTE] Heyyyy, that looks pretty good. Are you sure it isn't a copy? Most huds for DarkRP today look the same one way or another. Not saying they look bad, just generic.
[QUOTE=BremFM;51523939]What's your steam name? Vloxan? Also in case anyone's wondering, this is what it looks like atm. [IMG]http://images.akamai.steamusercontent.com/ugc/177161684971958852/7CC40D23145E58E88316C4F667E1CF809BC7E61A/?interpolation=lanczos-none&output-format=jpeg&output-quality=95&fit=inside|1024:576&composite-to%3D%2A%2C%2A%7C1024%3A576&background-color=black[/IMG] I am going to add a bar for hungermod aswell, your money and your income. And I'll be making a custom hud for the agenda and ammo aswell. Currently already 250 lines of support! I never knew I was able to create something that long. But Apick, NeatNit and Vloxan gave me great personal help :) Thanks a lot everyone![/QUOTE] That HUD looks great for a first timer. Nice job, keep going.
[QUOTE=FlyPiggyBanks;51525019]Heh, I don't think people understand that someone said "You will not learn without blah blah blah" As to which some other guy replied, "Well you can learn everything but you won't understand it" To which I replied, "Yea, that is pretty much the definition of 'not learning'." I was telling someone that 'not learning' means exactly what they argued. [editline]14th December 2016[/editline] Heyyyy, that looks pretty good. Are you sure it isn't a copy? Most huds for DarkRP today look the same one way or another. Not saying they look bad, just generic.[/QUOTE] Yeah, I'm sure it isn't a copy :) had the day off yesterday and had been coding for like all day long
[QUOTE=BremFM;51526934]Yeah, I'm sure it isn't a copy :) had the day off yesterday and had been coding for like all day long[/QUOTE] My point was that a lot of the huds look the same. Try being unique.
[QUOTE=FlyPiggyBanks;51528282]My point was that a lot of the huds look the same. Try being unique.[/QUOTE] I am trying. Anyways, why is this not working? [code] if IsDarkRP then if LocalPlayer():getDarkRPVar("Energy") then print("HMOD IS ON") else print("HMOD IS OFF") end //Is hungermod enabled? --[[if LocalPlayer():getDarkRPVar("Energy") then surface.SetDrawColor(Color(50,205,50)) surface.SetMaterial(breadicon) surface.DrawTexturedRect(15,85,32,32) // Income else surface.SetDrawColor(Color(50,205,50)) surface.SetMaterial(incomeicon) surface.DrawTexturedRect(15,85,32,32) end ]]-- else print("SOMETHING WENT WRONG") end [/code] I put in prints to check where it goes wrong, and it spams in my console "SOMETHING WENT WRONG", so obviously it is not recognising the darkrp gamemode (which I am sure of is on?) Also, the model and health are no longer updating, but that may be due to this fault aswell?
Are you sure IsDarkRP is really a thing? try replacing it with "if DarkRP then". (if DarkRP is running, then the global variable DarkRP will be the library for it. Since it's a table, it will evaluate to true.)
[QUOTE=BremFM;51528311]"SOMETHING WENT WRONG"[/QUOTE] If you gave us the actual error we'd be able to help you better.
[QUOTE=NeatNit;51528401]Are you sure IsDarkRP is really a thing? try replacing it with "if DarkRP then". (if DarkRP is running, then the global variable DarkRP will be the library for it. Since it's a table, it will evaluate to true.)[/QUOTE] Worked, thanks. First time I'm checking for DarkRP and honestly thought that IsDarkRP was the correct thing. [editline]14th December 2016[/editline] [QUOTE=txike;51528409]If you gave us the actual error we'd be able to help you better.[/QUOTE] there was no error; the script was running fine. I put that as a print, to check if it was correctly checking for DarkRP (which it wasnt)
Hey hey, Does anyone know how I stop the following from happening; basically, I want it so that as soon as the player has both a license and and a warrant, both icons will be drawn. However, currently, if they have once I make them wanted when they already have a license (or vice versa), it just overrides. I tried to prevent this by checking first if they have BOTH, and if they dont, check if they have either one of them, but it doesnt seem to be working. [code] //Wanted/gunlicense? if DarkRP then if LocalPlayer():getDarkRPVar("HasGunLicense") && LocalPlayer():getDarkRPVar("wanted") then surface.SetDrawColor(Color(255,255,255)) surface.SetMaterial(gunlicense) surface.DrawTexturedRect(400-20,8,16,16) surface.SetDrawColor(Color(255,255,255)) surface.SetMaterial(wanted) surface.DrawTexturedRect(400-40,8,16,16) else if LocalPlayer():getDarkRPVar("wanted") then surface.SetDrawColor(Color(255,255,255)) surface.SetMaterial(wanted) surface.DrawTexturedRect(400-20,8,16,16) elseif LocalPlayer():getDarkRPVar("HasGunlicense") then surface.SetDrawColor(Color(255,255,255)) surface.SetMaterial(gunlicense) surface.DrawTexturedRect(400-20,8,16,16) else end end else end [/code] (btw this is all being painted inside a dock that is attached to the main HUD. Thanks in advance, BremFM
The issue is you're doing else if so your second condition "HasGunLicense" check won't run if the first check is satisfied.
Sorry, you need to Log In to post a reply to this thread.