Forum

> > CS2D > Scripts > lua request(kind of inventory)
Forums overviewCS2D overview Scripts overviewLog in to reply

English lua request(kind of inventory)

23 replies
Page
To the start Previous 1 2 Next To the start

old lua request(kind of inventory)

loldlold123
User Off Offline

Quote
hello guys,i need something that we can call it as inventory
there are already 2 inventory script in file archive i already know that,but im looking for something that is more basic, these features what im looking for;
-doesnt need to images of items
-doesnt need to drop items
-f4 to see your inventory
-f3 to get items from shop(basicly you can make asd item and gives you 100 hp boost)
-items will be saved...

i'll create lots of items so needed tables but god damn im not good at those things...

old Re: lua request(kind of inventory)

loldlold123
User Off Offline

Quote
user Infinite Rain has written
user Avo has written
Check out my http://unrealsoftware.de/files_show.php?file=10938 . It has got little bug, but whatever. I give you permission to edit and even a upload, but add me in credits.
Haha, really funny.

@user loldlold123: Listen, I cn do to you an easy example with infinite menus. Function for each item and item exparation, if you want.


ok it would be nice for me,but also needed remove item function...(cuz im gonna make trade system with that so i need to remove items)

old Re: lua request(kind of inventory)

Infinite Rain
Reviewer Off Offline

Quote
OK I will make it now
WAIT.

Edit:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--Factis' inventory script for my Friend HeadHunter

--//Config
Items = {
	[1] = {
		name = "Item 1";
		func = function(id) msg(player(id, 'name') .." used an item 1!") end;
	};
}
InventorySlots = 5
--//End of the config
Player = {}

function OpenInventory(id, page)
	local page = page or 1
	local pages = 5
	if page < 1 then page = pages end
	if page > pages then page = 1 end
	local m = "Inventory P".. page
	for i = 6 * page - 5, 6 * page do
		if Player[id].inventory[i] then m = m ..', '.. Items[Player[id].inventory[i]].name else m = m ..',' end
	end
	if page == pages then m = m ..',,<<- First page' else m = m ..',,Next page -->' end
	if page == 1 then m = m ..',Last page ->>' else m = m ..',<-- Previvius page' end
	menu(id, m)
end

function AddItem(id, itemid)
	table.insert(Player[id].inventory, itemid)
end

function RemoveItem(id, itemid)
	for n, w in pairs(Player[id].inventory) do
		if w == itemid then
			table.remove(Player[id].inventory, n)
			break
		end
	end
end

addhook("join", "JoinHook")
function JoinHook(id)
	Player[id] = {inventory = {}}
	for k = 1, 17 do
		AddItem(id, 1)
	end
end

addhook('serveraction', 'ServerActionHook')
function ServerActionHook(id, action)
	if action == 1 then
		OpenInventory(id)
	end
end

addhook('menu', 'MenuHook')
function MenuHook(id, title, button)
	if title:sub(1, 11) == 'Inventory P' then
		local page = tonumber(title:sub(12))
		if button == 8 then OpenInventory(id, page + 1) end
		if button == 9 then OpenInventory(id, page - 1) end
		if button <= 6 then
			local x = (page - 1) * 6 + button
			Items[Player[id].inventory[x]].func(id)
		end
	end
end

In config:
Items:
name = name of the item
func = function of the item

Functions:
ItemAdd(id, itemid) -- adds an item into player's inventory
RemoveItem(id, itemid) -- Removes the item from player's inventory

