Forum

> > CS2D > Scripts > Inventory Script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Inventory Script

3 replies
To the start Previous 1 Next To the start

old Inventory Script

Gaios
Reviewer Off Offline

Quote
Hi, us
How to write a script in which:
      • Inventory has only 9 seats
      • When the pile of something in a shop[menu], it is recorder in the Inventory
      • When I use it in the Inventory, then disappear
edited 2×, last 05.09.12 04:36:46 pm

Admin/mod comment

Rules §4.3 - Only English/German (depending on section) is allowed also: attention whore title removed

old Re: Inventory Script

mafia_man
User Off Offline

Quote
Stop using translator, it sucks. I can only give you example of inventory code. It won't work because it's part of my rp mod.
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function showInv(id)
	if #Player[id].inv == 0 then
		msg2(id, "©255000000You don't have anything in inventory!");
		return 0;
	end
	local _, i;
	local t = {
		title = "Inventory";
		items = {};
	};
	for _, i in pairs(Player[id].inv) do
		table.insert(t.items, {Item[i].name, "", assert(loadstring("local id = ".. id .."; showItem(id, ".. _ ..");"))});
	end
	unimenu(id, true, t, 1);
end

function showItem(id, slotid)
	local iid = Player[id].inv[slotid];
	local t = {
		title = "Item " .. Item[iid].name;
		items = {};
	}
	if Item[iid].drop ~= nil then
		table.insert(t.items, {"Drop", "", assert(loadstring("local id = ".. id .."; dropItem(id, ".. slotid ..");"))});
	end
	if Item[iid].equip ~= nil then
		table.insert(t.items, {"Equip", "", assert(loadstring("local id = ".. id .."; equipItem(id, ".. slotid ..");"))});
	end
	if Item[iid].use ~= nil then
		table.insert(t.items, {Item[iid].use[1], "", assert(loadstring("local id = ".. id .."; Item[".. iid .."].use[2](id, ".. slotid ..");"))});
	end
	unimenu(id, true, t, 1);
end

function removeItem(id, slotid)
	table.remove(Player[id].inv, slotid);
end

function buyItem(id, cost, iid)
	if Player[id].money >= cost then
		if addItem(id, iid) then
			msg2(id, "©255128064You bought ".. Item[iid].name .."!");
			Player[id].money = Player[id].money - cost;
			if show then
				msg2(id, "©255000000-" .. cost .. "$");
			end
			UpdateHud(id);
		else
			msg2(id, "©255000000You don't have enough space in inventory!");
		end
	else
		msg2(id, "©255000000You don't have enough money!");
	end
end

function addItem(id, iid)
	if #Player[id].inv <= inv_maxitems then
		table.insert(Player[id].inv, iid);
		return true;
	end
	return false;
end

function dropItem(id, slotid)
	local iid = Player[id].inv[slotid];
	if Item[iid].drop ~= nil then
		msg2(id, "©255128064Dropped "..Item[iid].name.."!");
		removeItem(id, slotid);
		if type(Item[iid].drop) == "table" then
			local _, i;
			for _, i in pairs(Item[iid].drop) do
				parse("spawnitem ".. i .." ".. player(id, "tilex") .." ".. player(id, "tiley"));
			end
		else
			parse("spawnitem ".. Item[iid].drop .." ".. player(id, "tilex") .." ".. player(id, "tiley"));
		end
	end
end

function equipItem(id, slotid)
	local iid = Player[id].inv[slotid];
	if Item[iid].equip ~= nil then
		msg2(id, "©255128064Equipped "..Item[iid].name.."!");
		removeItem(id, slotid);
		if type(Item[iid].equip) == "table" then
			local _, i;
			for _, i in pairs(Item[iid].equip) do
				parse("equip ".. id .." ".. i);
			end
		else
			parse("equip ".. id .." ".. Item[iid].equip);
		end
	end
end
And items config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Item = {
	[1] = {
		name = "AK-47";
		drop = 30; -- id itemy do wyrzucenia, usuń to jak nie pozwalasz wyrzucać
		equip = 30; -- id itemu do ubrania, usuń to jak nie pozwalasz ubrać
	};
	[2] = {
		name = "Apple";
		use = {"Eat", function(id, slotid) DecHunger(id, 5); removeItem(id, slotid); msg2(id, "©255000000Yummy apple!"); end};
	};
	[3] = {
		name = "AK-47 Shipment";
		drop = {30,30,30,30,30};
	};
}
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview