• Sparks on a Stunstick
    9 replies, posted
I have made a copy of the Stunstick so I could modify some properties of it, but it doesn't have the electric sparks that appear on the default Stunstick when you swing it. Does anyone know how to add that onto the weapon, both in the viewmodel but also in the world?
[CODE]SWEP.ViewModel = "models/weapons/v_stunstick.mdl" SWEP.WorldModel = "models/weapons/w_stunbaton.mdl" [/CODE] The name of the effect is [CODE]StunstickImpact[/CODE]
Unfortunately there isn't effect for draw electric sparks. Only hit effect, but stunstick model has attachments for sprites. Here is names: spark1a - spark9a and spark1b - spark9b.
[QUOTE=sabadyCZ;45666854]Unfortunately there isn't effect for draw electric sparks. Only hit effect, but stunstick model has attachments for sprites. Here is names: spark1a - spark9a and spark1b - spark9b.[/QUOTE] How do I attach sprites to these points? And what is/are the names for the sprite(s) that the Stunstick uses? I have already done StunstickImpact, I'm talking about the electric small bolts that emit from the top of the stunstick.
You can try my version. It looks similar like stunstick effect or you can look into Source codes. weapon.swingCur is start time of swing. [CODE] local white = Color(180,180,180) local beamMat = CreateMaterial("beamMaterial"..CurTime() , "UnlitGeneric", { ["$additive"] = 1, ["$basetexture"] = "sprites/lgtning" }); local sprites = { Material( "sprites/light_glow02_add_noz" ), Material( "sprites/light_glow02_add" ), Material( "effects/blueflare1" ) } hook.Add( "PostDrawViewModel", "stunstick", function(ViewModel, ply, weapon ) if IsValid(ViewModel) and IsValid(weapon) and ply:Alive() and weapon:GetClass() == "WEAPON_NAME" then local size = 12 - math.Clamp((CurTime()-weapon.swingCur)*1.25,0,1)*12 local eyepos = EyePos() local eyeangles = EyeAngles() if size != 0 then for i=1,9 do local ID = ViewModel:LookupAttachment("spark" .. i .. "a") local attach = ViewModel:GetAttachment( ID ) cam.Start3D(eyepos,eyeangles) render.SetMaterial( sprites[math.random(1,3)] ) render.DrawSprite( attach.Pos, size, size, white) cam.End3D() end for i=1,9 do local ID = ViewModel:LookupAttachment("spark" .. i .. "b") local attach = ViewModel:GetAttachment( ID ) cam.Start3D(eyepos,eyeangles) render.SetMaterial( sprites[math.random(1,3)] ) render.DrawSprite( attach.Pos, size, size, white) cam.End3D() end if math.random(1,3) == 3 then local attach = ViewModel:GetAttachment( math.random(1,18) ) local posTables = {attach.Pos} for i=1,3 do local Rand = VectorRand()*3 local offset = attach.Ang:Forward()*Rand.x + attach.Ang:Right()*Rand.y + attach.Ang:Up()*Rand.z local pos = posTables[i] cam.Start3D(eyepos,eyeangles) render.SetMaterial( beamMat ) render.DrawBeam( pos, pos + offset, 3.25-i, 1, 1.25, white ) cam.End3D() table.insert(posTables, pos + offset) end end end end end) [/CODE]
Anything like that would be better done in Weapon.[URL="http://wiki.garrysmod.com/page/WEAPON/PostDrawViewModel"]PostDrawViewModel[/URL]
[QUOTE=sabadyCZ;45667984]You can try my version. It looks similar like stunstick effect or you can look into Source codes. weapon.swingCur is start time of swing. [CODE] local white = Color(180,180,180) local beamMat = CreateMaterial("beamMaterial"..CurTime() , "UnlitGeneric", { ["$additive"] = 1, ["$basetexture"] = "sprites/lgtning" }); local sprites = { Material( "sprites/light_glow02_add_noz" ), Material( "sprites/light_glow02_add" ), Material( "effects/blueflare1" ) } hook.Add( "PostDrawViewModel", "stunstick", function(ViewModel, ply, weapon ) if IsValid(ViewModel) and IsValid(weapon) and ply:Alive() and weapon:GetClass() == "WEAPON_NAME" then local size = 12 - math.Clamp((CurTime()-weapon.swingCur)*1.25,0,1)*12 local eyepos = EyePos() local eyeangles = EyeAngles() if size != 0 then for i=1,9 do local ID = ViewModel:LookupAttachment("spark" .. i .. "a") local attach = ViewModel:GetAttachment( ID ) cam.Start3D(eyepos,eyeangles) render.SetMaterial( sprites[math.random(1,3)] ) render.DrawSprite( attach.Pos, size, size, white) cam.End3D() end for i=1,9 do local ID = ViewModel:LookupAttachment("spark" .. i .. "b") local attach = ViewModel:GetAttachment( ID ) cam.Start3D(eyepos,eyeangles) render.SetMaterial( sprites[math.random(1,3)] ) render.DrawSprite( attach.Pos, size, size, white) cam.End3D() end if math.random(1,3) == 3 then local attach = ViewModel:GetAttachment( math.random(1,18) ) local posTables = {attach.Pos} for i=1,3 do local Rand = VectorRand()*3 local offset = attach.Ang:Forward()*Rand.x + attach.Ang:Right()*Rand.y + attach.Ang:Up()*Rand.z local pos = posTables[i] cam.Start3D(eyepos,eyeangles) render.SetMaterial( beamMat ) render.DrawBeam( pos, pos + offset, 3.25-i, 1, 1.25, white ) cam.End3D() table.insert(posTables, pos + offset) end end end end end) [/CODE][/QUOTE] Many thanks, it worked even better than the default (because the default had the sprites offset so they looked like they were floating). Do you happen to know about the same thing for third person view/other peoples views? :P
I have only this. Try to find attachments for the worldmodel, but probably they don't exists. It isn't so hard to write the code when you have this.
Are there any ways to get a weapon models position? Like a position that follows it during a swing or gunshot recoil? Something that moves exactly the same way as the model? I might be able to use that as the origin and the offset it, so the sprites can be rendered exactly on the Stunsticks tip.
This follows the stun-stick in thirdperson, and firstperson: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/effects/stunstick_admin_baton_effects.lua.html[/url]
Sorry, you need to Log In to post a reply to this thread.