[QUOTE=|Royal|;39148224][LUA]child:SetPos( ScrW() / 2 + 105, ScrH() / 2 - 200)[/LUA][/QUOTE]
That does the same thing but the new window is to the right, still nothing closes unless I 'x' them out
[LUA]
function DOit()
if( /*any bool*/ LocalPlayer():Alive() ) then // true
//run my code
Msg( "SPAM \n")
elseif( !LocalPlayer():Alive() ) then //false
// stop me baby
end
end
hook.Add("Think","Think",DOit) [/LUA]
[QUOTE=|Royal|;39148281][LUA]
function DOit()
if( /*any bool*/ LocalPlayer():Alive() ) then // true
//run my code
Msg( "SPAM \n")
elseif( !LocalPlayer():Alive() ) then //false
// stop me baby
end
end
hook.Add("Think","Think",DOit) [/LUA][/QUOTE]
Right thats what I've managed so far, the issues I'm having is removing an effect I don't know how to reference it.
[LUA] child = vgui.Create( "DFrame" , frame ) [/LUA]
You want something like that ? If you close the mainframe it automaticly close the child ?
greetz
Royal
[editline]9th January 2013[/editline]
[QUOTE=Sean C;39148330]Right thats what I've managed so far, the issues I'm having is removing an effect I don't know how to reference it.[/QUOTE]
Use the render lib render.DrawBeam and The HUDPaint hook.
I want it so that when you press the button (Terrorist) it closes all the Derma's. So like you click the terrorist button and everything closes and you can play.
[lua]function DrawBeamAim() local eyestart = LocalPlayer():GetEyeTrace().StartPos
local eyeend = LocalPlayer():GetEyeTrace().HitPos
local laser = Material("effects/laser1")
render.SetMaterial(laser)
render.DrawBeam( eyestart, eyeend, 10, 1, 1, Color( 255, 255, 255, 255 ) )
Msg ("Runningdrawbeam")
end
hook.Add("HUDPaint", "DrawBeamAim", DrawBeamAim);[/lua]
Why wouldn't this be working then? It compiles fine and if I add prints to debug it, it makes it through the whole block of code.
another error :/
unexpected symbol near '"chatfont"'
[CODE]self:DrawInformation(self.configuration )["Website URL"], "ChatFont", ScrW(), ScrH(), Color(255, 255, 255, 255), 255, true, function(x, y, width, height)[/CODE]
YES! Thank you wiki, I got my problem fixed.
[QUOTE=Sean C;39149059][lua]function DrawBeamAim() local eyestart = LocalPlayer():GetEyeTrace().StartPos
local eyeend = LocalPlayer():GetEyeTrace().HitPos
local laser = Material("effects/laser1")
render.SetMaterial(laser)
render.DrawBeam( eyestart, eyeend, 10, 1, 1, Color( 255, 255, 255, 255 ) )
Msg ("Runningdrawbeam")
end
hook.Add("HUDPaint", "DrawBeamAim", DrawBeamAim);[/lua]
Why wouldn't this be working then? It compiles fine and if I add prints to debug it, it makes it through the whole block of code.[/QUOTE]
Got it to work by using the PostPlayerDraw hook. Not sure if that's a good thing but as far as I can research it seems to be one of the only viable ways of drawing an aiming beam in 3d space that other players can see.
Hello,
In my SWEP, there originally was a delay in how you attacked the player, but there's problems:
1) I split the attack up into two parts, which causes when I look at an NPC/player they die immediately (sometimes)
2) I want to fire a bullet without using self:PrimaryAttack()
Need some code? Here's what it is right now:
[lua]if not attacking then
local tr = self.Owner:GetEyeTrace();
if CurTime() >= killTimer+2 then --if current time is greater than itself, plus two, or some other value..
if tr.HitNonWorld && (tr.Entity:IsPlayer() || tr.Entity:IsNPC()) and IsValid(tr.Entity) then --Are we looking at a player or NPC? If yes..
self:Caught(tr.Entity) --ah shit, they got caught, good job!
end
end
if CurTime() >= killTimer+8 and tr.HitNonWorld && (tr.Entity:IsPlayer() || tr.Entity:IsNPC()) and IsValid(tr.Entity) then --Are we looking at a player or NPC? If yes..
self:PrimaryAttack() --ATTACK!
killTimer = CurTime() + delay --delay the next shot
end
end[/lua]
[QUOTE=Turtle95;39151131]Hello,
In my SWEP, there originally was a delay in how you attacked the player, but there's problems:
1) I split the attack up into two parts, which causes when I look at an NPC/player they die immediately (sometimes)
2) I want to fire a bullet without using self:PrimaryAttack()
Need some code? Here's what it is right now:
[lua]if not attacking then
local tr = self.Owner:GetEyeTrace();
if CurTime() >= killTimer+2 then --if current time is greater than itself, plus two, or some other value..
if tr.HitNonWorld && (tr.Entity:IsPlayer() || tr.Entity:IsNPC()) and IsValid(tr.Entity) then --Are we looking at a player or NPC? If yes..
self:Caught(tr.Entity) --ah shit, they got caught, good job!
end
end
if CurTime() >= killTimer+8 and tr.HitNonWorld && (tr.Entity:IsPlayer() || tr.Entity:IsNPC()) and IsValid(tr.Entity) then --Are we looking at a player or NPC? If yes..
self:PrimaryAttack() --ATTACK!
killTimer = CurTime() + delay --delay the next shot
end
end[/lua][/QUOTE]
well you made two if statements with nearly the same conditions. Since the conditions are both being met, both if statements are ran.
if not i prolly have no idea what im talking about
Hey, I'm unable to get the AddCSLuaFile to work on my server. It worked 100% fine on my dev server but when I upload it to the main server, I get these errors.
Console Output:
[quote]
[AddCSLuaFile] Couldn't find 'autorun/client/cl_mv.lua' (<nowhere>)
[AddCSLuaFile] Couldn't find 'autorun/client/cl_mv.lua' (@addons/mapvote/lua/autorun/server/sv_mv.lua (line 25))
[/quote]
[lua]
Line 25: AddCSLuaFile("autorun/client/cl_mv.lua")
[/lua]
Is there a length limit to strings in GMod Lua that isn't in regular Lua? I ran and tested the output of a script in Lua, and am in the process of running it in the gamemode code.. but printing the output of the string gets cut off somewhere around 1000 characters. Or is this just a limitation of the print statement?
I've spent a lot of time debugging this and can't seem to figure it out. Even if I manually append text to the end of the string variable, it's not printing it. Madness!
The code basically takes a table structure that represents the database, and converts it into an sql string either for mysql or sqlite. It is for the initial creation of the database structure - a first time install.
Am I just confused here or am I really supposed to take this and break it up into a bunch of mini statements? I thought perhaps that I would send each query separately, but I would still have to write code to handle the case that any query comes to a string length of more than 1024 characters? Is that for real?
My trace isn't hitting the world it's drawing to its maximum what could going wrong here?
[lua]function MyCalcView(ply, pos, angles, fov)
gui.EnableScreenClicker(true)
local view = {}
view.origin = pos + Vector(250, 0, 250)
view.angles = Angle(45, 180, 0)
view.fov = fov
local pointertrace = {}
pointertrace.startpos = view.origin
pointertrace.endpos = pointertrace.startpos + LPCameraScreenToVector( gui.MouseX(), gui.MouseY(), ScrW(), ScrH(), angles, math.rad(fov) ) * 5000
pointertrace.filter = ply
local tr = util.TraceLine(pointertrace)
if tr.Hit then
print(tr.HitPos)
print("\n")
end
return view
end
--[[
Give this function the coordinates of a pixel on your screen, and it will return a unit vector pointing
in the direction that the camera would project that pixel in.
Useful for converting mouse positions to aim vectors for traces.
iScreenX is the x position of your cursor on the screen, in pixels.
iScreenY is the y position of your cursor on the screen, in pixels.
iScreenW is the width of the screen, in pixels.
iScreenH is the height of the screen, in pixels.
angCamRot is the angle your camera is at
fFoV is the Field of View (FOV) of your camera in ___radians___
Note: This must be nonzero or you will get a divide by zero error.
]]
function LPCameraScreenToVector( iScreenX, iScreenY, iScreenW, iScreenH, angCamRot, fFoV )
--This code works by basically treating the camera like a frustrum of a pyramid.
--We slice this frustrum at a distance "d" from the camera, where the slice will be a rectangle whose width equals the "4:3" width corresponding to the given screen height.
local d = 4 * iScreenH / ( 6 * math.tan( 0.5 * fFoV ) ) ;
--Forward, right, and up vectors (need these to convert from local to world coordinates
local vForward = angCamRot:Forward();
local vRight = angCamRot:Right();
local vUp = angCamRot:Up();
--Then convert vec to proper world coordinates and return it
a = ( d * vForward + ( iScreenX - 0.5 * iScreenW ) * vRight + ( 0.5 * iScreenH - iScreenY ) * vUp )
a:Normalize()
return a
end [/lua]
[QUOTE=Sean C;39141822]By adding a hook that already exists would you mean like having hook.Add("CalcView" ...1view) in one place in the code and hook.Add("CalcView"...view2) somewhere else? Would that be okay as long as they don't modify the same information or should it just all be contained into one function?
Wouldn't removing the hook as in your snippet just remove the new functionality for the hook from the gamemode altogether? Or for your example would you have two different CalcView calls like I just described but run that removal code inbetween them so the first CalcView hook is removed before the second is run?[/QUOTE]
I just combine all my code into one hook, no reason to create more than one. It would be okay to do, but it would be inefficient.
And no, I put that at the top of my scripts, so that the new hook that I add doesn't collide with the old one. Hooks are ran in the order they're added, so the old one would run first (that is, if hooks stack, but I don't think it works like that).
If you're wanting to just remove one hook and then make a new one, just do hook.Remove with just the name. That loop I posted removes all hook with a certain prefix.
[QUOTE=brickyross;39152522]Hey, I'm unable to get the AddCSLuaFile to work on my server. It worked 100% fine on my dev server but when I upload it to the main server, I get these errors.
Console Output:
[lua]
Line 25: AddCSLuaFile("autorun/client/cl_mv.lua")
[/lua][/QUOTE]
are you incasing it in [lua]if SERVER
then[/lua]
[QUOTE=Sean C;39149777]Got it to work by using the PostPlayerDraw hook. Not sure if that's a good thing but as far as I can research it seems to be one of the only viable ways of drawing an aiming beam in 3d space that other players can see.[/QUOTE]
At first, I was like, why in the hell are you using an effect?
Also, I was actually doing this myself. Here's my render code:
[code]
hook.Add("PostDrawOpaqueRenderables", "sc_cl_tpc_Laser", function()
...
render.SetMaterial(HUDLaserMaterial)
render.DrawBeam(MuzzlePos, FinalPos, 0.75, 0, 1, Color(255, 255, 255, 255))
...
end)
[/code]
[editline]9th January 2013[/editline]
AUTOMERRRRRRRRRRRRRRRRRRRRGE
[editline]9th January 2013[/editline]
[QUOTE=Sean C;39156754]
[lua]pointertrace.startpos + LPCameraScreenToVector( gui.MouseX(), gui.MouseY(), ScrW(), ScrH(), angles, math.rad(fov) ) * 5000[/lua][/QUOTE]
I haven't ran it myself, but maybe try -5000?
[editline]9th January 2013[/editline]
[QUOTE=HarryMudd;39153656]somewhere around 1000 characters[/QUOTE]
Have you actually tried printing the :len() of the string itself?
Is there a tutorial on how to make a basic swep for Gmod13?
An example of a swep would work fine as well!
I actually got it to work with gui.ScreenToVector (which I'm assuming might not have existed when theJ89 wrote that code block I was using). Anyway I'm drawing the beam it it works perfectly (as in my cursor position is right and the end of it where it hits the terrain) but when I try to set the players eyes to match it, something's off. Hard to describe so here's a picture of where the player is actually aiming (the phys beam). I think it just has to do with the points I'm getting my start positions from but can't quite get it.
[img]https://dl.dropbox.com/u/4636203/aimbeamprob.jpg[/img]
[lua]local vector1 = gui.ScreenToVector( gui.MouseX( ), gui.MouseY( ) )
local traceRes1 = util.QuickTrace( view.origin, vector1 * 5000, ply )
beamend = traceRes1.HitPos
local Vec1 = traceRes1.HitPos -- This is where we are going to look at
local Vec2 = ply:GetEyeTrace().StartPos -- This is where we are
local Ang = (Vec1 - Vec2):Angle() -- Gets the angle between the two points
ply:SetEyeAngles( Ang )[/lua]
[QUOTE=hogofwar;39159210]Is there a tutorial on how to make a basic swep for Gmod13?
An example of a swep would work fine as well![/QUOTE]
If you're just starting out in glua, I wouldn't recommend starting off with a SWEP. It can be a complicated process.
Check [url=http://wiki.garrysmod.com/page/Lua/Tutorials]this[/url] out if that's the case.
If not, there aren't any official ones on the new wiki. However, there is an [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8e50.html]older one for GM12[/url]. Most of the stuff there still applies to 13.
[url=https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/edit]Here's[/url] a small list of stuff Garry has compiled together that show some of the differences between GM12 and GM13.
[editline]9th January 2013[/editline]
[QUOTE=Sean C;39159249]-snip-[/QUOTE]
It seems to be on the right track, but just ever-so-slightly off.
Try making a few more debug beams to show where the beam (the trace hit) is actually going. That function may not work as advertised.
Has anyone ever seen the error "vgui: adding child in layout". It spams when you talk to a npc and their are items in the shop, I narrowed it down to this code where the error appears.
[CODE]
if (!self.ModelPanel) then
print("before") -- See if the error appears before this code
self.ModelPanel = vgui.Create('perp2_trade_inv_item', self:GetParent()); - Error here
print(self:GetParent()) -- This is here to see is self:GetParent() is null which it is not
print("after") -- Prints after the error
self.ModelPanel.trueParent = self;
end
[/CODE]
[QUOTE=DarkShadow6;39159283]If you're just starting out in glua, I wouldn't recommend starting off with a SWEP. It can be a complicated process.
Check [url=http://wiki.garrysmod.com/page/Lua/Tutorials]this[/url] out if that's the case.
If not, there aren't any official ones on the new wiki. However, there is an [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8e50.html]older one for GM12[/url]. Most of the stuff there still applies to 13.
[url=https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/edit]Here's[/url] a small list of stuff Garry has compiled together that show some of the differences between GM12 and GM13.
[editline]9th January 2013[/editline]
It seems to be on the right track, but just ever-so-slightly off.
Try making a few more debug beams to show where the beam (the trace hit) is actually going. That function may not work as advertised.[/QUOTE]
Could you recommend something to start off with?
[QUOTE=hogofwar;39159363]Could you recommend something to start off with?[/QUOTE]
...I placed three links in the post...
[QUOTE=DarkShadow6;39159283]
It seems to be on the right track, but just ever-so-slightly off.
Try making a few more debug beams to show where the beam (the trace hit) is actually going. That function may not work as advertised.[/QUOTE]
Yeah that's what I was thinking too but it seems to be pretty spot on with its resultant world coords. The trouble must be with determining the SetEyeAngles
[img]https://dl.dropbox.com/u/4636203/beamtrub2.jpg[/img]
[QUOTE=DarkShadow6;39159395]...I placed three links in the post...[/QUOTE]
You don't recommend starting out with a swep, so that is one link gone.
Another link is barely any info about gmod13 lua.
The 3rd link is just changes between 12 and 13.
You don't recommend starting with a swep, so what sort of creation should I start with instead? This is not answered with your links.
Anyone know if net.WriteInt writes a signed or unsigned integer?
[QUOTE=hogofwar;39159693]You don't recommend starting out with a swep, so that is one link gone.
Another link is barely any info about gmod13 lua.
The 3rd link is just changes between 12 and 13.
You don't recommend starting with a swep, so what sort of creation should I start with instead? This is not answered with your links.[/QUOTE]
I recommended the first one if you were just beginning learning glua.
[QUOTE=DarkShadow6;39159753]I recommended the first one if you were just beginning learning glua.[/QUOTE]
Yes, and while I appreciate that all the "tutorials" are just code snippets, nothing decent to start making.
[QUOTE=LostInTheWired;39159710]Anyone know if net.WriteInt writes a signed or unsigned integer?[/QUOTE]
Signed, there is a net.WriteUInt as well.
[QUOTE=Sparky-Z;39159952]Signed, there is a net.WriteUInt as well.[/QUOTE]
Ah, didn't notice that. Thanks.
Sorry, you need to Log In to post a reply to this thread.