• Dynamic Light and other apply player color
    0 replies, posted
I 1 day crash my brain at mission to apply player/weapon color to effects and dynamic lights, I have only console errors "A nil value!" this code from dynamic light function SWEP:DoImpactEffect( tr, nDamageType )     if ( tr.HitSky ) then return end                       local effectdata = EffectData()     effectdata:GetColor( WeaponColor )     effectdata:SetOrigin( tr.HitPos + tr.HitNormal )     effectdata:SetNormal( tr.HitNormal )     util.Effect( "cball_explode", effectdata )     sound.Play( "weapons/physcannon/superphys_launch2.wav", Vector ( tr.HitPos + tr.HitNormal ) )              if CLIENT then             local dlight = DynamicLight( self:EntIndex() )             if ( dlight ) then                                  --local r, g, b, a = Vector (dlight:GetWeaponColor().r / 255, dlight:GetWeaponColor().g / 255, dlight:GetWeaponColor().b / 255) -- 1st variant                 --local r, g, b, a = 255, 50, 50 -- baisc color                 local r, g, b, a = WeaponColor(GetColor).r, WeaponColor(GetColor).g, WeaponColor(GetColor).b, WeaponColor(GetColor).a -- last variant                 dlight.Pos = tr.HitPos + tr.HitNormal                 dlight.r = r                 dlight.g = g                 dlight.b = b                 dlight.Brightness = 4                 dlight.Size = 256                 dlight.Decay = 0                 dlight.DieTime = CurTime( ) + 0.1                 dlight.Style = 0             end         end end console [TFA Base] nexuiz/lua/weapons/nexuiz_tfa_hlac_laser_carbine_scoped/shared.lua:45: attempt to call global 'WeaponColor' (a nil value)   1. unknown - addons/[tfa] nexuiz/lua/weapons/nexuiz_tfa_hlac_laser_carbine_scoped/shared.lua:45    2. FireBullets - [C]:-1     3. BallisticFirebullet - lua/weapons/tfa_gun_base/sh_bullet.lua:29      4. ShootBullet - lua/weapons/tfa_gun_base/sh_bullet.lua:179       5. ShootBulletInformation - lua/weapons/tfa_gun_base/sh_bullet.lua:59        6. unknown - lua/weapons/tfa_gun_base/shared.lua:1291 [TFA Base] nexuiz/lua/weapons/nexuiz_tfa_hlac_laser_carbine_scoped/shared.lua:42: attempt to call method 'GetWeaponColor' (a nil value)   1. unknown - addons/[tfa] nexuiz/lua/weapons/nexuiz_tfa_hlac_laser_carbine_scoped/shared.lua:42    2. FireBullets - [C]:-1     3. BallisticFirebullet - lua/weapons/tfa_gun_base/sh_bullet.lua:29      4. ShootBullet - lua/weapons/tfa_gun_base/sh_bullet.lua:179       5. ShootBulletInformation - lua/weapons/tfa_gun_base/sh_bullet.lua:59        6. unknown - lua/weapons/tfa_gun_base/shared.lua:1291 And how to make get weapon color for tracer effect? This code of tracer TRACER_FLAG_USEATTACHMENT    = 0x0002; SOUND_FROM_WORLD            = 0; CHAN_STATIC                    = 6; EFFECT.Speed                = 6500; EFFECT.Length                = 64; //EFFECT.WhizSound            = Sound( "nomad/whiz.wav" );        -- by Robinhood76 (http:--www.freesound.org/people/Robinhood76/sounds/96556/) EFFECT.WhizDistance            = 72; local MaterialMain            = Material( "effects/nexuiz_hlac_main" ); local MaterialFront            = Material( "effects/nexuiz_hlac_front" ); function EFFECT:GetTracerOrigin( data )     -- this is almost a direct port of GetTracerOrigin in fx_tracer.cpp     local start = data:GetStart();          -- use attachment?     if( bit.band( data:GetFlags(), TRACER_FLAG_USEATTACHMENT ) == TRACER_FLAG_USEATTACHMENT ) then         local entity = data:GetEntity();                  if( not IsValid( entity ) ) then return start; end         if( not game.SinglePlayer() and entity:IsEFlagSet( EFL_DORMANT ) ) then return start; end                  if( entity:IsWeapon() and entity:IsCarriedByLocalPlayer() ) then             -- can't be done, can't call the real function             -- local origin = weapon:GetTracerOrigin();             -- if( origin ) then             --     return origin, angle, entity;             -- end                          -- use the view model             local pl = entity:GetOwner();             if( IsValid( pl ) ) then                 local vm = pl:GetViewModel();                 if( IsValid( vm ) and not LocalPlayer():ShouldDrawLocalPlayer() ) then                     entity = vm;                 else                     -- HACK: fix the model in multiplayer                     if( entity.WorldModel ) then                         entity:SetModel( entity.WorldModel );                     end                 end             end         end         local attachment = entity:GetAttachment( data:GetAttachment() );         if( attachment ) then             start = attachment.Pos;         end     end          return start; end function EFFECT:Init( data )          self.StartPos = self:GetTracerOrigin( data );     self.EndPos = data:GetOrigin();          self.Entity:SetRenderBoundsWS( self.StartPos, self.EndPos );     local diff = ( self.EndPos - self.StartPos );          self.Normal = diff:GetNormal();     self.StartTime = 0;     self.LifeTime = ( diff:Length() + self.Length ) / self.Speed;          -- whiz by sound     local weapon = data:GetEntity();     if( IsValid( weapon ) and ( not weapon:IsWeapon() or not weapon:IsCarriedByLocalPlayer() ) ) then         local dist, pos, time = util.DistanceToLine( self.StartPos, self.EndPos, EyePos() );     end end function EFFECT:Think()     self.LifeTime = self.LifeTime - FrameTime();     self.StartTime = self.StartTime + FrameTime();          return self.LifeTime > 0; end function EFFECT:Render()     local effectdata = EffectData()     effectdata:GetColor(WeaponColor)          local endDistance = self.Speed * self.StartTime;     local startDistance = endDistance - self.Length;          startDistance = math.max( 0, startDistance );     endDistance = math.max( 0, endDistance );     local startPos = self.StartPos + self.Normal * startDistance;     local endPos = self.StartPos + self.Normal * endDistance;          render.SetMaterial( MaterialFront );     render.DrawSprite( endPos, 8, 8, color_white );     render.SetMaterial( MaterialMain );     render.DrawBeam( startPos, endPos, 10, 0, 1, color_white );     --self.CEffectData:SetColor( WeaponColor )     --self.GetWeaponColor( MaterialMain )     --self.GetWeaponColor( MaterialFront ) end
Sorry, you need to Log In to post a reply to this thread.