Thirsty Panther Posted September 24, 2014 Share Posted September 24, 2014 I'm creating a FPS game but I've run into a problem with the Pistol prefab. I have a health bar for the player ( from Aggrors video tutorials) and every time I fire the pistol the health bar flashes simultaneously with the muzzle flash. Any help would be appriciated. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 24, 2014 Share Posted September 24, 2014 Can you post your draw script. Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted September 24, 2014 Author Share Posted September 24, 2014 Update: I've ruled out the Player Health Bar overlay as the problem. I thought it may have something to do with the Alpha channel. I also changed the colours of the Health Bar to no effect. The scripts are as follows: Pistol: function Script:Draw() local t = Time:GetCurrent() if self.muzzlelight:Hidden()==false then if t-self.firetime>50 then self.muzzlelight:Hide() end end local jumpbob = 0 if self.jumpoffset<0 then jumpbob = (Math:Sin(self.jumpoffset))*0.01 self.jumpoffset = self.jumpoffset + 8 end if self.landoffset<0 then jumpbob = jumpbob + (Math:Sin(self.landoffset))*0.01 self.landoffset = self.landoffset + 10 end --Animate the weapon local bob = 0; local speed = math.max(0.1,self.player.entity:GetVelocity():xz():Length()) if self.player.entity:GetAirborne() then speed = 0.1 end self.swayspeed = Math:Curve(speed,self.swayspeed,20) self.swayspeed = math.max(0.5,self.swayspeed) self.amplitude = math.max(2,Math:Curve(speed,self.amplitude,20)) self.timeunits = self.timeunits + self.swayspeed*4*Time:GetSpeed() local sway = math.sin(self.timeunits/120.0) * self.amplitude * self.maxswayamplitude bob = (1-math.cos(self.timeunits/60.0)) * self.maxswayamplitude * 0.1 * self.amplitude local campos = self.player.camera:GetPosition(true) self.smoothedposition.x = campos.x self.smoothedposition.y = Math:Curve(campos.y,self.smoothedposition.y,2) self.smoothedposition.z = campos.z self.entity:LockMatrix() self.entity:SetPosition(sway*self.entity.scale.x,bob+jumpbob,0) self.entity:Translate(self.offset.x,self.offset.y,self.offset.z) self.animationmanager:Update() self.entity:UnlockMatrix() end Health Bar: function Script:PostRender(context) --background context:SetColor(self.backgroundColorFractioned) context:DrawRect(self.offset.x, context:GetHeight() - self.offset.y, self.size.x, self.size.y) --healthbar context:SetColor(self.healthbarColorFractioned) local healthFactor = self.player.script.health / self.player.script.maxHealth context:DrawRect(self.offset.x,context:GetHeight() - self.offset.y, self.size.x * healthFactor, self.size.y) --Draw overlay if self.overlay ~= nil then context:SetBlendMode(Blend.Alpha) context:SetColor(1,1,1,1) context:DrawImage(self.overlay, 0, context:GetHeight() - self.overlay:GetHeight()) context:SetBlendMode(Blend.Solid) end end Both these scripts are unaltered from Leadwerks (Pistol prefab) and Aggror (Player Health Bar). Thanks. Quote Link to comment Share on other sites More sharing options...
CoolBeans Posted April 3, 2015 Share Posted April 3, 2015 Same problem we seek knowledge from the wise ones. http://www.leadwerks.com/werkspace/topic/12388-attempt-to-index-field-player-a-nil-value/ Thank you. CB Quote Link to comment Share on other sites More sharing options...
Jazz Posted April 4, 2015 Share Posted April 4, 2015 Health Bar: function Script:PostRender(context) --background context:SetColor(self.backgroundColorFractioned) context:DrawRect(self.offset.x, context:GetHeight() - self.offset.y, self.size.x, self.size.y) --healthbar context:SetColor(self.healthbarColorFractioned) local healthFactor = self.player.script.health / self.player.script.maxHealth context:DrawRect(self.offset.x,context:GetHeight() - self.offset.y, self.size.x * healthFactor, self.size.y) --Draw overlay if self.overlay ~= nil then context:SetBlendMode(Blend.Alpha) context:SetColor(1,1,1,1) context:DrawImage(self.overlay, 0, context:GetHeight() - self.overlay:GetHeight()) context:SetBlendMode(Blend.Solid) end end Both these scripts are unaltered from Leadwerks (Pistol prefab) and Aggror (Player Health Bar). Thanks. Does putting context:SetBlendMode(Blend.Alpha) right at the start of the postrender function help? Quote --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
CoolBeans Posted April 4, 2015 Share Posted April 4, 2015 You are the man! Thank you very much! Works like a champ I really appreciate you helping out. Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted April 5, 2015 Author Share Posted April 5, 2015 Thanks Jazz. Works perfectly now. Quote Link to comment Share on other sites More sharing options...
BluHornet Posted April 7, 2015 Share Posted April 7, 2015 Also tip for the guy that spent a lot of time trying to fix issues. When you set the blend mode to alpha at the end of that function set the blend mode back to solid. I have had other rendering issues due to not setting the blend modes properly, typically when more than one script is using context. Quote Link to comment Share on other sites More sharing options...
CoolBeans Posted April 7, 2015 Share Posted April 7, 2015 Thanks for the tip BH. I'm starting to see how every problem overcome is a valuable learning experience. Just a few weeks ago I thought I would never get this but already I'm fixing things and learning fast. I know I'm a long long long way away but every time I think that I learn something new and the motivation sticks. Never thought it could be so frustrating wanting to learn everything yesterday. Why wasn't it like that back in school . Of course I have many of you to thank for your help so thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.