Shirk Posted January 12, 2014 Share Posted January 12, 2014 I havent dealt much with lua before, so Im trying to learn a bit of it by picking apart the code from the given files. There is no HUD or anything that comes with the example fpsweapon.lua so I decided I wanted to try and make one. Ive added the following function to fpsweapon.lua, but it doesn't seem to work at all. function Script:Loop() self.context:SetBlendMode(Blend.Alpha) self.context:SetColor(1,1,1,1) self.context:DrawText("Ammo ",92,92) return true end Quote Link to comment Share on other sites More sharing options...
ChrisV Posted January 12, 2014 Share Posted January 12, 2014 Try this: function Script:Loop() self.context:SetBlendMode(Blend.Alpha) self.context:SetColor(1,1,1,1) self.context:DrawText("Ammo ",92,92) -- Add these two lines self.context:SetBlendMode(Blend.Solid) self.context:Sync() return true end Also, in your start function, be sure to set the font. I'm not sure if that's needed, but just in case. Quote My Artwork. ZBrush 4R7 64-bit - 3DCoat 4.5 BETA 12 - Fl Studio 12 64Bit - LE 3.2 Indie version - Truespace 7 - Blender 2.71 - iClone 5.51 Pro - iClone 3DXChange 5.51 pipeline - Kontakt 5 - Bryce 7 - UU3D Pro - Substance Designer/Painter - Shadermap 3 - PaintShop Photo Pro X7 - Hexagon - Audacity - Gimp 2.8 - Vue 2015 - Reaktor 5 - Guitar Rig 5 - Bitmap2Material 3 Link to comment Share on other sites More sharing options...
Shirk Posted January 12, 2014 Author Share Posted January 12, 2014 Thanks for the response, but that doesn't seem to do anything. I added a simple print ("Test") to the loop function, but it appears that the whole function isn't even called. Quote Link to comment Share on other sites More sharing options...
ChrisV Posted January 12, 2014 Share Posted January 12, 2014 Hmm, this works for me : function App:Start() self.window = Window:Create() self.context = Context:Create(self.window) local font = Font:Load("Fonts/Arial.ttf",36) self.context:SetFont(font) font:Release() return true end function App:Loop() if (self.window:Closed() or self.window:KeyDown(Key.Escape)) then return false end self.context:SetColor(0,0,0) self.context:Clear() --Draw text on screen local text = "LEADWERKS" local text2 = "IS" local text3 = "AWESOME !!!" local font = self.context:GetFont() x = 0 y = 0 self.context:SetBlendMode(Blend.Alpha) self.context:SetColor(1,0.0,1) self.context:DrawText(text,x,y) self.context:SetColor(0.3,1,1) self.context:DrawText(text2,x,y+30) self.context:SetColor(1,1,0) self.context:DrawText(text3,x,y+60) self.context:SetBlendMode(Blend.Solid) self.context:Sync() return true end Quote My Artwork. ZBrush 4R7 64-bit - 3DCoat 4.5 BETA 12 - Fl Studio 12 64Bit - LE 3.2 Indie version - Truespace 7 - Blender 2.71 - iClone 5.51 Pro - iClone 3DXChange 5.51 pipeline - Kontakt 5 - Bryce 7 - UU3D Pro - Substance Designer/Painter - Shadermap 3 - PaintShop Photo Pro X7 - Hexagon - Audacity - Gimp 2.8 - Vue 2015 - Reaktor 5 - Guitar Rig 5 - Bitmap2Material 3 Link to comment Share on other sites More sharing options...
Shirk Posted January 12, 2014 Author Share Posted January 12, 2014 Editing App.lua works for me too, but I want to edit the fpsweapon.lua to be able to display an ammo counter. Quote Link to comment Share on other sites More sharing options...
ChrisV Posted January 12, 2014 Share Posted January 12, 2014 The above script, i had it attached to a camera. The draw commands need a camera to work (either created in the code, or by attaching the script to a camera). The fpsweapon.lua script doesn't have a camera (in the code), so it won't work. It should work in the FPSPlayer.lua script, since there is a camera created in the script. Quote My Artwork. ZBrush 4R7 64-bit - 3DCoat 4.5 BETA 12 - Fl Studio 12 64Bit - LE 3.2 Indie version - Truespace 7 - Blender 2.71 - iClone 5.51 Pro - iClone 3DXChange 5.51 pipeline - Kontakt 5 - Bryce 7 - UU3D Pro - Substance Designer/Painter - Shadermap 3 - PaintShop Photo Pro X7 - Hexagon - Audacity - Gimp 2.8 - Vue 2015 - Reaktor 5 - Guitar Rig 5 - Bitmap2Material 3 Link to comment Share on other sites More sharing options...
SarperSoher Posted January 12, 2014 Share Posted January 12, 2014 Script:PostRender() This function will be called following a call to World::Render(). Use this for 2D drawing for HUDs, health meters, map displays, etc. So you can do this and it will work just fine in any script; function Script:PostRender() local context = Context:GetCurrent() context:SetBlendMode(Blend.Alpha) context:SetColor(1,1,1,1) context:DrawText("Ammo ",92,92) context:SetBlendMode(Blend.Solid) end Quote Link to comment Share on other sites More sharing options...
ChrisV Posted January 12, 2014 Share Posted January 12, 2014 Ah yes, very true, SarperSoher! I'm gettin used to the LE 3.1 commands. Thanks for pointing that out. Quote My Artwork. ZBrush 4R7 64-bit - 3DCoat 4.5 BETA 12 - Fl Studio 12 64Bit - LE 3.2 Indie version - Truespace 7 - Blender 2.71 - iClone 5.51 Pro - iClone 3DXChange 5.51 pipeline - Kontakt 5 - Bryce 7 - UU3D Pro - Substance Designer/Painter - Shadermap 3 - PaintShop Photo Pro X7 - Hexagon - Audacity - Gimp 2.8 - Vue 2015 - Reaktor 5 - Guitar Rig 5 - Bitmap2Material 3 Link to comment Share on other sites More sharing options...
Shirk Posted January 13, 2014 Author Share Posted January 13, 2014 Alright so I got my basic HUD working, displays health and ammo. I decided to try and add vignette, which I have successfully except one small problem, the vignette layer is above the ammo layer so so it gets displayed above it, where as I would prefer it displayed below. The health displays above it (because I have the code written after the vignette in fpsplayer.lua). Here is what Im talking about. How do I get my ammo to display above the vignette layer? Quote Link to comment Share on other sites More sharing options...
SarperSoher Posted January 13, 2014 Share Posted January 13, 2014 Wait you are saying the health display is above it because you have the code written after the vignette but ammo is below it and how you can make it so that it's displayed above the vignette? You already know the solution as it appears. Quote Link to comment Share on other sites More sharing options...
Shirk Posted January 13, 2014 Author Share Posted January 13, 2014 (edited) The health is displayed from FPSPlayer.lua, where as the ammo is displayed from FPSWeapon.lua, and Im assuming fpsweapon.lua is ran before fpsplayer.lua. Im not sure how to get the variables I used in fpsweapon.lua to work in fpsplayer.lua. Thats kind of confusing, basically Im assuming one file is ran before the other, and so the vignette is displayed above. I cant use the ammo variables defined in fpsweapon.lua in fpsplayer.lua, if I could, then I would know how to fix the problem. Edited January 13, 2014 by Shirk Quote Link to comment Share on other sites More sharing options...
CustomZ02 Posted January 18, 2014 Share Posted January 18, 2014 (edited) How did you get the ammo counter to work? I tried the above codes and all I get is ammo: displayed but no actual information. And if you don't mind me asking, whats the code for displaying the health bar. Im new to lua myself only ever touched visual basic stuff. Also, anyone know why the AI runs backwards? I tried rotating the enemy 180 but it doesnt seem to do anything. Edited January 18, 2014 by CustomZ02 Quote Link to comment Share on other sites More sharing options...
nate066 Posted January 18, 2014 Share Posted January 18, 2014 How did you get the ammo counter to work? I tried the above codes and all I get is ammo: displayed but no actual information. And if you don't mind me asking, whats the code for displaying the health bar. Im new to lua myself only ever touched visual basic stuff. Also, anyone know why the AI runs backwards? I tried rotating the enemy 180 but it doesnt seem to do anything. You have pass the ammo varible to the draw command. And set the physics charactor angle to 180 degrees Quote Link to comment Share on other sites More sharing options...
CustomZ02 Posted January 18, 2014 Share Posted January 18, 2014 (edited) You have pass the ammo varible to the draw command. And set the physics charactor angle to 180 degrees Sorry, but where would I find the ammo variable. I see a few things in the FPSweaopn script "Script.ammo=200". Im sorry for the dumb questions but im confused here >.< NVM figured it out: local ammocount = self.ammo //to set the variable drawtext(ammocount,92,650) // to display ammo Edited January 18, 2014 by CustomZ02 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.