Jump to content

Simple ammo counter?


Shirk
 Share

Recommended Posts

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

Link to comment
Share on other sites

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. wink.png

 

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

Hmm, this works for me smile.png :

 

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

 

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

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.

 

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

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

Link to comment
Share on other sites

Ah yes, very true, SarperSoher! smile.png

I'm gettin used to the LE 3.1 commands. Thanks for pointing that out. wink.png

 

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

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?

Screenshot%202014-01-13%2004.10.38.png

Link to comment
Share on other sites

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 by Shirk
Link to comment
Share on other sites

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 by CustomZ02
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by CustomZ02
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...