I deleted it because I have a hunch! But I will definitely consider your solution too, man of coolness, seeing as my hunches run off my barebones knowledge of math.
-snip-
[QUOTE=bobbleheadbob;47159694]If you make a HUD in C++ then go for it. The standard for HUD's in Lua is GM:HUDPaint.[/QUOTE]
Thanks, Mr. Standard Authority. Who'd of known I've been wrong this whole time! All hail the superior logic of calculating element positions on a per-frame basis.
I hope you realise the HUDPaint hook is the Paint hook of an internal VGUI element.
[QUOTE=Willox;47161363]Thanks, Mr. Standard Authority. Who'd of known I've been wrong this whole time! All hail the superior logic of calculating element positions on a per-frame basis.
I hope you realise the HUDPaint hook is the Paint hook of an internal VGUI element.[/QUOTE]
An internal pre-configured VGUI element, not a Derma panel.
And whatever way you slice it, you'll have to overwrite a paint hook.
Also just realized that Derma panels draw over the escape menu in some cases. HUD's shouldn't do that.
[QUOTE=bobbleheadbob;47161433]An internal pre-configured VGUI element, not a Derma panel.
And whatever way you slice it, you'll have to overwrite a paint hook.
Also just realized that Derma panels draw over the escape menu in some cases. HUD's shouldn't do that.[/QUOTE]
You can parent your own panels to the HUD panel.
panel:ParentToHUD()
And no, you don't have to overwrite a paint hook. You're spouting shit about shit you don't know.
Hey quick question, if I was to pre cache a .png file, what would I do?
Would I call it on Server or Client. An example would help :)
[QUOTE=Willox;47161472]You can parent your own panels to the HUD panel.
panel:ParentToHUD()
And no, you don't have to overwrite a paint hook. You're spouting shit about shit you don't know.[/QUOTE]
Was unaware of that method, but regardless here is a quick HUD I whipped up with Derma:
[lua]
local health = vgui.Create("DPanel")
health:ParentToHUD()
health:SetPos(15,ScrH()-80)
health:SetSize(200,30)
function health:Paint(w,h) --Oh look an overridden paint hook.
draw.RoundedBox(4, 0, 0, w, h, Color(50,0,0,255))
draw.RoundedBox(4, 0, 0, w * (LocalPlayer():Health() / 100), h, Color(255,0,0,255))
end
local armor = vgui.Create("DPanel")
armor:ParentToHUD()
armor:SetPos(15,ScrH()-45)
armor:SetSize(200,30)
function armor:Paint(w,h) --Hey woah we've had to override TWO paint hooks!
draw.RoundedBox(4, 0, 0, w, h, Color(0,0,50,255))
draw.RoundedBox(4, 0, 0, w * (LocalPlayer():Armor() / 100), h, Color(0,0,255,255))
end
hook.Add("HUDShouldDraw","No Healtharmor",function(n)
if (n=="CHudHealth" or n=="CHudBattery") then
return false
end
end)
[/lua]
Same HUD in HUDPaint:
[lua]
hook.Add("HUDPaint","Not-Shit HUD",function()
local y = ScrH()
local w,h = 200, 30
draw.RoundedBox(4, 15, y-80, w, h, Color(50,0,0,255))
draw.RoundedBox(4, 15, y-80, w * (LocalPlayer():Health() / 100), h, Color(255,0,0,255))
draw.RoundedBox(4, 15, y-45, w, h, Color(0,0,50,255))
draw.RoundedBox(4, 15, y-45, w * (LocalPlayer():Armor() / 100), h, Color(0,0,255,255))
end)
hook.Add("HUDShouldDraw","No Healtharmor",function(n)
if (n=="CHudHealth" or n=="CHudBattery") then
return false
end
end)
[/lua]
You tell me which one is better.
EDIT:
I sound really rude. Sorry.
If I have a png IMaterial, how can I flip it horizontally without creating another file?
[QUOTE=zerf;47161849]If I have a png IMaterial, how can I flip it horizontally without creating another file?[/QUOTE]
Using UV you might be able to set the start point to 1,0 and the end point to 0,1.
I don't know if that will work for sure though.
Thanks, that worked well.
[QUOTE=bobbleheadbob;47161745]Was unaware of that method, but regardless here is a quick HUD I whipped up with Derma:
[lua]
-- vgui
[/lua]
Same HUD in HUDPaint:
[lua]
-- hudpaint
[/lua]
You tell me which one is better.
EDIT:
I sound really rude. Sorry.[/QUOTE]
First.
Panels are objects, they store their own state and properties.
With Immediate drawing, you have to keep track of state for every single thing.
[QUOTE=vexx21322;47161903]First.
Panels are objects, they store their own state and properties.
With Immediate drawing, you have to keep track of state for every single thing.[/QUOTE]
What do you mean by state?
I suppose if your HUD consisted of a bunch of added and removed elements such as snowflakes or something which moved about all that jazz, then making each little item a panel would be the best solution; however, health, armor, ammo, money, points, these all just display data in a visually appealing way. You don't need to make and configure panels just to draw a couple rectangles and text.
I mean if you want to get the local player's health, you don't access the health bar's value you just access LocalPlayer():Health().
As for consistent properties, like a lerping health bar, a local variable declared above the hook should do the trick.
Still trying to determine velocity required to start at (0, 64) and end at (5120, 0).
Using this to determine initial velocity required: [img]https://upload.wikimedia.org/math/5/4/2/5427a94d0f78acd3fdf6b5582565d062.png[/img]
Using this to for parabolic function (blah): [img]https://upload.wikimedia.org/math/d/1/b/d1bb5f2d6b1b1c7c2395d1213979352d.png[/img]
[code] function SWEP:BulletDropTrace( )
local gravity = GetConVarNumber( "sv_gravity" )
local eyeHeight = self.Owner:EyePos( ).z - self.Owner:GetPos( ).z
local dropDist = 1024
local velocity = math.sqrt( ( ( dropDist ^ 2 ) * gravity ) / ( dropDist * math.sin( 2 * math.rad( 45 ) ) ) + ( 2 * eyeHeight * ( math.cos( math.rad( 45 ) ) ^ 2 ) ) ) -- https://upload.wikimedia.org/math/5/4/2/5427a94d0f78acd3fdf6b5582565d062.png
local i = 0
while i <= 5120 do
local blah = velocity * i * math.sin( math.rad( 45 ) ) - ( .5 * gravity * ( i ^ 2 ) ) -- https://upload.wikimedia.org/math/d/1/b/d1bb5f2d6b1b1c7c2395d1213979352d.png
print( "distance = "..dropDist, "time = "..i, "velocity = "..velocity, "~ z = "..blah )
i = i + 512
end
end[/code]
I have no idea what I'm doing wrong, but it outputs with this:
[code]distance = 64 time = 0 velocity = 196.1224107541 z = 0
distance = 64 time = 512 velocity = 196.1224107541 z = -78572196.102868
distance = 64 time = 1024 velocity = 196.1224107541 z = -314430792.20574
distance = 64 time = 1536 velocity = 196.1224107541 z = -707575788.3086
distance = 64 time = 2048 velocity = 196.1224107541 z = -1258007184.4115
distance = 64 time = 2560 velocity = 196.1224107541 z = -1965724980.5143
distance = 64 time = 3072 velocity = 196.1224107541 z = -2830729176.6172
distance = 64 time = 3584 velocity = 196.1224107541 z = -3853019772.7201
distance = 64 time = 4096 velocity = 196.1224107541 z = -5032596768.8229
distance = 64 time = 4608 velocity = 196.1224107541 z = -6369460164.9258
distance = 64 time = 5120 velocity = 196.1224107541 z = -7863609961.0287
[/code]
[b]EDIT:[/b] oops, messed up and put "5012" instead of dropDist, which is 1024:
[code] function SWEP:BulletDropTrace( )
local gravity = GetConVarNumber( "sv_gravity" )
local eyeHeight = self.Owner:EyePos( ).z - self.Owner:GetPos( ).z
local dropDist = 1024
local velocity = math.sqrt( ( ( dropDist ^ 2 ) * gravity ) / ( dropDist * math.sin( 2 * math.rad( 45 ) ) ) + ( 2 * eyeHeight * ( math.cos( math.rad( 45 ) ) ^ 2 ) ) ) -- https://upload.wikimedia.org/math/5/4/2/5427a94d0f78acd3fdf6b5582565d062.png
local i = 0
while i <= dropDist do
local blah = velocity * i * math.sin( math.rad( 45 ) ) - ( .5 * gravity * ( i ^ 2 ) ) -- https://upload.wikimedia.org/math/d/1/b/d1bb5f2d6b1b1c7c2395d1213979352d.png
print( "distance = "..dropDist, "time = "..i, "velocity = "..velocity, "~ z = "..blah )
i = i + 16
end
end[/code]
[code]distance = 64 time = 0 velocity = 196.1224107541 ~ z = 0
distance = 64 time = 16 velocity = 196.1224107541 ~ z = -74581.12821461
distance = 64 time = 32 velocity = 196.1224107541 ~ z = -302762.25642922
distance = 64 time = 48 velocity = 196.1224107541 ~ z = -684543.38464383
distance = 64 time = 64 velocity = 196.1224107541 ~ z = -1219924.5128584
[/code]
What sound file formats are allowed to be uploaded on workshop? If any at all.
[QUOTE=Minteh Fresh;47163255]What sound file formats are allowed to be uploaded on workshop? If any at all.[/QUOTE]
All of them. All being the ones you can use in-game.
[QUOTE=Robotboy655;47163317]All of them. All being the ones you can use in-game.[/QUOTE]
[IMG]http://puu.sh/g22wH/68ada7a4ab.png[/IMG]
Are you sure?
[QUOTE=Minteh Fresh;47163374][IMG]http://puu.sh/g22wH/68ada7a4ab.png[/IMG]
Are you sure?[/QUOTE]
Yes, you are too smart to open a vpk or an addon to see that the correct folder name is SOUND, not SOUND[B]S[/B].
Hello, I'm searching since like a day how can I set an existing prop so that the physgun can't interact with it? Like SetPersistent but without the saving feature. Or, a way to call ent:SetPersistent( false ) just before the ShutDown hook is called, so that it isn't saved.
I've tried every collision types, tried to use ent:Fire and ent:SetKeyValue( "gmod_allowphysgun", 0 ), but that doesn't work either. Also tried many combinations of Flags and EFlags...
I know I can return false in PhysgunPickup but it's crap and doesn't seem to be working on client. So I'm out of ideas, and you?
[QUOTE=DEFCON1;47163411]Hello, I'm searching since like a day how can I set an existing prop so that the physgun can't interact with it? Like SetPersistent but without the saving feature. Or, a way to call ent:SetPersistent( false ) just before the ShutDown hook is called, so that it isn't saved.
I've tried every collision types, tried to use ent:Fire and ent:SetKeyValue( "gmod_allowphysgun", 0 ), but that doesn't work either. Also tried many combinations of Flags and EFlags...
I know I can return false in PhysgunPickup but it's crap and doesn't seem to be working on client. So I'm out of ideas, and you?[/QUOTE]
You won't be able to do it on client either way, but there's ent.PhysgunDisabled = true that can do that.
Thanks, that worked ;)
[QUOTE=Robotboy655;47163405]Yes, you are too smart to open a vpk or an addon to see that the correct folder name is SOUND, not SOUND[B]S[/B].[/QUOTE]
Wow, I really am stupid - well played.
[QUOTE=wauterboi;47162710]
[code]distance = 64 time = 0 velocity = 196.1224107541 ~ z = 0
distance = 64 time = 16 velocity = 196.1224107541 ~ z = -74581.12821461
distance = 64 time = 32 velocity = 196.1224107541 ~ z = -302762.25642922
distance = 64 time = 48 velocity = 196.1224107541 ~ z = -684543.38464383
distance = 64 time = 64 velocity = 196.1224107541 ~ z = -1219924.5128584
[/code][/QUOTE]
But i is a time, not a distance
Isn't that what I put? I meant for "i" to represent time, and the length to represent distance. What did I do wrong?
[b]EDIT:[/b] What I'm doing is using "time" as the x-axis on a chart. I'm not going to be making my bullets delayed by actual time.
[QUOTE=wauterboi;47163722]Isn't that what I put? I meant for "i" to represent time, and the length to represent distance. What did I do wrong?
[b]EDIT:[/b] What I'm doing is using "time" as the x-axis on a chart. I'm not going to be making my bullets delayed by actual time.[/QUOTE]
I'm a bit late to this question.
What is your input and what is your output here? is input the angle which the player shoots their gun and output is the point at which the bullet lands with bullet drop?
Or is input the point that you want the bullet to land at, and output is the angle required?
My input is the distance the bullet should travel before hitting the ground (dropDist), and the output is the velocity needed. I then pump that into the proper velocity equation.
[QUOTE=wauterboi;47166523]My input is the distance the bullet should travel before hitting the ground (dropDist), and the output is the velocity needed. I then pump that into the proper velocity equation.[/QUOTE]
So you already have the point which the bullet will land given any firing pos/ang, and you need to know how fast the bullet must be fired to get it to land there?
I assumed your end goal was to find out where the bullet lands.
dropDist represents the maximum distance. Since that's going to be at a 45 degree angle, I tried to calculate the velocity for that. Shooting the gun should always shoot at that velocity, but not that distance.
I hope I'm not being redundant but I have nothing better to do considering I'm in UNIX 101. :suicide:
Here is how I would solve the issue.
Let's first recognize Newton's First Law of Inertia:
[QUOTE=Motherfucking Issaac Newton]Objects in motion stay in motion unless acted upon by an outside force.[/QUOTE]
In this case, our projectile is constantly being acted upon by one outside force: gravity. We know that gravity (in the Source engine) only pulls downward.
When our bullet flies through the air, nothing ever changes its x and y velocity. If not for gravity to change that z value, it would keep going and going until it hit something, which is what the current trace system does.
However, you won't settle for the current system, you hipster. So be it, but now we must account for z [I]acceleration[/I].
Acceleration is the rate of change in velocity over time, or
[code]
| newVel - oldVel |
-------------------------
| newTime - oldTime |
[/code]
This means that as time goes on, our z velocity will [I]change[/I]. Keep in mind that z-velocity is entirely different from z-pos, and that velocity is just distance over time.
Let's look at this hastily drawn graph of a bullet fired from a point:
[t]http://s10.postimg.org/rh2h0pa3t/graph.jpg[/t]
We can see that when Δx is constant, Δy starts off positive, decreases until it is 0, then becomes negative until the bullet lands.
Because we are operating in a complex environment, and not a flat graph, we unfortunately can't just graph the function. We have to use traces.
Look at this diagram of a flying projectile:
[t]http://www.chs.d211.org/science/kulakmp/HWAnswers/2D/5%20-%20Homework%20ans_files/image002.gif[/t]
Notice two things:
First, the xSpeed never changes.
Second, the velocity of the object is the combination of the xSpeed and ySpeed. We can replicate this with traces:
[lua]
// Speed of bullet as it is fired from the chamber in units per second.
SWEP.BulletSpeed = 1000
function SWEP:GetBulletDropHitPos(ang)
//Create a normal vector from the angle, and multiply it by our constant.
local v0 = ang:Forward() * self.BulletSpeed
//We need to trace the path of our bullet as it goes.
//If we want our bullet to land within the same frame, we use a loop.
//If we wanted our bullet to take time to land, we would use a think hook.
local landed, v, pos, traceResult = false, v0, self.Owner:GetShootPos(), {} //Initialize our base stuff.
local deltaTime = .1 // Simulated time for our loop. would be FrameTime() in a think hook. Lower number is more physics accuracy and less fps.
local gravity = GetConVarNumber("sv_gravity")
repeat
util.TraceLine({
start = pos, //Trace from our bullet's current pos
endpos = pos + (v * deltaTime), //to its new possible pos
filter = {self,self.Owner}, //Bullet doesn't hit gun or player.
output = traceResult, //Save a bit of memory and garbage collection
mask = MASK_SHOT //Bullet hits anything that would stop a bullet.
}
if traceResult.Hit then //we hit something. Stop tracing.
landed = true
else //No hit. Continue the trace with new position and velocity.
v.z = v.z - (gravity * deltaTime) //Change velocity by gravity.
pos = pos + (v * deltaTime) //Update position.
debugoverlay.Cross(pos,3,2,Color(255,100,0),false)
end
until landed //Stop when we hit something.
//You can now use the traceResult table to determine what to do.
if not traceResult.HitSky then //Sky hits should kill the bullet.
self:FireBullets({
Attacker = self.Owner,
Damage = self.PrimaryDamage,
Force = self.PrimaryForce,
Distance = 1000,
Num = 1,
Dir = v:GetNormalized(),
Src = pos,
})
end
end
[/lua]
That code is untested, but should work (or crash your game with an infinite loop).
I need help with logic
I'm using the CreateMove hook and I'm trying to make it so it takes away stamina if you jump.
so far I have
[code]
if cmd:KeyDown(IN_JUMP) and ply:OnGround() then
--do shit
end
[/code]
But it takes away stamina if you're holding down the spacebar and you're still on the ground. I tried a bunch of combination with latches but it doesn't work, I'm still trying.
[QUOTE=ROFLBURGER;47168788]I need help with logic
I'm using the CreateMove hook and I'm trying to make it so it takes away stamina if you jump.
so far I have
[code]
if cmd:KeyDown(IN_JUMP) and ply:OnGround() then
--do shit
end
[/code]
But it takes away stamina if you're holding down the spacebar and you're still on the ground. I tried a bunch of combination with latches but it doesn't work, I'm still trying.[/QUOTE]
[lua]
local hasjumped = false
hook.Add("CreateMove","swag",function(ply,cmd)
if cmd:KeyDown(IN_JUMP) and ply:OnGround() then
if not hasjumped then
--do shit
hasjumped = true
end
else //when the player lets go of the space bar
hasjumped = false
end
end)
[/lua]
Sorry, you need to Log In to post a reply to this thread.