• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
1) Try it 2) Those are absolute positions, you gotta need to use Relative positions
So predicting my SWEP's burst fire by calling it in Think was an idea. But visually I am seeing way more than 3 shots being fired! function SWEP:DoBurstNew() local ply = self.Owner local Bullet = {} Bullet.Num = 1 Bullet.Src = ply:GetShootPos() Bullet.Dir = (ply:GetAimVector():Angle()+ply:GetViewPunchAngles()):Forward() Bullet.Spread = Vector( .05+((3-self:GetShotsToFire())*.02), .05+((3-self:GetShotsToFire())*.02), 0 ) Bullet.Tracer = 1 Bullet.Damage = self.Primary.Damage Bullet.AmmoType = self.Primary.Ammo if CurTime() > self:LastShootTime()+.02 && self:GetShotsToFire() >= 3 then Bullet.Dir = (ply:GetAimVector():Angle()+ply:GetViewPunchAngles()):Forward() Bullet.Spread = Vector( .05+((3-self:GetShotsToFire())*.02), .05+((3-self:GetShotsToFire())*.02), 0 ) self.Owner:FireBullets(Bullet) self:TakePrimaryAmmo(1) self:SetShotsToFire(2) elseif CurTime() > self:LastShootTime()+.02 && self:GetShotsToFire() == 2 then Bullet.Dir = (ply:GetAimVector():Angle()+ply:GetViewPunchAngles()):Forward() Bullet.Spread = Vector( .05+((3-self:GetShotsToFire())*.02), .05+((3-self:GetShotsToFire())*.02), 0 ) self.Owner:FireBullets(Bullet) self:TakePrimaryAmmo(1) self:SetShotsToFire(1) ply:ViewPunch( Angle(-self.Primary.Recoil,math.Rand(-1,1),0) ) elseif CurTime() > self:LastShootTime()+.02 && self:GetShotsToFire() == 1 then Bullet.Dir = (ply:GetAimVector():Angle()+ply:GetViewPunchAngles()):Forward() Bullet.Spread = Vector( .05+((3-self:GetShotsToFire())*.02), .05+((3-self:GetShotsToFire())*.02), 0 ) self.Owner:FireBullets(Bullet) self:TakePrimaryAmmo(1) self:SetShotsToFire(0) ply:ViewPunch( Angle(-self.Primary.Recoil,math.Rand(-1,1),0) ) end end and I think part of the issue is idk what should be SERVER or what should be CLIENT only.
Single-player uses fake prediction in Think for shooting simulation. Use IsFirstTimePredicted for single-player only.
Can I disable the sounds playing by npc_combine_camera?
But if IsFirstTimePredicted is shared shouldn't it be ok to use for both single player and multiplayer? Also I'm trying to form code around an idea of optimization and security, less filler code and preforming tasks with as little processing as possible. Does anyone have any good resources I can read about this? I know GLua isn't exactly a professional programming language but it's a place to start and getting good programming practices here is a good gateway to other languages.
Use the EntityEmitSound hook and return true if it's coming from that entity class.
Shared means it can be used server-side and client-side, and doesn't relate to the mode, but regardless, the Think hook is just an exception for single-player. Really, it shouldn't be called but Garry added a hack out of prediction.
Well I solved the bullet spam by adding this line to the top of the function: if game.SinglePlayer() && !IsFirstTimePredicted() then return end cus if IsFirstTimePredicted is shared... I don't wanna call it on SERVER right?
It will always return true serverside, so you can use it shared.
function GM:EntityEmitSound(data) if not data then return end local ent = data.Entity if not ent or not IsValid(ent) then return end if ent:GetClass() == "npc_combine_camera" then return end end
Did you even read what the page says? Returning nil will just play the sound normally, use hook.Add and return FALSE to stop the sound from playing, or, modify the table and return TRUE to apply changes. I don't remember but I believe this needs to be called in a shared environment
Trig question. I have an arbitrary position in the world (not to any entity, just a random position), and I have a render.RenderView() pointing to that location. How do I get the proper angle to look at the position? The camera is placed up high, and the target position is down low. Do I simply dot the two vectors?
(TargetPos - CameraPos):Angle() will find the angle needed for the camera to point directly at TargetPos. You can see the maths behind it here.
Ok here's a thing I don't understand. I don't want to completely overwrite how damage is handled, but if for example an attack came in with 250 damage and a player who got hit by that attack had 67 HP and 100 ARMOR... and I want ARMOR to mean you can't get killed by an attack. well, I can try to sethealth back to 67 but I don't think that matters, he's dead.
GM:EntityTakeDamage
30 damage. armor takes 20, health takes 0. 30 damage of some other damage type...armor takes 10 health takes 0. How can I let the damage happen to armor... but take no health damage...? help
You block the health damage and manualy take the suit energy
Example?
I wanted to avoid manually taking the suit energy tho, cus that messes with damage scaling pretty sure. I think things that would've done fractions of damage (where taking enough shots actually loses a point, more than one) would no longer add up the same. Not 100% sure how to block health damage without blocking suit damage.
-- Inside of the hook if (pEntity:GetClass() == "foo") then return true end
hook.Add("EntityEmitSound", "RemoveCobmineCameraSound", function(data) local ent = data.Entity if ent:GetClass() == "npc_combine_camera" then return true end end) Not working
Please do yourself a favor and learn to read the wiki. wiki.garrysmod.com/page/GM/EntityEmitSound The wiki contains a ton of helpful information and examples and is essential for anyone trying to develop on Gmod
What way should I make traces from the skybox or just max height of the map to the ground in random locations? I'm trying to spawn things in random places and I want to make sure it's always on the ground and visible from the sky.
Trace straight down for ground, trace straight up and check tr.HitSky for sky visibility (only straight up, though).
Yeah I tried that. Its NOT working.
How would I auto resize DListView Columns to fit it's contents? I have a column labeled # that I want to decrease the width of but can't find anything on the wiki
maybe SetDirty
Would anybody know how to detect a loop that runs longer than my threshold and stop
I'm trying to make a block for ulx crashers. Ulx extended uses some skiddy sendlua while true do end. So I was wondering if there was a way to detect this and stop it
Don’t rely on SendLua since there’s almost never a reason to use it, replace it with whatever.
Sorry, you need to Log In to post a reply to this thread.