[QUOTE=Ott;47194266]Anybody got the stencil code for drawing one thing through another thing (but no everything else)?[/QUOTE]
What do you mean? Care to draw something for me?
[QUOTE=bobbleheadbob;47194374]What do you mean? Care to draw something for me?[/QUOTE]
[img]http://i.imgur.com/QOTySbu.png[/img]
[editline]22nd February 2015[/editline]
But not a solid 2d color or material.
[editline]22nd February 2015[/editline]
Think "hole in the ground".
So, like only draw the model when it is beneath/touching the ground?
[QUOTE=bobbleheadbob;47194625]So, like only draw the model when it is beneath/touching the ground?[/QUOTE]
Draw the model when it is beneath and above.
[QUOTE=Ott;47194701]Draw the model when it is beneath and above.[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/cam/IgnoreZ]cam.IgnoreZ[/url]
v:v:v
[QUOTE=Ott;47194266]Anybody got the stencil code for drawing one thing through another thing (but not everything else)?[/QUOTE]
[t]http://i.imgur.com/zI8QTID.jpg[/t]
I'm having trouble getting my crossbow SWEP's bolt to deliver damage properly:
[CODE]function SWEP:PrimaryAttack()
if !self:CanPrimaryAttack() then return end
self:SetNextPrimaryFire(CurTime() + 0.75)
if SERVER then
local Bolt = ents.Create("crossbow_bolt")
if !IsValid(Bolt) then return end
Bolt:SetPos(self.Owner:GetShootPos() + self.Owner:EyeAngles():Forward()*50 - self.Owner:EyeAngles():Up()*3 + self.Owner:EyeAngles():Right()*3)
Bolt:SetAngles(self.Owner:EyeAngles()) --[[* self.Owner:GetEyeTrace().Fraction*2000]]
Bolt:Spawn()
Bolt:SetOwner(self.Owner)
Bolt:SetVelocity(Bolt:GetAngles():Forward()*3447.2)
Bolt.SetPhysicsAttacker(self.Owner)
Bolt.m_iDamage = 100
end
end
[/CODE]
Entities hit by it call OnTakeDamage(), I think it's just set to 0. If anyone could tell me how exactly I can set damage properly, and hopefully have it punt physical props, that'd be awesome. Thanks.
[QUOTE=VIoxtar;47195476]I'm having trouble getting my crossbow SWEP's bolt to deliver damage properly:
[CODE]function SWEP:PrimaryAttack()
if !self:CanPrimaryAttack() then return end
self:SetNextPrimaryFire(CurTime() + 0.75)
if SERVER then
local Bolt = ents.Create("crossbow_bolt")
if !IsValid(Bolt) then return end
Bolt:SetPos(self.Owner:GetShootPos() + self.Owner:EyeAngles():Forward()*50 - self.Owner:EyeAngles():Up()*3 + self.Owner:EyeAngles():Right()*3)
Bolt:SetAngles(self.Owner:EyeAngles()) --[[* self.Owner:GetEyeTrace().Fraction*2000]]
Bolt:Spawn()
Bolt:SetOwner(self.Owner)
Bolt:SetVelocity(Bolt:GetAngles():Forward()*3447.2)
Bolt.SetPhysicsAttacker(self.Owner)
Bolt.m_iDamage = 100
end
end
[/CODE]
Entities hit by it call OnTakeDamage(), I think it's just set to 0. If anyone could tell me how exactly I can set damage properly, and hopefully have it punt physical props, that'd be awesome. Thanks.[/QUOTE]
If I'm not mistaken, crossbow_bolt is the Source entity for it. What I would recommend is making your own bolt swep, then on the ENT:Touch method, check if the entity it touched is a player. If it is, checked GM:PlayerShouldTakeDamage and if it succeeds, call GM:EntityTakeDamage with the entity it touched and make your own DamageInfo to pass to it.
It might help to read Valve's code for the bolt, but it's in C++ which is a LOT harder to read than Lua. [url]https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/server/hl2/weapon_crossbow.cpp[/url]
I've been trying to get a detoured function to not happen twice/thrice/four times every time I update a file and cause a lua autorefresh. My code:
[lua]local oldfunc = undo.Finish
--[[------------------------------------------------------------------------------
Catch undos - call the UndoCaught hook when a player did any undoable action.
---------------------------------------------------------------------------------]]
function undo.Finish()
local OUT = {} -- OUT = Old Undo Table
for uid, undos in pairs(undo.GetTable() ) do
OUT[uid] = table.GetKeys(undos)
end
oldfunc() -- Do the ACTUAL undo.Finish()
local CUT = undo.GetTable() -- CUT = Current Undo Table
for uid, undos in pairs(CUT) do
for undokey, undodata in pairs(undos) do
if !OUT[uid] or !table.HasValue(OUT[uid], undokey) then hook.Run( "UndoCaught", uid, undokey, undodata ) end
end
end
end[/lua]
This works great, except it calls UndoCaught more than once depending on how many times lua has autorefreshed.
What's the cleanest way to solve it? I've thought of making some global variable (like UndoCatcherDone = true) and checking it BEFORE doing this, but that's a bit ugly. (pun not intended but is awesome)
[QUOTE=Neat-Nit;47197314]I've been trying to get a detoured function to not happen twice/thrice/four times every time I update a file and cause a lua autorefresh. My code:
local oldfunc = undo.Finish--[[------------------------------------------------------------------------------ Catch undos - call the UndoCaught hook when a player did any undoable action.---------------------------------------------------------------------------------]]function undo.Finish() local OUT = {} -- OUT = Old Undo Table for uid, undos in pairs(undo.GetTable() ) do OUT[uid] = table.GetKeys(undos) end oldfunc() -- Do the ACTUAL undo.Finish() local CUT = undo.GetTable() -- CUT = Current Undo Table for uid, undos in pairs(CUT) do for undokey, undodata in pairs(undos) do if !OUT[uid] or !table.HasValue(OUT[uid], undokey) then hook.Run( "UndoCaught", uid, undokey, undodata ) end end endend
This works great, except it calls UndoCaught more than once depending on how many times lua has autorefreshed.
What's the cleanest way to solve it? I've thought of making some global variable (like UndoCatcherDone = true) and checking it BEFORE doing this, but that's a bit ugly. (pun not intended but is awesome)[/QUOTE]
Something like this should work.
[code]
OldUndoFinish = OldUndoFinish or undo.Finish
[/code]
That way the old function is stored and not updated ever time the file reloads.
Anyone know of any good tutorials or explanations on how to make 3D2D HUDs?
[QUOTE=Zachy;47199315]Anyone know of any good tutorials or explanations on how to make 3D2D HUDs?[/QUOTE]
A quick rundown is as simple as 1, 2, 3:
1) Determine how many planes you want. Usually you will want two; one on the left and one on the right for armor/health and ammo, respectively.
2) For each plane, create a 3D2D clause using cam.Start3D2D() and cam.End3D2D(). The position should be offset from the player's EyePos(). It should be rotated based on their EyeAngles().
3) Inside each clause, draw your HUD like you would draw it normally.
Why does table.ForEach exist?
[QUOTE=Author.;47199982][lua]> table.ForEach( {"potatoes", 1337, {4, 2, 0}}, function(k, v) print(k, v) end)...
1 potatoes
2 1337
3 table: 0x26a2d098[/lua]
Just a cleaner way to iterate through tables I guess?[/QUOTE]
I would argue it's less clean than a for loop. Looking at the source, it's simply one unneeded function call then one unneeded function call per loop:
[lua]
function table.ForEach( tab, funcname )
for k, v in pairs( tab ) do
funcname( k, v )
end
end
[/lua]
[QUOTE=bobbleheadbob;47199996]
Well the uncapitalized version is the old way to iterate a table, deprecated and replaced by iteration functions like pairs().
The one with UpperCamelCase says this on the wiki:
If table.foreach()'s callback function returns anything, the loop is broken. This is how we broke loops before the break keyword came into play.
[/QUOTE]
Since it seems like the capitalized version was never and is never needed, perhaps deprecation should be issued?
[lua]> table.ForEach( {"potatoes", 1337, {4, 2, 0}}, function(k, v) print(k, v) end)...
1 potatoes
2 1337
3 table: 0x26a2d098[/lua]
Just a cleaner way to iterate through tables I guess? Don't forget table.foreach is a deprecated function, which I'm guessing is the main reason for it's existance.
[QUOTE=zerf;47199847]Why does table.ForEach exist?[/QUOTE]
Well the uncapitalized version is the old way to iterate a table, deprecated and replaced by iteration functions like pairs().
The one with UpperCamelCase says this on the wiki:
[quote="The Wiki"]
Unlike table.foreach, this ignores the value returned by the function.
[/quote]
If table.foreach()'s callback function returns anything, the loop is broken. This is how we broke loops before the break keyword came into play.
I really really bothers me when people use pairs over ipairs.
Is there any other documentation on a scroll menu rather than the TTT one?
[QUOTE=StonedPenguin;47200402]I really really bothers me when people use pairs over ipairs.[/QUOTE]
It was tested and someone found out that ipairs is actually slower by the smallest fraction.
It's only useful for intentional sorting.
Does the loading screen HTML panel support HTML5?
I have a clientside script that adds somes of viewpunch based on acceleration. This is the code I have so far.
[code]
function HandleAcceleration(ply)
if not ply.NewAcceleration then
ply.NewAcceleration = Vector(0,0,0)
end
if not ply.OldAcceleration then
ply.OldAcceleration = Vector(0,0,0)
end
if not ply.LastAngle then
ply.LastAngle = ply:EyeAngles()
end
ply.NewAcceleration = WorldToLocal(ply:GetVelocity(),Angle(0,0,0),Vector(0,0,0),ply:GetAngles())
local nx = ply.NewAcceleration.x
local ny = ply.NewAcceleration.y
local nz = ply.NewAcceleration.z
local ox = ply.OldAcceleration.x
local oy = ply.OldAcceleration.y
local oz = ply.OldAcceleration.z
ply.OldAcceleration = WorldToLocal(ply:GetVelocity(),Angle(0,0,0),Vector(0,0,0),ply:GetAngles())
local Result = Angle( (-(nx - ox) / 100) + ((nz - oz) / 100) ,0, -(ny - oy) / 100 )
if Result ~= Angle(0,0,0) then
if ply.PunchAmount then
ply.PunchAmount = ply.PunchAmount + Result
else
ply.PunchAmount = Result
end
end
if ply.PunchAmount then
ply.OldAngle = ply:EyeAngles() - ply.PunchAmount
local Amount = 2*FrameTime()
local PClamp
local YClamp
local RClamp
if ply.PunchAmount.p > 0 then
PClamp = math.max(0,ply.PunchAmount.p - Amount)
elseif ply.PunchAmount.p < 0 then
PClamp = math.min(0,ply.PunchAmount.p + Amount)
else
PClamp = 0
end
if ply.PunchAmount.y > 0 then
YClamp = math.max(0,ply.PunchAmount.y - Amount)
elseif ply.PunchAmount.y < 0 then
YClamp = math.min(0,ply.PunchAmount.y + Amount)
else
YClamp = 0
end
if ply.PunchAmount.r > 0 then
RClamp = math.max(0,ply.PunchAmount.r - Amount)
elseif ply.PunchAmount.r < 0 then
RClamp = math.min(0,ply.PunchAmount.r + Amount)
else
RClamp = 0
end
ply.PunchAmount = Angle(PClamp,YClamp,RClamp)
else
ply.OldAngle = ply:EyeAngles()
end
local Test = ply.PunchAmount
if Test ~= Angle(0,0,0) then
print(Test)
end
local Difference = ply:EyeAngles() - ply.LastAngle + Test
ply:SetEyeAngles( ply:EyeAngles() )
ply.LastAngle = ply:EyeAngles()
end
[/code]
I'm stuck on actually putting everything together, so it sets the view based on ply.PunchAmount
ie if ply.PunchAmount is Angle(1,0,0), then it would set the EyeAngles Pitch to 1 degree over what it should normally be.
Just stick it in a CalcView hook and override aim angles.
[editline]23rd February 2015[/editline]
[url=https://bitbucket.org/blackops7799/breakpoint/src/99258984fa415d32c26d0c54c2bd9f2aa37d790e/gamemodes/css/entities/weapons/?at=default]BlackAwps' CS:S base does, this, take a look at this repo.[/url]
Alright, how do I detect and block any clients on my server that might be using clientsided lua scripts?
[QUOTE=michaelrule4;47201581]Alright, how do I detect and block any clients on my server that might be using clientsided lua scripts?[/QUOTE]
[b]Make sure you set sv_allowcslua to 0.[/b] It's so fucking annoying when you find an allowcslua 1 server but get kicked immediately. There is no surefire way to detect something, but start with detouring hook.Add.
[QUOTE=Acecool;47125595]Are you just trying to angle the ends, or make it rise / fall? With poly it's simply connect the dots without allowing the lines to cross.
Here's an example of a simple angled bar ( using easy input of x, y, w, h and tilt-shift amount ):
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/poly/tilted_rectangle_poly_as_health_meter.lua.html[/url]
Try to simplify what you're trying to do and make helper-functions.[/QUOTE]
I managed to almost fully get what I want but I feel like my calculations are off. Whenever I put in 90 degrees for the angle it won't draw the polygons. Also whenever I try to do certain angles it will not work correctly.
I am trying to make things like the health bar, ammo bar, and hud panels face inward towards the center of the screen.
Something like this:[t]http://rog.asus.com/wp-content/uploads/2013/02/crysis3-2013-02-18-23-23-08-45.jpg[/t]
The degress in the pic below was 160.
[img]http://i.gyazo.com/2440c64b55f4f138d94d37f8ef0e140b.png[/img]
The degress in the pic below was 170.
[img]http://i.gyazo.com/d09fd1bb0e095016b608d490c0abd58a.png[/img]
code:
[code]
function tiltedSquare( x, y, theta, hypo, thick)
local tbl = {
//{ x=x+(math.cos(theta)*hypo), y=y },
//{ x=x, y=y+(math.sin(theta)*hypo) },
//{ x=x, y=y+thick+(math.sin(theta)*hypo) },
//{ x=x+(math.cos(theta)*hypo), y=y+thick },
{ x=x+(math.cos(theta)*hypo), y=y+thick },
{ x=x+(math.cos(theta)*hypo), y=y },
{ x=x, y=y+(math.sin(theta)*hypo) },
{ x=x, y=y+thick+(math.sin(theta)*hypo) },
}
return tbl
end
[/code]
[QUOTE=Ott;47201615][b]Make sure you set sv_allowcslua to 0.[/b] It's so fucking annoying when you find an allowcslua 1 server but get kicked immediately. There is no surefire way to detect something, but start with detouring hook.Add.[/QUOTE]
Thank you, detouring definitely looks promising. I guess a follow up question would be if there's any quick way to load my lua script first on the client before they load up any other addons/lua files?
[QUOTE=michaelrule4;47201648]Thank you, detouring definitely looks promising. I guess a follow up question would be if there's any quick way to load my lua script first on the client before they load up any other addons/lua files?[/QUOTE]
There are ways a client can modify any lua file you send them before they're ran. However, only 3 people have reported the exploit, so it's pretty unknown. I'd assume that gamemode and lua/ code is ran before addon code is, though.
Actually, addons are loaded prior to GM being set ( which is why if you want to create new GM functions, you need to do so in a hook such as Initialize )...
Gamemode is loaded next.
Lua/ may be loaded first or maybe at the same time as addons because addons load into GMod as virtual directories...
I'm running dev-mode.
[editline]24th February 2015[/editline]
[QUOTE=bran92don;47201640]I managed to almost fully get what I want but I feel like my calculations are off. Whenever I put in 90 degrees for the angle it won't draw the polygons. Also whenever I try to do certain angles it will not work correctly.
I am trying to make things like the health bar, ammo bar, and hud panels face inward towards the center of the screen. [/QUOTE]
You should have no trouble using 3D2D and rotating the panels out... This way you can simply create the panels on a flat surface then rotate them out; it'll make the code easier to follow, easier to alter, etc...
Someone posted a sorted list of files, where you can see, which files will be run at first.
[url]http://pastebin.com/HR1FWScu[/url]
If that helps.
I'm having trouble sorting a table by more than one member.
My test code:
[lua]local tab = {
{one = 2, two = 1},
{one = 3, two = 2},
{one = 1, two = 3},
{one = 2, two = 1},
{one = 3, two = 2},
{one = 3, two = 3},
{one = 3, two = 1},
{one = 1, two = 2},
{one = 2, two = 3},
}
print("\nBefore SortByMember:")
PrintTable(tab)
table.SortByMember(tab, "one")
print("\nAfter Sort By One:")
PrintTable(tab)
table.SortByMember(tab, "two")
print("\nAfter Sort By Two:")
PrintTable(tab)[/lua]
The results:
[code]Before SortByMember:
1:
one = 2
two = 1
2:
one = 3
two = 2
3:
one = 1
two = 3
4:
one = 2
two = 1
5:
one = 3
two = 2
6:
one = 3
two = 3
7:
one = 3
two = 1
8:
one = 1
two = 2
9:
one = 2
two = 3
After Sort By One:
1:
one = 3
two = 2
2:
one = 3
two = 1
3:
one = 3
two = 2
4:
one = 3
two = 3
5:
one = 2
two = 1
6:
one = 2
two = 1
7:
one = 2
two = 3
8:
one = 1
two = 2
9:
one = 1
two = 3
After Sort By Two:
1:
one = 1
two = 3
2:
one = 2
two = 3
3:
one = 3
two = 3
4:
one = 1
two = 2
5:
one = 3
two = 2
6:
one = 3
two = 2
7:
one = 2
two = 1
8:
one = 3
two = 1
9:
one = 2
two = 1[/code]
As can be seen, the first sort is essentially lost in the second one. I'd have expected it to be preserved when two values are the same.
What's going on, and do I have to write my own sort function? :suicide:
Sorry, you need to Log In to post a reply to this thread.