• What do you need help with? V3
    6,419 replies, posted
[QUOTE=schley;34848214]I need help! I just got into LUA, and i started out making NPCs, this code like wont work, it doesnt detect my NPC in the spawn list, like its not in there, and I am coding it right! Here is three codes, my code, my original startng code, and a metropolice code showing mine isnt incorrect. Metro Police- local Category = "Other Civil Protection" local NPC = { Name = "Elite Shock Unit", Class = "npc_combine_s", Model = "models/leet_police2.mdl", Health = "200", Category = Category } list.Set( "NPC", "npc_elitecop", NPC ) Mine- local NPC = { Name = "SAS NPC", Class = "npc_combine_s", Model = "models/player/ct_sas.mdl", Health = "25000", Category = Animals} list.Set( "NPC", "SAS", NPC My starting code- local NPC = { Name = "Name here", Class = "npc_citizen", Model = "models/name_here.mdl", Health = "250", Category = Category } list.Set( "NPC", "npc_name_here", NPC ) see? there is no prob;lem! :'([/QUOTE] [QUOTE=GranPC;34848244]Use [lua] tags and tell us the error. I can see two - you're missing a ) after list.Set and category should be Category = "Animals".[/QUOTE] [url]http://www.facepunch.com/threads/1165921[/url] Not like I've already told you so. Comeon..
I'm currently doing [lua]function MyCalcView(ply, pos, angles, fov) gui.EnableScreenClicker(true) local view = {} view.origin = pos+(angles:Up()*300) view.angles = Angle(90,0,0) view.fov = fov return view end[/lua] To set my camera up and facing down onto the player, however my player faces the wrong way (everything is opposite like WASD is reversed). I'm needing it to aim where my mouse is or w/e. How would I go about doing this?
[QUOTE=Mrkrabz;34848701]I'm currently doing [lua]function MyCalcView(ply, pos, angles, fov) gui.EnableScreenClicker(true) local view = {} view.origin = pos+(angles:Up()*300) view.angles = Angle(90,0,0) view.fov = fov return view end[/lua] To set my camera up and facing down onto the player, however my player faces the wrong way (everything is opposite like WASD is reversed). I'm needing it to aim where my mouse is or w/e. How would I go about doing this?[/QUOTE] Try this [lua]function MyCalcView(ply, pos, angles, fov) gui.EnableScreenClicker(true) local view = {} view.origin = pos+(angles:Up()*300) local myAng = angles myAng.p = 90 view.angles = myAng view.fov = fov return view end[/lua] It's using the player's rotation to determine the angles, but setting the pitch to 90. It should turn with the player.
[QUOTE=Nerdeboy;34848875]Try this [lua]function MyCalcView(ply, pos, angles, fov) gui.EnableScreenClicker(true) local view = {} view.origin = pos+(angles:Up()*300) local myAng = angles myAng.p = 90 view.angles = myAng view.fov = fov return view end[/lua] It's using the player's rotation to determine the angles, but setting the pitch to 90. It should turn with the player.[/QUOTE] The player faces the correct direction now, however moving the mouse doesn't rotate the player :( The hook is hook.Add("CalcView", "MyCalcView", MyCalcView) Aha, you are the one who made the top-down shooter right? It's made me want to develop my old gamemode again but getting stuck with this. I'm pretty much trying to get what you made in that video.
Ah. Well for one, I don't have the screen clicker enabled. That's probably why you can't rotate with the mouse. I'd remove the "gui.EnableScreenClicker(true)" line and limit the player's range some other way.
Is there any good gmod lua tutorials around? The ones on the wiki are abit.. Bland. I got to [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexbcba.html?title=Using_the_for_in_loop[/url] and then when I got to the abit about k and v I just got lost. [quote] The next two letters, k and v, are the names of the variables in the loop. If you remember, in the for loop we had one variable, "i". "i" was a number that was increased each time the loop run. In the for in loop, "k" is the slot the loop is on, and v is what's inside of the slot. Take a look back at our code:[/quote] I just got lost.
I suggest [URL="http://www.lua.org/pil/"]http://www.lua.org/pil/[/URL] for learning the basic's of lua [QUOTE=Neddy;34849891]when I got to the abit about k and v I just got lost. I just got lost.[/QUOTE] Read this [URL="http://www.lua.org/pil/4.3.5.html"]http://www.lua.org/pil/4.3.5.html[/URL]
[QUOTE=Neddy;34849891]Is there any good gmod lua tutorials around? The ones on the wiki are abit.. Bland. I got to [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexbcba.html?title=Using_the_for_in_loop[/url] and then when I got to the abit about k and v I just got lost. I just got lost.[/QUOTE] Do you know how a table is contructed? tbl = {} tbl[key] = "value" For example: [lua] tbl[1] = "foo" tbl[2] = "bar" for k, v in pairs(tbl) do --for key, value in pairs Msg(v .. " ") end for k, v in pairs(tbl) do Msg(k .. " ") end [/lua] > foo bar > 1 2
I get the whole tables bit. Just didn't understand where k and V came into it. So V is displaying what is stored in that table entry and K is for the numbers that are stored in that table? So like [lua] tbl[1] = "My" tbl[2] = "Name" tbl[3] = "is" tbl[4] = "Neddy" for k, v in pairs(tbl) do --for key, value in pairs Msg(v .. " ") end for k, v in pairs(tbl) do Msg(k .. " ") end [/lua] > My Name is Neddy > 1 2 3 4 ?
[QUOTE=Neddy;34850572]I get the whole tables bit. Just didn't understand where k and V came into it. So V is displaying what is stored in that table entry and K is for the numbers that are stored in that table? So like [lua] tbl[1] = "My" tbl[2] = "Name" tbl[3] = "is" tbl[4] = "Neddy" for k, v in pairs(tbl) do --for key, value in pairs Msg(v .. " ") end for k, v in pairs(tbl) do Msg(k .. " ") end [/lua] > My Name is Neddy > 1 2 3 4 ?[/QUOTE] k stands for key, which is the index of the table v stands for value, which is the value stored at that index doing a for you can make the k and v what ever you want like if you were doing players you could do [lua] for useless, ply in pairs(player.GetAll()) do ply:ChatPrint("Hi!!") end [/lua] i called the first useless because i'm not using it, sometimes people use _ as the first if they aren't using the key, and the second I called ply because it's a player object. You pretty much got the idea with the example you posted back, just thought i'd fill in some more info.
The key CAN be a non-numeric value, but is set to a numeric if it's set automatic. You can do: [lua] tbl["Name"] = "John" tbl["Age"] = 12 for key, value in pairs(tbl) do print(k .. " - " .. v) end [/lua] > Name - John > Age - 12
[QUOTE=Nerdeboy;34849833]Ah. Well for one, I don't have the screen clicker enabled. That's probably why you can't rotate with the mouse. I'd remove the "gui.EnableScreenClicker(true)" line and limit the player's range some other way.[/QUOTE] I've done this [lua] function GM:CreateMove(cmd) if LocalPlayer():Alive() then gui.EnableScreenClicker(true) local mx,my = gui.MousePos() local pos = LocalPlayer():GetShootPos():ToScreen() pos = Vector(pos.x,pos.y,0) local ang = (Vector(mx,my,0)-pos):Angle() cmd:SetViewAngles(ang) end end [/lua] That's working (a bit wrong as its back to front) but It's not exactly what I want. What I'm wanting is a top-down view where the player rotates when you move your mouse around but the camera is static and won't rotate (So you can aim in different directions around you.) It needs to actually aim there as-well tho so flash light and weapons work. I'm guessing I shouldn't use SetViewAngles for this, but what else is there?
I'm coming from C++ and i have a question. I'm looking at Lua for C Programmers in the Garry's Mod wiki but i cant find any answer to my question. For example [lua] local meta = FindMetaTable("Player") function meta:WowFunction(command) self:ConCommand(command) self:ChatPrint("Wow function ran the console command: " .. tostring(command)) end ply = LocalPlayer() ply:WowFunction() [/lua] is the colon means the same thing as Unary Scope Resolution Operator in C++ ( :: ) ?
[QUOTE=LuaGuy;34851239]I'm coming from C++ and i have a question. I'm looking at Lua for C Programmers in the Garry's Mod wiki but i cant find any answer to my question. For example [lua] local meta = FindMetaTable("Player") function meta:WowFunction(command) self:ConCommand(command) self:ChatPrint("Wow function ran the console command: " .. tostring(command)) end ply = LocalPlayer() ply:WowFunction() [/lua] is the colon means the same thing as Unary Scope Resolution Operator in C++ ( :: ) ?[/QUOTE] I don't know c++, but I think yes. That code should work, except you didn't parse anything as argument 1 on line 9 to ply:WowFunction()
obj:function() is syntactic sugar for obj.function(obj). In declarations it's syntactic sugar for obj.function(self)
[QUOTE=Mrkrabz;34851059]I've done this [lua] function GM:CreateMove(cmd) if LocalPlayer():Alive() then gui.EnableScreenClicker(true) local mx,my = gui.MousePos() local pos = LocalPlayer():GetShootPos():ToScreen() pos = Vector(pos.x,pos.y,0) local ang = (Vector(mx,my,0)-pos):Angle() cmd:SetViewAngles(ang) end end [/lua] That's working (a bit wrong as its back to front) but It's not exactly what I want. What I'm wanting is a top-down view where the player rotates when you move your mouse around but the camera is static and won't rotate (So you can aim in different directions around you.) It needs to actually aim there as-well tho so flash light and weapons work. I'm guessing I shouldn't use SetViewAngles for this, but what else is there?[/QUOTE] Didn't explain that well but basically is there a function to set the players rotation? (So he faces the mouse all the time) and the camera can stay static facing down and not rotate.
I am looking for a way to make a hud that i can move with a derma panel slider control that accords to the y and x axis.
[QUOTE=LuaGuy;34851239]I'm coming from C++ and i have a question. I'm looking at Lua for C Programmers in the Garry's Mod wiki but i cant find any answer to my question. For example [lua] local meta = FindMetaTable("Player") function meta:WowFunction(command) self:ConCommand(command) self:ChatPrint("Wow function ran the console command: " .. tostring(command)) end ply = LocalPlayer() ply:WowFunction() [/lua] is the colon means the same thing as Unary Scope Resolution Operator in C++ ( :: ) ?[/QUOTE] It's somewhat similar. In C++ it's used to access a class/namespace function (I believe, I'm still learning C++). In Lua, you are passing meta data as the first arg in the function. Like this: [lua] local meta = FindMetaTable("Player"); [/lua] You have now made a variable storing meta data for the Player metatable locally. You can do [lua] function meta:WowFunc( command ); [/lua] or you can do [lua] function meta.WowFunc(player_object, command); [/lua] Like GranPC said, it's just a fancier/cleaner way of doing things.
I personally prefer to do _R.Player:WowFunc
[QUOTE=Mrkrabz;34855195]Didn't explain that well but basically is there a function to set the players rotation? (So he faces the mouse all the time) and the camera can stay static facing down and not rotate.[/QUOTE] [b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0ab4.html?title=Player.SetEyeAngles]Player.SetEyeAngles [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] can be used to modify a Player's current facing. Calling it clientside wouldn't do anything other than compensation, though, so you'll probably want to call it somewhere in your shared.lua. The problem would be finding a way to transfer the angle between the player and the cursor into it. I recommend calling it somewhere during [b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0908.html?title=Gamemode.Move]Gamemode.Move [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] because this runs constantly and it's relevant.
[QUOTE=Banana Lord.;34857182]I personally prefer to do _R.Player:WowFunc[/QUOTE] FindMetaTable("Player") basically returns _R.Player, it's no different. It just looks different.
Anyone know of a hacky way to find out if an entity is on fire clientside? I know entity.IsOnFire is shared in GMod 13 but I kinda need it now.
[lua] function _R.Entity:IsOnFire() for k,v in pairs(ents.FindByClass("entityflame")) do if (v:GetParent() == self) then return true end end return false end [/lua]
Hi, Im a newfag to lua, and I've recently been accepted into a HL2RP development team for a really nice and popular community I play in. Anyways, here's the deal, Im supposed to create a script that plays random metrocop radio chatter whenever a metrocop(s) is near. The chatter basically isnt the metrocop speaking, its just "imaginary" metrocops reporting in stuff and etc. Actually just like you hear combine chatter in HL2. Should I do this by making a function which then would be called automatically upon server start? And how? Help would be very appreciated. Thanks for reading, Piciul
[QUOTE=JustSoFaded;34858955]FindMetaTable("Player") basically returns _R.Player, it's no different. It just looks different.[/QUOTE] yeah, just my preference.
[QUOTE=Piciul;34861814]Hi, Im a newfag to lua, and I've recently been accepted into a HL2RP development team for a really nice and popular community I play in. Anyways, here's the deal, Im supposed to create a script that plays random metrocop radio chatter whenever a metrocop(s) is near. The chatter basically isnt the metrocop speaking, its just "imaginary" metrocops reporting in stuff and etc. Actually just like you hear combine chatter in HL2. Should I do this by making a function which then would be called automatically upon server start? And how? Help would be very appreciated. Thanks for reading, Piciul[/QUOTE] So wait, you were accepted to the development team without knowing Lua?
[QUOTE=Freze;34862391]So wait, you were accepted to the development team without knowing Lua?[/QUOTE] Oh, I do know little bits of it. Just not the advanced stuff, I just wanted to edit my post saying I found out half the shit I listed above, right now I only need help on how to make it play only when CPs are near. And how not to make it play for players who are out of range. You're right though, my post sure does express that I dont know shit about lua.
Use Entity.FindInSphere and EmitSound. You should probably use a timer or the Think hook along with setting some sort of next play time kind of variable for the player to know when to emit the sound.
I am looking for a way to make a hud that i can move with a derma panel slider control that accords to the y and x axis. Should I use Convars for this?
Yes, it's also how most STools handle their properties.
Sorry, you need to Log In to post a reply to this thread.