Jump to content

lua script for inventory


armylad2011
 Share

Recommended Posts

Make a table and write your items in it like this:

self.inventory[#self.inventory+1]={}
self.inventory[#self.inventory].name="Sword"
self.inventory[#self.inventory].amount=3

This will add 3 swords into your inventory. Then in PostRender you check if inventory menu is opened, and if it is you loop through inventory and draw items icons:

for i=1, #self.inventory do
context:DrawImage(Texture:Load("folderWithIcons/"..self.inventory[i].name), 100, 100+i*50)
context:DrawText(self.inventory[i].amount, 120, 100+i*50)
end

Link to comment
Share on other sites

hi there thanx for the script but i have tried to sort mine out lol

 

i have restarted it all again when im on the final bit putting the item into my inventory nothing happens.

 

i have looked in the output and it says "we got the inventory Item B we place the bottle in the inventory

bottle

Loading shader "E:/leadwerks/MyGame/Shaders/Model/default.shader.....

process complete."

Link to comment
Share on other sites

i just added the self.items before the return and still the same lol i also downloaded the script and used that so i know they wouldn't be any typo but for some reason its not drawing my bottle icon ? im finding it hard as im not used to Lua or c++ in the past i used a built in interface GML i think it was called it was set out different to what im used to so finding errors is abit difficult for me lol sorry to be a big pain for you guys lol

Link to comment
Share on other sites

Replace the PostRender function with the script below.

 

Tell us what the output is and whether your see something on screen.


function Script:PostRender(context)

for i = 1, self.itemSlots, 1 do

context:SetColor(1,1,1)

local x = self.screenWidth - self.itemSize.x

local y = (i * self.itemSize.y) + (i * self.offset)

context:DrawRect(x,y, self.itemSize.x, self.itemSize.y)

local currentItem = self.items

if currentItem ~= nil and currentItem.texture ~= nil then

System:Print("going to draw a texture. i="..i..)

context:SetBlendMode(Blend.Alpha)

context:DrawImage(currentItem.texture, 0, 40 * i, 40, 40)

context:SetBlendMode(Blend.Solid)

end

end

end

Link to comment
Share on other sites

Can you post an ingame screenshot?

 

It looks like the textures are missing, but I wonder why it isn't causing errors. Can you do a quick test by putting this line right after the PostRender function (assuming the location of the texture is correct):

context:DrawImage(Texture:Load("Materials/items/bottleicon.tex", 0,0, 100, 100)

Link to comment
Share on other sites

yes i have a picture drawn haha what do i do now ? its in the top left it already draws it when you start the game

 

i also was putting ")"

 

when you said but it was saying error soio kept starting the game and it finally came on so i there a glitch in the system ?

post-13477-0-49990500-1426263512_thumb.png

Link to comment
Share on other sites

It was a simple test to check if the texture location was correct, and yes is was supposed to be drawn there.

Lets try out severall drawImage commands. Replace the if statement with the following:

if currentItem ~= nil and currentItem.texture ~= nil then
context:SetBlendMode(Blend.Alpha)
context:DrawImage(Texture:Load("Materials/items/bottleicon.tex"), x, y, self.itemSize.x, self.itemSize.y)
context:DrawImage(currentItem.texture, 0, 0, self.itemSize.x, self.itemSize.y)
context:DrawImage(currentItem.texture, x, y, 80, 80)
context:SetBlendMode(Blend.Solid)
end

Link to comment
Share on other sites

  • 4 years later...

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