[QUOTE=KingofBeast;52327409]Better yet, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/DistToSqr]Vector:DistToSqr[/url][/QUOTE]
I do agree, but as I recall, the real-world difference turned out to be negligible to the point of not being worth it. Even with 100 players, that's unlikely to affect anything at all.
[QUOTE=NeatNit;52331399]I do agree, but as I recall, the real-world difference turned out to be negligible to the point of not being worth it. Even with 100 players, that's unlikely to affect anything at all.[/QUOTE]
Even if it didn't, giving good optimisation/coding habits a backseat with the excuse of it being "negligible" or "useless" is a toxic and terrible mindset that is plaguing the world of software engineering today almost as much as strong limiting OOP. People should use good and efficient habits naturally, and this is a key example in which the difference might be negligible to your small script but would make a big difference in other applications.
Also, just to note, sqrt is the most expensive CPU operation and should be avoided where possible.
[QUOTE=code_gs;52331441]Even if it didn't, giving good optimisation/coding habits a backseat with the excuse of it being "negligible" or "useless" is a toxic and terrible mindset that is plaguing the world of software engineering today almost as much as strong limiting OOP. People should use good and efficient habits naturally, and this is a key example in which the difference might be negligible to your small script but would make a big difference in other applications.
Also, just to note, sqrt is the most expensive CPU operation and should be avoided where possible.[/QUOTE]
And here I thought premature optimization is the root of all evil... Or is this the critical 3%?
[QUOTE=Castiel789;52326196]Like I said though I've tried it on a dedicated server, 4GHz processor etc, completely default, and it still appears to have more variation(less var, but sv fluctuates more) than their populated server with however many active scripts are running.[/QUOTE]
What are the numbers your seeing on a default sandbox , and a darkrp server fully loaded with scripts?
[QUOTE=dx9er;52332999][code]
require("gxml")
local yourgroup = "GROUPHEREPLEASEREPLACE"
groupinfo = {}
function UpdateGroupInfo()
local link = "http://www.steamcommunity.com/groups/" .. yourgroup .. "/memberslistxml/?xml=1"
print(link)
http.Fetch(link,
function(body)
print("success")
groupinfo = XMLToTable(body)
end)
end
hook.Add("Initialize", "GetGroupInfo", UpdateGroupInfo)
[/code]
I'm trying to get information about a group, but "groupinfo" never gets overwritten, even though "success" gets printed out. This worked yesterday, but not anymore apparently. No errors get spat out.
GXML is this: [url]https://facepunch.com/showthread.php?t=961117[/url]
[sp]sorry for posting this here also[/sp][/QUOTE]
Have you tried checking the same URL in-browser? Steam XML api is patchy at best, and also has a severe ratelimit.
So I want to draw a circle that can be mapped to a value that changes how "Filled" it it. I don't really mean filled, but I mean to take segments out, sort of like how the PacMan head looks. I vaguely remember seeing a tutorial on here about it somewhere, but I'm unable to find it. Any ideas?
[QUOTE=CryptAlchemy;52334429]Yes, that works, but then the player is able to use the arrow keys to control where he goes.
What I'm looking for is a way to make gravity still applicable, and just like it works for entities.
There are sweps like nocollide world which do this, but to entities; gravity still applies to the entities and they simply fall through the world.
I was looking to do this with players.[/QUOTE]
You want a player to uncontrollably fall through the world?
[QUOTE=CryptAlchemy;52334478][IMG]https://facepunch.com/fp/emotes_p/snip.png[/IMG] [B]SOLVED![/B][/QUOTE]
[QUOTE=CryptAlchemy;52334429][IMG]https://facepunch.com/fp/emotes_p/snip.png[/IMG] [B]SOLVED![/B][/QUOTE]
[QUOTE=CryptAlchemy;52334352][IMG]https://facepunch.com/fp/emotes_p/snip.png[/IMG] [B]SOLVED![/B][/QUOTE]
No. No no no no no. [B][U]NO![/U][/B]
That's not what you do when your problem is solved.
You keep the post unedited so future people that might encounter the same issue could read it.
[URL="https://xkcd.com/979/"]Don't be DenverCoder9[/URL], LEAVE YOUR POSTS UP
[QUOTE=JasonMan34;52334750]No. No no no no no. [B][U]NO![/U][/B]
That's not what you do when your problem is solved.
You keep the post unedited so future people that might encounter the same issue could use.
[URL="https://xkcd.com/979/"]Don't be DenverCoder9[/URL], LEAVE YOUR POSTS UP[/QUOTE]
Oh, sorry, I'll put it back up.
Problem:
How do you check if a player can actually teleport to a specific location?
Soln:
-- Set newPos to the vector coordinate that you wish to be sent to
local pos = newPos -- Choose your position.
local tr = {
start = pos,
endpos = pos,
mins = Vector( -16, -16, 0 ),
maxs = Vector( 16, 16, 71 )
}
local hullTrace = util.TraceHull( tr )
if hullTrace.Hit == false then
-- Send them somewhere
end
[QUOTE=JasonMan34;52334750]No. No no no no no. [B][U]NO![/U][/B]
That's not what you do when your problem is solved.
You keep the post unedited so future people that might encounter the same issue could use.
[URL="https://xkcd.com/979/"]Don't be DenverCoder9[/URL], LEAVE YOUR POSTS UP[/QUOTE]
+1 for the XKCD reference.
But SERIOUSLY! I've seen this so many times on stuff that I needed help with. DO NOT SNIP PLEASE!
Hey, so I'm trying to edit the weapon base for F2S: Stronghold so as to allow for a burst fire option for custom weapons. The only problem is that the client is out of sync with the server and often fires and incorrect amount of times. Here is the code.
[code]
function SWEP:Think()
--There is other code here, it is just omitted!--
self:IsBurstFiring()
end
function SWEP:IsBurstFiring()
local firemode = self.FireModes[self:GetNWInt("FireMode")]
if !self.Owner:KeyDown( IN_ATTACK ) and firemode == "burst" then
self:SetNWInt("firedshots", 0)
end
end
function SWEP:CanPrimaryAttack()
local firemode = self.FireModes[self:GetNWInt("FireMode")]
if firemode == "safe" then return false end
if firemode == "burst" and self:GetNWInt("firedshots") >= self.Primary.BurstAmount then return false end
local Running = self.Owner:KeyDown( bit.bor(IN_FORWARD,IN_BACK,IN_MOVELEFT,IN_MOVERIGHT) ) and self.Owner:KeyDown( IN_SPEED )
if Running or self.Owner:GetColor().a < 255 then return false end
if self:Clip1() <= 0 then return false end
return true
end
function SWEP:PrimaryAttack()
if !self:CanPrimaryAttack() then return end
local shotsfired = self:GetNWInt("firedshots")
if self.FireModes[self:GetNWInt("FireMode")] == "burst" then
self:SetNWInt("firedshots", shotsfired + 1)
print(self:GetNWInt("firedshots"))
end
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self:ShootBullet()
end
[/code]
How can I make sure that the client will fire the correct amount of bullets?
I have a question about the Material
If I generate too much material, will it make client crash?
If it is, Do i have to do garbage cleaning with the Material?
If I have to, How?
How can I render a ParticleEffect in a DModelPanel?
[QUOTE=meharryp;52340613]How can I render a ParticleEffect in a DModelPanel?[/QUOTE]
[url]http://wiki.garrysmod.com/page/Global/ParticleEffect[/url] ? You can't.
You can however do use this:
[url]http://wiki.garrysmod.com/page/CNewParticleEffect/Render[/url]
I need a function to return the angle between two points.
I'm making a rocket launcher and the rocket needs to start out pointed at where the player is pointing so I can stop having the rocket spawn dead center.
So like ENT:PointAtEntity() but more generic.
I can't find the source for that in the garrysmod github, so I'm here
[QUOTE=a1steaksa;52341604]I need a function to return the angle between two points.
I'm making a rocket launcher and the rocket needs to start out pointed at where the player is pointing so I can stop having the rocket spawn dead center.[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/Angle]Vector:Angle[/url]
[code]
local ang = (p1 - p2):Angle()
[/code]
omg snip wrong thread
[QUOTE=bigdogmat;52341615][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/Angle]Vector:Angle[/url]
[code]
local ang = (p1 - p2):Angle()
[/code][/QUOTE]
Beautiful, thank you
I apologize in advance if my question is too confusing.
How do I determine the correct spread of a weapon using a 2d vector place on the player's HUD?
In order words, how do I make it so that my HUD crosshair reflects where the bullet is going to go?
I've been using a rough formula that's been relatively accurate: cone*900*(desiredfov/currentfov)
but it's garbage and it isn't entirely accurate, I'm concerned about other aspect rations and different fovs.
I looked at the Mad Cows weapon base for reference and it's an even bigger clusterfuck than what I have now
[code]local gap = ((self.Primary.Cone * 275) + (((self.Primary.Cone * 275) * (ScrH() / 720))) * (1 / self:CrosshairAccuracy())) * 0.75[/code]
I know that a self.Primary.Cone of 1 is basically "The gun shoots 360 degrees" but 275 is used for some reason. This formula also doesn't account for FOV.
[QUOTE=rebel1324;52339413]I have a question about the Material
If I generate too much material, will it make client crash?
If it is, Do i have to do garbage cleaning with the Material?
If I have to, How?[/QUOTE]
Are you talking about CreateMaterial? Yeah, you can theoretically crash the game if you somehow manage to generate almost 2 gigabyte worth of materials. I doubt you will ever get there.
Afaik you can't unload them at will, the game will do that on map change.
[QUOTE=rebel1324;52339413]I have a question about the Material
If I generate too much material, will it make client crash?
If it is, Do i have to do garbage cleaning with the Material?
If I have to, How?[/QUOTE]
FWIW, I know one guy who essentially creates a custom material for each entity in the game, sometimes more than one per entity (for multi-material entities). You're probably good.
Don't go crazy with textures though, those are what REALLY uses up memory. Not sure if they get garbage collected or not.
[QUOTE=ROFLBURGER;52343333]I apologize in advance if my question is too confusing.
How do I determine the correct spread of a weapon using a 2d vector place on the player's HUD?
In order words, how do I make it so that my HUD crosshair reflects where the bullet is going to go?
I've been using a rough formula that's been relatively accurate: cone*900*(desiredfov/currentfov)
but it's garbage and it isn't entirely accurate, I'm concerned about other aspect rations and different fovs.
I looked at the Mad Cows weapon base for reference and it's an even bigger clusterfuck than what I have now
[code]local gap = ((self.Primary.Cone * 275) + (((self.Primary.Cone * 275) * (ScrH() / 720))) * (1 / self:CrosshairAccuracy())) * 0.75[/code]
I know that a self.Primary.Cone of 1 is basically "The gun shoots 360 degrees" but 275 is used for some reason. This formula also doesn't account for FOV.[/QUOTE]
I'm not great with maths so feel free to correct me but:
Spread is a vector defining how much random x-y is given to the direction vector, a spread of 0.1x would mean that the direction can sway 0.1 either left or right. So we can use [url=http://wiki.garrysmod.com/page/Vector/Angle]this[/url] to translate the potential direction difference to degrees.
Then if the degrees of potential change is 30, and we know our fov is 90 then the reticle should be 33% the width of our screen
.. maybe
would it be possible to make loading screen for custom gamemode or does it have to be always made in server?
[QUOTE=>>oubliette<<;52345976]I'm not great with maths so feel free to correct me but:
Spread is a vector defining how much random x-y is given to the direction vector, a spread of 0.1x would mean that the direction can sway 0.1 either left or right. So we can use [url=http://wiki.garrysmod.com/page/Vector/Angle]this[/url] to translate the potential direction difference to degrees.
Then if the degrees of potential change is 30, and we know our fov is 90 then the reticle should be 33% the width of our screen
.. maybe[/QUOTE]
I've tried before that but the math doesn't work out. Either that means that FOV is not what we think it is or that the spread of the weapon doesnt' work like I think it works.
[code] local ConeAngle = (self:HandleCone(self.Primary.Cone,true,false)*360) -- THE IS THE CONE, IN AN ANGLE. A CONE OF 1 MEANS IT SHOOTS ALL AROUND SO IT'S CONVERTED TO AN ANGLE BY MULTIPLYING IT BY 30
local FOV = self.Owner:GetFOV() -- THIS IS THE FOV. 360 MEANS IT SHOWS ALL AROUND
-- OK SO A FOV OF 360 AND A CONEANGLE OF 360 MEANS THAT THE CONE GAP SHOULD BE 1 * ScrW()
-- OK SO A FOV OF 90 AND A CONEANGLE OF 90 MEANS THAT THE CONE GAP SHOULD BE 1 * ScrW()
-- OK SO A FOV OF 90 AND A CONEANGLE OF 45 MEANS THAT THE CONE GAP SHOULD BE 0.5 * ScrW()
--print(ConeAngle)
RightCone = (ConeAngle/FOV) * ScrH() * 0.25[/code]
This is what I have so far. Using ScrW() makes the crosshair larger than it should be. ScrH() does the same thing, but I have to multiply it by 0.25 in order for it to be accurate.
What I have is fine but it's not 100% accurate.
Don't forget that player FOV and weapon FOV are different.
Sorry, you need to Log In to post a reply to this thread.