ItemSlots -- The number of the slots in inventory (deffault 5 - 30 items can be held

If you want to make stacks, ask Alistaire, as he asked to.
edited 2×, last 07.07.12 09:20:31 pm

old Re: lua request(kind of inventory)

loldlold123
User Off Offline

Quote
how to call that,like if player has got asd item then function? i can check player has got item or not but i have to add counter for each item and i dont wanna do that...so what im gonna do?

old Re: lua request(kind of inventory)

Alistaire
User Off Offline

Quote
He wants the items have a counter in the table so that he can do stuff like;

1
2
3
4
if player[id][inventory][item][ammount] >= 5 then
	player[id][inventory][item][ammount] = player[id][inventory][item][ammount] - 5
	player[id][inventory][gold] = player[id][inventory][gold] + 100
end

And the like. Not that the table looks like this, but to give an idea.

old Re: lua request(kind of inventory)

Infinite Rain
Reviewer Off Offline

Quote
Oh you mean, ammount of the same items?

1
2
3
4
5
6
7
8
9
function Items(id, itemid)
	local count = 0
	for n, w in pairs(Player[id].inventory) do
		if w == itemid then
			count = count + 1
		end
	end
	return count
end

old Re: lua request(kind of inventory)

Alistaire
User Off Offline

Quote
I mean that the inventory table needs another table to store the current ammount of the items, and that the ammount should be showed next to the item name in the inventory menu.

old Re: lua request(kind of inventory)

Infinite Rain
Reviewer Off Offline

Quote
user Alistaire has written
I mean that the inventory table needs another table to store the current ammount of the items, and that the ammount should be showed next to the item name in the inventory menu.

OH you mean stacks?

old Re: lua request(kind of inventory)

Alistaire
User Off Offline

Quote
user Infinite Rain has written
user Alistaire has written
I mean that the inventory table needs another table to store the current ammount of the items, and that the ammount should be showed next to the item name in the inventory menu.

OH you mean stacks?


Yes. Check my first post on the thread.
edited 1×, last 08.07.12 02:04:44 pm

old Re: lua request(kind of inventory)

Infinite Rain
Reviewer Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--Factis' inventory script for my Friend HeadHunter

--//Config
Items = {
     [1] = {
          name = "Item 1";
          func = function(id) msg(player(id, 'name') .." used an item 1!") end;
     };
}
InventorySlots = 5
--//End of the config
Player = {}

function OpenInventory(id, page)
     local page = page or 1
     local pages = 5
     if page < 1 then page = pages end
     if page > pages then page = 1 end
     local m = "Inventory P".. page
     for i = 6 * page - 5, 6 * page do
          if Player[id].inventory[i] then m = m ..', '.. Items[Player[id].inventory[i][1]].name ..'|'.. Player[id].inventory[i][1] else m = m ..',' end
     end
     if page == pages then m = m ..',,<<- First page' else m = m ..',,Next page -->' end
     if page == 1 then m = m ..',Last page ->>' else m = m ..',<-- Previvius page' end
     menu(id, m)
end

function AddItem(id, itemid)
     for n, w in pairs(Player[id].inventory) do
          if w[1] == itemid then
	        w[2] = w[2] + 1
	  else
	        table.insert(Player[id].inventory, {itemid, 1})
	  end
     end
end

function RemoveItem(id, itemid, ammount)
     for n, w in pairs(Player[id].inventory) do
          if w[1] == itemid then
	       w[2] = w[2] - ammount
	       if w[2] <= 0 then 
               	     table.remove(Player[id].inventory, n)
               end
               break
          end
     end
end

addhook("join", "JoinHook")
function JoinHook(id)
     Player[id] = {inventory = {}}
     for k = 1, 17 do
          AddItem(id, 1)
     end
end

addhook('serveraction', 'ServerActionHook')
function ServerActionHook(id, action)
     if action == 1 then
          OpenInventory(id)
     end
end

addhook('menu', 'MenuHook')
function MenuHook(id, title, button)
     if title:sub(1, 11) == 'Inventory P' then
          local page = tonumber(title:sub(12))
          if button == 8 then OpenInventory(id, page + 1) end
          if button == 9 then OpenInventory(id, page - 1) end
          if button <= 6 then
               local x = (page - 1) * 6 + button
               Items[Player[id].inventory[x]].func(id)
          end
     end
end
Should work

user Avo has written
user Infinite Rain has written
OH you mean stacks?

He already said it, David.


Well, thank you captain obvious.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview