
How to write a script in which:



edited 2×, last 05.09.12 04:36:46 pm
Admin/mod comment

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
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}; 	}; }