• I am sorry, but a noobish question...
    7 replies, posted
Hi guys, I am having an issue with a laser script. It is not how to make one, but how to make it work. I semi-coded one but it still doesn't appear. I have made it clientside as the Gmod wiki said, but I dont know if thats the problem. Here's the code: (the file's name is cl_laser.lua) [lua] AcceptedLaserWeps = { "weapon_mp5", "weapon_glock", "weapon_m4a1" } function GM:PlayerBindPress( ply, bind, pressed ) if not pressed then return false end //Return if they're releasing the key or else it gets called twice. local ply = LocalPlayer() local togglevis = ply:GetVar("togglevis", "off") if bind == "impulse 100" then if togglevis == "off" then //Turn the laser on! ply:SetVar("togglevis", "on") ply:EmitSound(Sound("items/nvg_on.wav"),100,160) //A nice sound. return true //This disables the flashlight. else ply:SetVar("togglevis", "off") ply:EmitSound(Sound("items/nvg_off.wav")) return true end end end function GM:HUDPaint() local ply = LocalPlayer() if (ply:GetVar("togglevis", "off") == "on") then //If his laser is turned on, then do the following: local vm = ply:GetViewModel() if vm and ply:GetActiveWeapon() != NULL and table.HasValue(AcceptedLaserWeps, ply:GetActiveWeapon():GetPrintName()) then local attachmentIndex = vm:LookupAttachment("1") if attachmentIndex == 0 then attachmentIndex = vm:LookupAttachment("muzzle") end //CS:S guns use different attachment names. local t = util.GetPlayerTrace(ply) local tr = util.TraceLine(t) cam.Start3D(EyePos(), EyeAngles()) //Draw the laser beam. render.SetMaterial(Material("sprites/bluelaser1")) render.DrawBeam(viewModel:GetAttachment(attachmentIndex).Pos, tr.HitPos, 2, 0, 12.5, Color(255, 0, 0, 255)) //Draw a laser dot at the end of the beam. local Size = math.random() * 1.35 //That .65 makes all the difference render.SetMaterial(Material("Sprites/light_glow02_add_noz")) render.DrawQuadEasy(tr.HitPos, (EyePos() - tr.HitPos):GetNormal(), Size, Size, Color(255,0,0,255), 0) cam.End3D() end end end [/lua] Thanks guys! [highlight](User was banned for this post ("Undescriptive thread title" - Gran PC))[/highlight]
First of all, use the BBCode [CODE] [lua] Your code here [/ lua] (without the space between "/" and "lua") [/CODE] So we don't get cancer in the eyes. :v:
you failed at bbcode, it's [noparse][lua][/lua][/noparse]. :3: he fixed it!
guys?
If I have problems to find my bug, I use print()s between the "if" sentences. [lua] print("#1!") -- Got the function even called? if (blah) then print("#2!") -- Got stuck on blah? if (plop) then print("#3!") -- Got stuck on plop? end end [/lua] or debug.Trace() But here is what you've done wrong: [quote='Old Gmod Wiki']This function can only be used in draw functions such as the ENT:Draw hook for scripted entities (see above example), cam functions, or effects. [/quote] (You're trying to call it in HUDPaint().) [editline]:[/editline] Sorry, that's wrong. You have a cam function there. :v:
[QUOTE=TheTrueAndy;37033473]If I have problems to find my bug, I use print()s between the "if" sentences. [lua] print("#1!") -- Got the function even called? if (blah) then print("#2!") -- Got stuck on blah? if (plop) then print("#3!") -- Got stuck on plop? end end [/lua] or debug.Trace() But here is what you've done wrong: (You're trying to call it in HUDPaint().) [editline]:[/editline] Sorry, that's wrong. You have a cam function there. :v:[/QUOTE] Im sorry, I really suck at Lua. What do you mean by a cam function and which function for the quote? Sorry, I just need a bit more clarity :)
Line 31. Change ply:GetActiveWeapon():GetPrintName() to ply:GetActiveWeapon():GetClass()
Thanks a lot guys for the advice! I got it to load but it gives me crap that: (error) [gamemodes\zmod\gamemode\cl_laser.lua:31] ')' expected near 'then' (line 31) [lua] if vm and ply:GetActiveWeapon() != NULL and table.HasValue(AcceptedLaserWeps, ply:GetActiveWeapon():GetClass() then [/lua]
Sorry, you need to Log In to post a reply to this thread.