• Bullet Callback function, how to make impact effects?
    8 replies, posted
Here's the section of code that matters: [lua] local burret = {} burret.Attacker = self.Owner burret.Num = self.Burrets if self.Shot1 then burret.Num = 2 -- I'm going to try to average the rounds per burst of the Helicopter, 5. This gun fires a lot faster, though, so I halved it. else burret.Num = 3 -- I will do that by alternating between 2 and 3 rounds, changing the setting at every new fire. Half of 5 is 2.5, but I can't use decimals. end burret.Src = self.Owner:GetShootPos() burret.Dir = self.Owner:GetAimVector() burret.Spread = Vector(self.Spread,self.Spread) burret.Callback = function(DInf, hPos, Dir) -- <-- THIS IS WHERE THE CALLBACK STARTS local EffectI = EffectData() for i=1,#hPos do EffectI:SetOrigin(hPos.i) EffectI:SetStart(hPos.i) end for i=1,#Dir do EffectI:SetNormal((-Dir.i):Normalize()) end EffectI:SetMagnitude(8) EffectI:SetRadius(3) util.Effect( "cball_bounce", EffectI, true, true) util.Effect( "StunstickImpact", EffectI, true, true) end -- <-- THIS IS WHERE THE CALLBACK ENDS. THESE COMMENTS ADDED, AND ONLY HERE, TO HELP YOU. burret.Hull = 6 -- Tiny, centered. burret.Tracer = 1 burret.TracerName = self.Tracer burret.Force = self.BurretForce burret.Damage = math.random(self.DMGMin,self.DMGMax) -- The helicopter does 6 dmg to npc's, 3 to plr's. Let's cut the difference, but I can't use decimals so I switch between 4 and 5 on every shot. The difference is 4.5 burret.AmmoType = self.Primary.Ammo if self.DoCrits then if self.CanCrit then burret.Damage = burret.Damage+(self.CritScale*burret.Damage) -- self:EmitSound( Sound( "Weapon_SMG.SingleCrit" ) ) -- Criticals don't seem to work in a base. end end -- I suppose I don't need the extra variable to see if we got a cirtical, "CanCrit", but whatever. self.Owner:FireBullets( burret ) -- self:EmitSound( self.ShootSound ) self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self:SetNextPrimaryFire( CurTime()+self.Primary.Delay )[/lua] But I keep getting this error: [ERROR] addons/chamberweapons/lua/weapons/cm_battery/shared.lua:234: attempt to get length of local 'Dir' (a userdata value) 1. unknown - addons/chamberweapons/lua/weapons/cm_battery/shared.lua:234 2. FireBullets - [C]:-1 3. unknown - addons/chamberweapons/lua/weapons/cm_battery/shared.lua:257 So how do I make those effects at the impact location without getting any errors? Right now it doesn't do a thing. I'd rather not start a new thread for this question, but I don't really have much of a choice right now. I want to imitate the effect that is made when the Helicopter's Gun's Bullets hit something, but not all of the effects work, I know that those effects (cball_bounce and StunstickImpact) will work. I need help getting this working. [editline]30th March 2013[/editline] Okay, I guess no one is willing to help, eh? What are some weapons that create effects at their impact zone and don't fire straight?
I'm not editing because editing kills Lua tags... I don't want all of my code to show up as one long ass line! I'm really going to need help here, I can't find a single swep that uses the modern code for Callback functions, as far as the wiki says there is no trace returned, but that would make this a hell-of-a-lot easier!
Hey Lua at least wait a week before bumping please, because many of us are busy in real life, or we're coding our own gamemodes and what not. real life comes first [lua]EffectI:SetNormal((-Dir.i):Normalize())[/lua] Try [lua]EffectI:SetNormal((Dir:GetPos() - i):Normalize())[/lua] It says a userdata so it has to be GetEyetrace or GetPos or something
You are using the # operator on Userdata values (hPos and Dir). [editline]31st March 2013[/editline] That is what is causing the error.
[QUOTE=RetTurtl3;40100606]Hey Lua at least wait a week before bumping please, because many of us are busy in real life, or we're coding our own gamemodes and what not. real life comes first [lua]EffectI:SetNormal((-Dir.i):Normalize())[/lua] Try [lua]EffectI:SetNormal((Dir:GetPos() - i):Normalize())[/lua] It says a userdata so it has to be GetEyetrace or GetPos or something[/QUOTE] THAT WASN'T MY GOAL jeez!!! I didn't want to edit because it ruins anything in Lua tags! [editline]30th March 2013[/editline] [QUOTE=MakeR;40100702]You are using the # operator on Userdata values (hPos and Dir). [editline]31st March 2013[/editline] That is what is causing the error.[/QUOTE] I know... how do I fix that? I don't think it matters, though, I need to know how to do this from scratch. [editline]30th March 2013[/editline] Also, if Dir is a direction, which it is, how would :GetPos() help?? [editline]30th March 2013[/editline] The code has already changed, anyways...
Instead of :Normalize, try :GetNormal().
If I understand what you are trying to achieve then this is what you need to do: [lua]burret.Callback = function(DInf, hPos, Dir) local EffectI = EffectData() EffectI:SetOrigin(hPos) EffectI:SetStart(hPos) EffectI:SetNormal(-Dir) EffectI:SetMagnitude(8) EffectI:SetRadius(3) util.Effect( "cball_bounce", EffectI, true, true) util.Effect( "StunstickImpact", EffectI, true, true) end [/lua]
Why not just use SWEP:DoImpactEffect( tr, dmgtype )? Just make sure to return true to block the default tracer
<([{SNIP}])> So it works like a charm using DoImpactEffect, thank you very, very much!! [URL]http://youtu.be/vBhPCZEWLOE[/URL] It doesn't seem to want to embed it as a video, I just get this: [IMG]http://youtu.be/vBhPCZEWLOE[/IMG]
Sorry, you need to Log In to post a reply to this thread.