blackMales = { [ 310] = true, [ 311] = true, [ 300] = true, [ 301] = true, [ 302] = true, [ 296] = true, [ 297] = true, [ 268] = true, [ 269] = true, [ 270] = true, [ 271] = true, [ 272] = true, [ 7] = true, [ 14] = true, [ 15] = true, [ 16] = true, [ 17] = true, [ 18] = true, [ 20] = true, [ 21] = true, [ 22] = true, [ 24] = true, [ 25] = true, [ 28] = true, [ 35] = true, [ 36] = true, [ 50] = true, [ 51] = true, [ 66] = true, [ 67] = true, [ 78] = true, [ 79] = true, [ 80] = true, [ 83] = true, [ 84] = true, [ 102] = true, [ 103] = true, [ 104] = true, [ 105] = true, [ 106] = true, [ 107] = true, [ 134] = true, [ 136] = true, [ 142] = true, [ 143] = true, [ 144] = true, [ 156] = true, [ 163] = true, [ 166] = true, [ 168] = true, [ 176] = true, [ 180] = true, [ 182] = true, [ 183] = true, [ 185] = true, [ 220] = true, [ 221] = true, [ 222] = true, [ 249] = true, [ 253] = true, [ 260] = true, [ 262 ] = true }
whiteMales = {[290] = true, [305] = true, [ 306] = true, [307] = true, [ 308] = true, [ 309] = true, [ 312] = true, [ 303] = true, [ 299] = true, [ 291] = true, [ 292] = true, [ 293] = true, [ 294] = true, [ 295] = true, [ 1] = true, [ 2] = true, [ 23] = true, [ 26] = true, [ 27] = true, [ 29] = true, [ 30] = true, [ 32] = true, [ 33] = true, [ 34] = true, [ 35] = true, [ 36] = true, [ 37] = true, [ 38] = true, [ 43] = true, [ 44] = true, [ 45] = true, [ 46] = true, [ 47] = true, [ 48] = true, [ 50] = true, [ 51] = true, [ 52] = true, [ 53] = true, [ 58] = true, [ 59] = true, [ 60] = true, [ 61] = true, [ 62] = true, [ 68] = true, [ 70] = true, [ 72] = true, [ 73] = true, [ 78] = true, [ 81] = true, [ 82] = true, [ 94] = true, [ 95] = true, [ 96] = true, [ 97] = true, [ 98] = true, [ 99] = true, [ 100] = true, [ 101] = true, [ 108] = true, [ 109] = true, [ 110] = true, [ 111] = true, [ 112] = true, [ 113] = true, [ 114] = true, [ 115] = true, [ 116] = true, [ 120] = true, [ 121] = true, [ 122] = true, [ 124] = true, [ 125] = true, [ 126] = true, [ 127] = true, [ 128] = true, [ 132] = true, [ 133] = true, [ 135] = true, [ 137] = true, [ 146] = true, [ 147] = true, [ 153] = true, [ 154] = true, [ 155] = true, [ 158] = true, [ 159] = true, [ 160] = true, [ 161] = true, [ 162] = true, [ 164] = true, [ 165] = true, [ 170] = true, [ 171] = true, [ 173] = true, [ 174] = true, [ 175] = true, [ 177] = true, [ 179] = true, [ 181] = true, [ 184] = true, [ 186] = true, [ 187] = true, [ 188] = true, [ 189] = true, [ 200] = true, [ 202] = true, [ 204] = true, [ 206] = true, [ 209] = true, [ 212] = true, [ 213] = true, [ 217] = true, [ 223] = true, [ 230] = true, [ 234] = true, [ 235] = true, [ 236] = true, [ 240] = true, [ 241] = true, [ 242] = true, [ 247] = true, [ 248] = true, [ 250] = true, [ 252] = true, [ 254] = true, [ 255] = true, [ 258] = true, [ 259] = true, [ 261] = true, [ 264] = true, [ 272 ] = true }
asianMales = {[ 49] = true, [ 57] = true, [ 58] = true, [ 59] = true, [ 60] = true, [ 117] = true, [ 118] = true, [ 120] = true, [ 121] = true, [ 122] = true, [ 123] = true, [ 170] = true, [ 186] = true, [ 187] = true, [ 203] = true, [ 210] = true, [ 227] = true, [ 228] = true, [ 229] = true, [ 294 ] = true }
blackFemales = {[304] = true, [ 298] = true, [ 10] = true, [ 11] = true, [ 12] = true, [ 13] = true, [ 40] = true, [ 41] = true, [ 63] = true, [ 64] = true, [ 69] = true, [ 76] = true, [ 91] = true, [ 139] = true, [ 148] = true, [ 190] = true, [ 195] = true, [ 207] = true, [ 215] = true, [ 218] = true, [ 219] = true, [ 238] = true, [ 243] = true, [ 244] = true, [ 245] = true, [ 256] = true, [ 304 ] = true }
whiteFemales = {[12] = true, [ 31] = true, [ 38] = true, [ 39] = true, [ 40] = true, [ 41] = true, [ 53] = true, [ 54] = true, [ 55] = true, [ 56] = true, [ 64] = true, [ 75] = true, [ 77] = true, [ 85] = true, [ 87] = true, [ 88] = true, [ 89] = true, [ 90] = true, [ 91] = true, [ 92] = true, [ 93] = true, [ 129] = true, [ 130] = true, [ 131] = true, [ 138] = true, [ 140] = true, [ 145] = true, [ 150] = true, [ 151] = true, [ 152] = true, [ 157] = true, [ 172] = true, [ 178] = true, [ 192] = true, [ 193] = true, [ 194] = true, [ 196] = true, [ 197] = true, [ 198] = true, [ 199] = true, [ 201] = true, [ 205] = true, [ 211] = true, [ 214] = true, [ 216] = true, [ 224] = true, [ 225] = true, [ 226] = true, [ 231] = true, [ 232] = true, [ 233] = true, [ 237] = true, [ 243] = true, [ 246] = true, [ 251] = true, [ 257] = true, [ 263] = true, [ 298 ] = true }
asianFemales = {[38] = true, [ 53] = true, [ 54] = true, [ 55] = true, [ 56] = true, [ 88] = true, [ 141] = true, [ 169] = true, [ 178] = true, [ 224] = true, [ 225] = true, [ 226] = true, [ 263 ] = true }
local fittingskins = {[0] = {[0] = blackMales, [1] = whiteMales, [2] = asianMales}, [1] = {[0] = blackFemales, [1] = whiteFemales, [2] = asianFemales}}
local badges = getBadges()
local masks = getMasks()

local cokeBottles = {}

function removeAnimation(player)
	exports.global:removeAnimation(player)
end

function PridatUtilitu(player, stav, hodnota, hp)
	--[[
		Stav 1 = Hlad.
		Stav 2 = Žízeň.
		Stav 3 = WC. ( Bude to méně využívaná funkce.)
	--]]
	if (stav==1) then
		local jidlo = getElementData(player, "jidlo")

		setElementData(player, "jidlo", jidlo+hodnota)
		
		giveHealth(player, hp)
	elseif (stav==2) then
		local piti = getElementData(player, "piti")
		
		setElementData(player, "piti", piti+hodnota)

		giveHealth(player, hp)	

		local zvuk = "drink"
		local players = getElementsByType("player")
		for k, p in ipairs(players) do
			triggerClientEvent(p,"zvukplay", player, zvuk, 7)
		end			
	end
end

function giveHealth(player, health)
	if health ~= nil then
		setElementHealth( player, math.min( 100, getElementHealth( player ) + health ) )
	end
end

function removeOOC(text)
	wtext = tostring(text)
	if not wtext then
		outputChatBox("Error code IT001")
		return ""
	end
	return wtext:gsub("%s*%(%(([^)]+)%)%)%s*","") -- removes the (( )) part
end

local shields = { }
local presents = { 1, 7, 8, 15, 11, 12, 19, 26, 59, 71 }
local glowstickColor = 1
--
-- callbacks
function useItem(itemSlot, additional, thePlayer)

	if not itemSlot then
		return
	end

	local items = getItems(source)
	local itemID = items[itemSlot][1]
	local itemValue = items[itemSlot][2]
	local itemName = getItemName( itemID, itemValue )
	if isPedDead(source) or getElementData(source, "injuriedanimation") then return end

	local hasItemProtect = hasItem(source, tonumber( itemID ), tostring(itemValue)) or  hasItem(source, tonumber( itemID ), tonumber(itemValue))
	if not hasItemProtect then
		return
	end

	if itemID then
		if (itemID==1) then -- hotdog
			giveHunger(source, 45)
			takeThirst(source, 3)
			triggerEvent('sendAme', source, "snědl hotdog.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==3) then -- car key
			local veh = getPedOccupiedVehicle(source)
			if veh and getElementData(veh, "dbid") == itemValue then
				triggerEvent("lockUnlockInsideVehicle", source, veh)
			else
				-- unlock nearby cars
				local value = exports.pool:getElement( "vehicle", itemValue )
				if value then
					local vx, vy, vz = getElementPosition(value)
					local x, y, z = getElementPosition(source)

					if getDistanceBetweenPoints3D(x, y, z, vx, vy, vz) <= 30 then -- car found
						triggerEvent("lockUnlockOutsideVehicle", source, value)
					else
						outputChatBox("Jsi příliš daleko od tohoto vozidla.", source, 255, 194, 14)
					end
				else
					outputChatBox("Neexistující vozidlo.", source, 255, 194, 14)
				end
			end
		elseif (itemID==4) or (itemID==5) then -- house key or business key
			local itemValue = tonumber(itemValue)
			local found = false

			local posX, posY, posZ = getElementPosition(source)
			local dimension = getElementDimension(source)
			local possibleInteriors = getElementsByType("interior")
			for _, interior in ipairs(possibleInteriors) do
				local interiorEntrance = getElementData(interior, "entrance")
				local interiorExit = getElementData(interior, "exit")
				local interiorID = getElementData(interior, "dbid")
				if interiorID == itemValue then
					for _, point in ipairs( { interiorEntrance, interiorExit } ) do
						if (point[5] == dimension) then
							local distance = getDistanceBetweenPoints3D(posX, posY, posZ, point[1], point[2], point[3])
							if (distance <= 6) then
								found = interiorID
								break
							end
						end
					end
				end
			end

			if not found then
				local possibleElevators = getElementsByType("elevator")
				for _, elevator in ipairs(possibleElevators) do
					local elevatorEntrance = getElementData(elevator, "entrance")
					local elevatorExit = getElementData(elevator, "exit")

					for _, point in ipairs( { elevatorEntrance, elevatorExit } ) do
						if (point[5] == dimension) then
							local distance = getDistanceBetweenPoints3D(posX, posY, posZ, point[1], point[2], point[3])
							if (distance < 6) then
								if elevatorEntrance[5] == itemValue then
									found = elevatorEntrance[5]
									break
								elseif elevatorExit[5] == itemValue  then
									found = elevatorExit[5]
									break
								end
							end
						end
					end
				end
			end

			if found then
				local dbid, entrance, exit, interiorType, interiorElement = exports['interior-system']:findProperty( source, found )
				local interiorStatus = getElementData(interiorElement, "status")
				local locked = interiorStatus[3] and 1 or 0

				locked = 1 - locked -- Invert status


				local newRealLockedValue = false
				mysql:query_free("UPDATE interiors SET locked='" .. locked .. "' WHERE id='" .. found .. "' LIMIT 1")
				if locked == 0 then
					triggerEvent('sendAme', source, "vloží klíč do dveří a odemkne je.")
					if not (exports.global:hasItem(source, 4, found)) and not (exports.global:hasItem(source, 5, found)) then
						exports.logs:logMessage("[INTERIOR-UNLOCK] Interior #" .. found .. " was unlocked by " .. getPlayerName(source), 21)
					end
				else
					newRealLockedValue = true
					triggerEvent('sendAme', source, "strčí klíč do dveří a zamkne je.")

					if not (exports.global:hasItem(source, 4, found)) and not (exports.global:hasItem(source, 5, found)) then
						exports.logs:logMessage("[INTERIOR-LOCK] Interior #" .. found .. " was locked by " .. getPlayerName(source), 21)
					end
				end

				interiorStatus[3] = newRealLockedValue
				exports.anticheat:changeProtectedElementDataEx(interiorElement, "status", interiorStatus, true)
			else
				outputChatBox("You are too far from the door.", source, 255, 194, 14)
			end
		elseif (itemID==73) then -- elevator remote
			local itemValue = tonumber(itemValue)
			local found = nil

			local dimension = getElementDimension(source)
			local posX, posY, posZ = getElementPosition(source)
			local possibleElevators = getElementsByType("elevator")
			for _, elevator in ipairs(possibleElevators) do
				local elevatorEntrance = getElementData(elevator, "entrance")
				local elevatorExit = getElementData(elevator, "exit")
				local elevatorID = getElementData(elevator, "dbid")
				if elevatorID == itemValue then
					for _, point in ipairs( { elevatorEntrance, elevatorExit } ) do
						if (point[5] == dimension) then
							local distance = getDistanceBetweenPoints3D(posX, posY, posZ, point[1], point[2], point[3])
							if (distance < 6) then
								found = elevator
								break
							end
						end
					end
				end
			end

			if not found then
				outputChatBox("You are too far from the door.", source, 255, 194, 14)
			else
				triggerEvent( "toggleCarTeleportMode", found, source )
			end
		elseif (itemID==8) then -- sandwich
			PridatUtilitu(source, 1, 15, 5)
			exports.global:applyAnimation(source, "food", "eat_burger", 4000, false, true, true)
			toggleAllControls(source, true, true, true)
			triggerClientEvent(source, "onClientPlayerWeaponCheck", source)
			triggerEvent('sendAme', source, "snědl sandwich.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==9) then -- sprunk
			PridatUtilitu(source, 2, 15, 10)
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "VENDING", "VEND_Drink_P", 4000, false, true, true)
			toggleAllControls(source, true, true, true)
			triggerClientEvent(source, "onClientPlayerWeaponCheck", source)
			triggerEvent('sendAme', source, "vypil sprite z plechovky.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==10) then -- red dice
			local max = tonumber(itemValue) or 6
			if max == 1 then
				max = 6
			end
			exports.global:sendLocalText(source, " ✪ " .. getPlayerName(source):gsub("_", " ") .. " hodil " .. (max == 6 and "" or (max .. "-stěnnou ")) .. "kostkou a padlo " .. math.random( 1, max ) ..".", 255, 51, 102)
		elseif (itemID==11) then -- taco
			PridatUtilitu(source, 1, 15, 5)
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "FOOD", "EAT_Burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "snědl kebab.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==12) then -- cheeseburger
			PridatUtilitu(source, 1, 15, 5)
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "FOOD", "EAT_Burger", 4000, false, true, true)
			setTimer(removeAnimation, 4000, 1, source)
			triggerEvent('sendAme', source, "snědl cheeseburger.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==13) then -- donut
			PridatUtilitu(source, 1, 15, 5)
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "FOOD", "EAT_Burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "snědl donut.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==232) then -- Dron
			local dimenze = getElementDimension(source)
			if (dimenze==0) then
				triggerClientEvent(source, "hideInventory", source, source)
				triggerEvent("RZ:StartDrone", source, source)
				outputChatBox(" #FFEF00Příkazem /drone schováš svého drona.", source, 255, 0, 0, true)
			else
				outputChatBox(" #FFEF00Drona nemůžeš použít v jiné dimenzi, zdá se to být i jako PowerGaming v mnoha případech.", source, 255, 0, 0, true)
			end			
		elseif (itemID==14) then -- cookie
			PridatUtilitu(source, 1, 1, 5)
			exports.global:applyAnimation(source, "FOOD", "EAT_Burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "snědl cookie.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==15) then -- water
			PridatUtilitu(source, 2, math.random(3, 6), 5)
			exports.global:applyAnimation(source, "VENDING", "VEND_Drink_P", 4000, false, true, true)
			triggerEvent('sendAme', source, "vypil flašku s vodou.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==16) then -- clothes
			local result = mysql:query_fetch_assoc("SELECT gender,skincolor FROM characters WHERE id='" .. getElementData(source, "dbid") .. "' LIMIT 1")
			local gender = tonumber(result["gender"])
			local race = tonumber(result["skincolor"])

			--local skin = tonumber(itemValue)
			local skin, clothingid = unpack(split(tostring(itemValue), ':'))
			skin = tonumber(skin)
			clothingid = tonumber(clothingid) or nil
			--if fittingskins[gender] and fittingskins[gender][race] and fittingskins[gender][race][skin] then
				setElementModel(source, skin)
				exports.anticheat:changeProtectedElementDataEx(source, "clothing:id", clothingid, true)
				mysql:query_free( "UPDATE characters SET skin = " .. skin .. ", clothingid = " .. ( clothingid or 'NULL' ) .. " WHERE id = " .. getElementData( source, "dbid" ) )
				triggerEvent('sendAme', source, "se převlékl.")
			--[[else
				outputChatBox("These clothes do not fit you.", source, 255, 0, 0)
			end]]
		elseif (itemID==17) then -- watch
			triggerEvent('sendAme', source, "se podíval na hodinky.")
			outputChatBox("Právě je " .. string.format("%02d:%02d", getTime()) .. ".", source, 255, 194, 14)
			exports.global:applyAnimation(source, "COP_AMBIENT", "Coplook_watch", 4000, false, true, true)
		elseif (itemID==20) then -- STANDARD FIGHTING
			setPedFightingStyle(source, 4)
			outputChatBox("Přečetl si si knihu základniho boje.", source, 255, 194, 14)
			mysql:query_free("UPDATE characters SET fightstyle = 4 WHERE id = " .. getElementData( source, "dbid" ) )
		elseif (itemID==21) then -- BOXING
			setPedFightingStyle(source, 5)
			outputChatBox("Přečetl si si knihu o boxu.", source, 255, 194, 14)
			mysql:query_free("UPDATE characters SET fightstyle = 5 WHERE id = " .. getElementData( source, "dbid" ) )
		elseif (itemID==22) then -- KUNG FU
			setPedFightingStyle(source, 6)
			outputChatBox("Přečetl si si knihu o Kung Fu.", source, 255, 194, 14)
			mysql:query_free("UPDATE characters SET fightstyle = 6 WHERE id = " .. getElementData( source, "dbid" ) )
		elseif (itemID==23) then -- KNEE HEAD
			--setPedFightingStyle(source, 7)
			outputChatBox("Otevřel si knihu a zjistil si že je napsana v staré řečtině.", source, 255, 194, 14)
			--mysql:query_free("UPDATE characters SET fightstyle = 7 WHERE id = " .. getElementData( source, "dbid" ) )
		elseif (itemID==24) then -- GRAB KICK
			setPedFightingStyle(source, 15)
			outputChatBox("Přečetl si si knihu na obranu.", source, 255, 194, 14)
			mysql:query_free( "UPDATE characters SET fightstyle = 15 WHERE id = " .. getElementData( source, "dbid" ) )
		elseif (itemID==25) then -- ELBOWS
			setPedFightingStyle(source, 16)
			outputChatBox("Přečetl si si knihu o bojovani s loktem.", source, 255, 194, 14)
			mysql:query_free("UPDATE characters SET fightstyle = 16 WHERE id = " .. getElementData( source, "dbid" ) )
		elseif (itemID==27) then -- FLASHBANG
			takeItemFromSlot(source, itemSlot)

			local obj = createObject(343, unpack(additional))
			exports.pool:allocateElement(obj)
			setTimer(explodeFlash, math.random(400, 800), 1, obj)
			triggerEvent('sendAme', source, "hodil flashbang.")
			setElementInterior(obj, getElementInterior(source))
			setElementDimension(obj, getElementDimension(source))
		elseif (itemID==28) then -- GLOWSTICK
			takeItemFromSlot(source, itemSlot)

			local x, y, groundz = unpack(additional)
			local marker = nil
			if tostring(itemValue) == "2" then
				marker = createMarker(x, y, groundz, "corona", 1, 255, 0, 0, 150)
			elseif tostring(itemValue) == "3" then
				marker = createMarker(x, y, groundz, "corona", 1, 0, 255, 0, 150)
			elseif tostring(itemValue) == "4" then
				marker = createMarker(x, y, groundz, "corona", 1, 255, 255, 0, 150)
			elseif tostring(itemValue) == "5" then
				marker = createMarker(x, y, groundz, "corona", 1, 255, 0, 255, 150)
			elseif tostring(itemValue) == "6" then
				marker = createMarker(x, y, groundz, "corona", 1, 0, 255, 255, 150)
			elseif tostring(itemValue) == "7" then
				marker = createMarker(x, y, groundz, "corona", 1, 255, 255, 255, 150)
			else
				marker = createMarker(x, y, groundz, "corona", 1, 0, 0, 255, 150)
			end
			exports.pool:allocateElement(marker)
			triggerEvent('sendAme', source, "položil glowstick.")
			setTimer(destroyElement, 600000, 1, marker)
		elseif (itemID==29) then -- RAM
			--if (getElementData(source, "duty") > 0) and (getElementModel(source) == 285) then
				local found = false
				local lastDistance = 5
				local posX, posY, posZ = getElementPosition(source)
				local dimension = getElementDimension(source)
				local possibleInteriors = getElementsByType("interior")
				for _, interior in ipairs(possibleInteriors) do
					local interiorEntrance = getElementData(interior, "entrance")
					local interiorExit = getElementData(interior, "exit")

					for _, point in ipairs( { interiorEntrance, interiorExit } ) do
						if (point[5] == dimension) then
							local distance = getDistanceBetweenPoints3D(posX, posY, posZ, point[1], point[2], point[3])
							if (distance < lastDistance) then
								found = interior
								lastDistance = distance
							end
						end
					end
				end

				if not (found) then
					outputChatBox("You are not near a door.", source, 255, 194, 14)
				else
					local dbid = getElementData(found, "dbid")
					local interiorStatus = getElementData(found, "status")

					if (interiorStatus[1] ~= 2) and (interiorStatus[4] < 0) and (interiorStatus[3]) and not (interiorStatus[2]) then
						outputChatBox("Tyhle dveře nevlastní hráč.", source, 255, 0, 0)
					elseif interiorStatus[2] then
						outputChatBox("Tyhle dveře jsou nedostupné.", source, 255, 0, 0)
					elseif (interiorStatus[3]) then
						interiorStatus[3] = false
						exports.anticheat:changeProtectedElementDataEx(found, "status", interiorStatus, true)
						mysql:query_free("UPDATE interiors SET locked='0' WHERE id='" .. mysql:escape_string(dbid) .. "' LIMIT 1")
						triggerEvent('sendAme', source, "swings the ram into the door, opening it.")
						exports.global:sendMessageToAdmins("Player "..getPlayerName(source).." otevřel interiér "..dbid.." s beranidlem")
						exports.logs:dbLog(source, 31, { source, found }, "UNLOCK WITH DOORRAM")
					else
						outputChatBox("Tyhle dveře nejsou zamknuté.", source, 255, 0, 0)
					end
				end
			--[[else
				outputChatBox("You are not on SWAT duty.", source, 255, 0, 0)
			end]]

		elseif (itemID==34) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "čouchl si k kokainu.")
		elseif (itemID==35) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "polkl pilulku morfia.")
		elseif (itemID==36) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "polkl pilulku extázy.")
		elseif (itemID==37) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "si dal injekci heroinu.")
		elseif (itemID==38) then
            local sucess, key, itemvalue = hasItem(source, 181)
            local itemVal = {}
            local i = 0
            for token in string.gmatch(tostring(itemValue), "[^%s]+") do
                i = i + 1
                itemVal[i] = token
            end
            if (tonumber(itemVal[1]) > 0) then
                if sucess then
                    if (tonumber(itemvalue) >= 1) then
                        if (hasSpaceForItem(source, 182, 1)) then
                            takeItemFromSlot(source, itemSlot)
                            giveItem(source, itemID, tonumber(itemVal[1]) - 1)
                            giveItem(source, 182, 1)
                            takeItem(source, 181, itemvalue)
                            exports.global:sendLocalMeAction(source, "vzal par gramů marihuany, nasadil filtr a obalil ho papírem.")
                            giveItem(source, 181, itemvalue - 1)
                        else
                            outputChatBox( "Tvůj inventář je plný.", source, 255, 0, 0 )
                        end
                    else
                        outputChatBox("V baličku, kde jsou papírky, tak neni žadny papír", source, 255, 0, 0)
                    end
                else
                    outputChatBox("Potřebuješ balíček s papírkama aby jsi mohl tohle udělat.", source, 255, 0, 0)
                end
            else
                triggerEvent('sendAme', source, "koukl do balíčku s marihuanou. Je prázdny")
            end
		elseif (itemID==39) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "čichl si k metamfataminu.")
		elseif (itemID==40) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "použil epipen.")
		elseif (itemID==41) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "dal si pár kousku lsd do pusy.")
		elseif (itemID==42) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "snědl nějake vysušené houby")
		elseif (itemID==43) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "polkl PCP pilulky")
		elseif itemID == 48 then -- Batoh
			triggerEvent("artifacts:toggle", source, source, "backpack")
               elseif itemID == 233 then -- Batoh
			triggerEvent("artifacts:toggle", source, source, "backpack")
		elseif (itemID==49) then
			triggerEvent("artifacts:toggle", source, source, "rod")
			triggerEvent( "fish", source )
		elseif itemID == 750 then
			triggerEvent("artifacts:toggle", source, source, "bandanared")
		elseif itemID == 751 then
			triggerEvent("artifacts:toggle", source, source, "bandanagang3")
		elseif itemID == 752 then
			triggerEvent("artifacts:toggle", source, source, "bandanablue3")
		elseif itemID == 753 then
			triggerEvent("artifacts:toggle", source, source, "bandanablack3")
		elseif itemID == 770 then
			triggerEvent("artifacts:toggle", source, source, "beret")
		elseif itemID == 771 then
			triggerEvent("artifacts:toggle", source, source, "maskdemon")
		elseif itemID == 772 then
			triggerEvent("artifacts:toggle", source, source, "maskpig")
		elseif itemID == 773 then
			triggerEvent("artifacts:toggle", source, source, "maskfriday13")
		elseif itemID == 774 then
			triggerEvent("artifacts:toggle", source, source, "maskmonkey")
		elseif itemID == 775 then
			triggerEvent("artifacts:toggle", source, source, "masksugarskull")
		elseif itemID == 776 then
			triggerEvent("artifacts:toggle", source, source, "maskOwl")
		elseif itemID == 777 then
			triggerEvent("artifacts:toggle", source, source, "maskBaby1")
		elseif itemID == 778 then
			triggerEvent("artifacts:toggle", source, source, "maskBaby2")
		elseif itemID == 779 then
			triggerEvent("artifacts:toggle", source, source, "maskBaby3")
		elseif itemID == 780 then
			triggerEvent("artifacts:toggle", source, source, "maskBaby4")
		elseif itemID == 781 then
			triggerEvent("artifacts:toggle", source, source, "hatsanta")
		elseif itemID == 782 then
			triggerEvent("artifacts:toggle", source, source, "hatmacersun")
		elseif itemID == 800 then
			triggerEvent("artifacts:toggle", source, source, "capback")
		elseif itemID == 801 then
			triggerEvent("artifacts:toggle", source, source, "capbraves")
		elseif itemID == 802 then
			triggerEvent("artifacts:toggle", source, source, "capbulls")
		elseif itemID == 803 then
			triggerEvent("artifacts:toggle", source, source, "capcavalier")
		elseif itemID == 804 then
			triggerEvent("artifacts:toggle", source, source, "capcelctics")
		elseif itemID == 805 then
			triggerEvent("artifacts:toggle", source, source, "capCN")
		elseif itemID == 806 then
			triggerEvent("artifacts:toggle", source, source, "capdodgers")
		elseif itemID == 807 then
			triggerEvent("artifacts:toggle", source, source, "capdodgersALL")
		elseif itemID == 808 then
			triggerEvent("artifacts:toggle", source, source, "capdodgerscamo")
		elseif itemID == 809 then
			triggerEvent("artifacts:toggle", source, source, "capkeine")
		elseif itemID == 810 then
			triggerEvent("artifacts:toggle", source, source, "caplakers")
		elseif itemID == 811 then
			triggerEvent("artifacts:toggle", source, source, "caplakersCAMO")
		elseif itemID == 812 then
			triggerEvent("artifacts:toggle", source, source, "caplakerschwart")
		elseif itemID == 813 then
			triggerEvent("artifacts:toggle", source, source, "capphillies")
		elseif itemID == 814 then
			triggerEvent("artifacts:toggle", source, source, "capsox")
		elseif itemID == 815 then
			triggerEvent("artifacts:toggle", source, source, "capsoxblack")
		elseif itemID == 816 then
			triggerEvent("artifacts:toggle", source, source, "capsoxCAMO")
		elseif itemID == 817 then
			triggerEvent("artifacts:toggle", source, source, "capstlouisgreen")
		elseif itemID == 818 then
			triggerEvent("artifacts:toggle", source, source, "capstlouisred")
		elseif itemID == 819 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesBABYBLAU")
		elseif itemID == 820 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesBRAUN")
		elseif itemID == 821 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesCAMO")
		elseif itemID == 822 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesCIRCLE")
		elseif itemID == 823 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesGRAU")
		elseif itemID == 824 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesGRAUlogo")
		elseif itemID == 825 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesNAVY")
		elseif itemID == 826 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesRED")
		elseif itemID == 827 then
			triggerEvent("artifacts:toggle", source, source, "capyankeesROT")
		elseif (itemID==50) then -- highway code book
			local bookTitle = "The Los Santos Highway Code"
			local bookName = "SFHighwayCode"
			triggerEvent('sendAme', source, "reads ".. bookTitle ..".")
			triggerClientEvent( source, "showBook", source, bookName, bookTitle )
		elseif (itemID==51) then -- chemistry book
			local bookTitle = "Chemistry 101"
			local bookName = "Chemistry101"
			triggerEvent('sendAme', source, "reads ".. bookTitle ..".")
			triggerClientEvent( source, "showBook", source, bookName, bookTitle )
		elseif (itemID==52) then -- PD manual book
			local bookTitle = "The Police Officer's Manual"
			local bookName = "PDmanual"
			triggerEvent('sendAme', source, "reads ".. bookTitle ..".")
			triggerClientEvent( source, "showBook", source, bookName, bookTitle )
		elseif (itemID==54) then -- GHETTOBLASTER
			triggerEvent('sendAme', source, "položil radio na zem.")
			local x, y, z = unpack(additional)

			triggerEvent("dropItem", source, itemSlot, x, y, z+0.3)
		elseif (itemID==55) then -- Stevie's business card
			triggerEvent('sendAme', source, "koukl na kus papíru.")
			outputChatBox("Na kartě je napsáno: 'Steven Pullman - L.V. Freight Depot, Tel: 12555'", source, 255, 51, 102)
		elseif (itemID==57) then -- FUEL CAN
			local nearbyVehicles = exports.global:getNearbyElements(source, "vehicle")

			if #nearbyVehicles < 1 then return end

			local found = nil
			local shortest = 6
			local x, y, z = getElementPosition(source)
			for i, veh in ipairs(nearbyVehicles) do
				local distanceToVehicle = getDistanceBetweenPoints3D(x, y, z, getElementPosition(veh))
				if shortest > distanceToVehicle then
					shortest = distanceToVehicle
					found = veh
				end
			end

			if found then
				triggerEvent("fillFuelTankVehicle", source, found, itemValue)
			else
				outputChatBox("Jsi moc daleko od vozidla.", source, 255, 194, 14)
			end
		elseif (itemID==58) then
                        takeItemFromSlot(source, itemSlot)
			giveHealth(source, 20)
			triggerEvent('sendAme', source, "vypil pivo.")
			setElementHealth(source,getElementHealth(source)-5)
				elseif (itemID==1558) then
                        takeItemFromSlot(source, itemSlot)
			giveHealth(source, 20)
			triggerEvent('sendAme', source, "vypil červené víno.")
			setElementHealth(source,getElementHealth(source)-5)
			
							elseif (itemID==2021) then
                        takeItemFromSlot(source, itemSlot)
			giveHealth(source, 1)
			triggerEvent('sendAme', source, "snědl palačinky a začal se dávit.")
			setElementHealth(source,getElementHealth(source)-100)
			
			
			
										elseif (itemID==9885) then
			triggerEvent('sendAme', source, "zmáčkl tlačítko pod stolem")
		executeCommandHandler ( "66555745554485", source )
		
													elseif (itemID==9888) then
			triggerEvent('sendAme', source, "zazvonil zvonečkem na přivolání obsluhy")
		executeCommandHandler ( "66555745554487", source )
			
			
													elseif (itemID==7200) then

			triggerEvent('sendAme', source, "se podíval na volební letáček")
				outputChatBox("Alex Lewis! Navýšení platů pro policisty, hasiče a lékaře! Dostupnější zbraně! Volte Alexe Lewise!", source, 255, 194, 14)
									
													elseif (itemID==7300) then

			triggerEvent('sendAme', source, "se podíval na letáček hotelu Lewis")
				outputChatBox("Navštivte nově otevřený Hotel Lewis!", source, 255, 194, 14)
				outputChatBox("Nabízíme kvalitní restauraci, fitness centrum a několik pokojů.", source, 255, 194, 14)
				outputChatBox("Rezervaci lze provvést po domluvě s Alexem Lewisem na čísle 11122.", source, 255, 194, 14)
				outputChatBox("Hotel se nachází v budově StarTower (Ikonka TT v F11).", source, 255, 194, 14)
						
													elseif (itemID==3050) then
                        takeItemFromSlot(source, itemSlot)
			giveHealth(source, 1)
			triggerEvent('sendAme', source, "se podíval na nápovědu.")
				outputChatBox("U velkého vysílače známý jako big ear tě čeká další nápověda.", source, 255, 194, 14)
			
			
										elseif (itemID==2226) then
                        takeItemFromSlot(source, itemSlot)
			giveHealth(source, 1)
			triggerEvent('sendAme', source, "vytáhl řízek a snědl ho.")
			setElementHealth(source,getElementHealth(source)+20)
			
					elseif (itemID==1559) then
                        takeItemFromSlot(source, itemSlot)
			giveHealth(source, 20)
			triggerEvent('sendAme', source, "vypil bílé víno.")
			setElementHealth(source,getElementHealth(source)-5)
			
				elseif (itemID==1560) then
                        takeItemFromSlot(source, itemSlot)
			giveHealth(source, 20)
			triggerEvent('sendAme', source, "vypil růžové víno.")
			setElementHealth(source,getElementHealth(source)-5)			
			
							elseif (itemID==3000) then
                        takeItemFromSlot(source, itemSlot)
				outputChatBox("Získal jsi víno.", source, 255, 194, 14)	
                            giveItem(source, 1559, 1)		

							
							elseif (itemID==7896) then
                        takeItemFromSlot(source, itemSlot)
				outputChatBox("Peněžní poukázka (šek) na 5.000$ of firmy Lewis Servie´s.", source, 255, 194, 14)	
				exports.global:giveMoney(source, 5000) 
							
														elseif (itemID==9090) then
                        takeItemFromSlot(source, itemSlot)
										setPedArmor(source, 100)
													triggerEvent('sendAme', source, "si nasazuje neprůstřelnou vestu.")

							
						
			
			
		elseif (itemID==59) then -- MUDKIP
			takeItemFromSlot(source, itemSlot)
			giveHealth(source, 20)
			triggerEvent('sendAme', source, "snědl Twix.")
			--killPed(source)
			
				elseif (itemID==1234) then -- atlas
			--takeItemFromSlot(source, itemSlot)
		--	giveHealth(source, 20)
			triggerEvent('sendAme', source, "vzal atlas zvířat a slabě bouchl osobu po hlavě")
			
					
				elseif (itemID==4321) then -- atlas
			--takeItemFromSlot(source, itemSlot)
		--	giveHealth(source, 20)
			triggerEvent('sendAme', source, "vzal knihu 350 tipů pro nejlepší sex a bouchl osobu po hlavě")	
		
		elseif (itemID==60) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil trezor.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox("Nejsi v interiéru.", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox("Nevlastníš tento interiér!", source, 255, 0, 0)
			end
               elseif (itemID==234) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil dveře.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end 
               elseif (itemID==235) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil dveře.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
                elseif (itemID==236) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil gril.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
               elseif (itemID==237) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil pračku.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
               elseif (itemID==238) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil sedačku.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
               elseif (itemID==239) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil křeslo.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
               elseif (itemID==240) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil stůl.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
               elseif (itemID==241) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil stůl k pc.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
               elseif (itemID==242) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil židli k pc.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
         elseif (itemID==243) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil postel.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
         elseif (itemID==244) then
			local x,y,z = getElementPosition(source)
			local rz = getPedRotation(source)
			local dimension = getElementDimension(source)
			local retval = call(getResourceFromName("interior-system"), "addSafeAtPosition", source, x,y,z, rz) --0 no error, 1 safe already exists, 2 player does not own interior
			if (retval == 0) then
				triggerEvent('sendAme', source, "položil skříň.")
				takeItemFromSlot(source, itemSlot)
			elseif (retval == 2) then
				outputChatBox(".", source, 255, 0, 0)
			elseif (retval == 3) then
				outputChatBox(".", source, 255, 0, 0)
                         end
		elseif (itemID==62) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "vypil vodku.")
			setElementHealth(source,getElementHealth(source)-10)
		elseif (itemID==63) then
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "vypil whiskey.")
			setElementHealth(source,getElementHealth(source)-10)
		elseif (itemID==68) then
			triggerEvent('sendAme', source, "si prohlíží loterijní lístek.")
			outputChatBox("Loterijní lístek s číslem: " .. itemValue, source, 0, 255, 0)
		elseif (itemID==69) then -- Dictionary
			local learned = call(getResourceFromName("language-system"), "learnLanguage", source, itemValue, true)
			local lang = call(getResourceFromName("language-system"), "getLanguageName", itemValue)

			if (learned) then
				takeItem(source, itemID, itemValue)
				outputChatBox("Naučil jsi se základy " .. lang .. ", stiskni F6 pro správu jazyků.", source, 0, 255, 0)
			end
		elseif (itemID==72) then -- Note
			triggerEvent('sendAme', source, "si přečetl poznámku.")
			
		elseif (itemID==74) then -- Bomba
			takeItemFromSlot(source, itemSlot)
			local x, y, z = getElementPosition(source)
			createExplosion( x, y, z, 10, source )
			createExplosion( x, y, z, 10, source )
			
		elseif (itemID==75) then -- Ovladač od bomby
			triggerEvent('sendAme', source, "stiskl červené tlačítko na ovladači.")
			local px, py, pz = getElementPosition(source)
			for k, v in pairs( getElementsByType( "object", getResourceRootElement(getResourceFromName("item-world")) ) ) do
				if isElement( v ) and getElementData( v, "itemID" ) == 74 and getElementData( v, "itemValue" ) == itemValue then
					local x, y, z = getElementPosition( v )
					if getDistanceBetweenPoints3D( x, y, z, px, py, pz ) < 200 then
						mysql:query_free("DELETE FROM worlditems WHERE id = " .. getElementData( v, "id" ) )
						createExplosion( x, y, z, 10, source )
						createExplosion( x, y, z, 10, source )
						destroyElement( v )
					end
				end
			end

			for k, v in pairs( exports.global:getNearbyElements(source, "vehicle", 200) ) do
				if hasItem( v, 74, itemValue ) then
					blowVehicle( v )

					while hasItem( v, 74 ) do
						takeItem( v, 74 )
					end
				end
			end

			for k, v in pairs( exports.global:getNearbyElements(source, "player", 200) ) do
				if hasItem( v, 74, itemValue ) then
					local x, y, z = getElementPosition( v )
					createExplosion( x, y, z, 10, source )
					createExplosion( x, y, z, 10, source )

					while hasItem( v, 74 ) do
						takeItem( v, 74 )
					end
				end
			end
			
		elseif (itemID==76) then -- SHIELD
			if (shields[source]) then -- Already using the shield
				destroyElement(shields[source])
				shields[source] = nil
			else
				local x, y, z = getElementPosition(source)
				local rot = getPedRotation(source)

				x = x + math.sin(math.rad(rot)) * 1.5
				y = y + math.cos(math.rad(rot)) * 1.5

				local object = createObject(1631, x, y, z)
				setElementInterior(object, getElementInterior(source))
				setElementDimension(object, getElementDimension(source))
				
				setElementData(object, "kolize", 1, true)
				if tonumber(itemValue) then
					exports.bone_attach:attachElementToBone(object, source, 4, 0, -1.158+tonumber(itemValue), -0.83, 270, 10, 10)
				else
					attachElements(object, source, 0, 1, 0)
				end
				
				setElementCollisionsEnabled(object, true)
				shields[source] = object
			end
		elseif (itemID==77) then -- Card Deck
			local cards = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" }
			local sign = { "Spades", "Clubs", "Hearts", "Diamonds" }
			local number = math.random( 1, #cards )
			local snumber = math.random( 1, #sign )
			exports.global:sendLocalText(source, " ✪ " .. getPlayerName(source):gsub("_", " ") .. " draws a card and gets a" .. ( number == 1 and "n" or "" ) .. " " .. cards[number] .." of ".. sign[snumber] ..".", 255, 51, 102)
		elseif (itemID==79) then -- Porn tape
			exports.global:applyAnimation( source, "PAULNMAC", "wank_loop", -1, true, false, false)
		elseif (itemID==80) then -- Generic Item
			showItem(removeOOC(itemName))
		elseif (itemID==83) then -- Coffee
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "VENDING", "VEND_Drink_P", 4000, false, true, true)
			triggerEvent('sendAme', source, "vypil kafe.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==88) then -- earpiece
			outputChatBox("You can use this earpiece with an radio.", source, 255, 194, 14)
		elseif (itemID==89) then -- Generic Food
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "food", "eat_burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "snědl " .. itemValue .. ".")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==91) then
			giveHealth(source, 20)
			takeItemFromSlot(source, itemSlot)
			triggerEvent('sendAme', source, "slízal nanuk Calippo.")
			setElementHealth(source, 100)
		elseif (itemID==92) then
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "FOOD", "EAT_Burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "slízal nanuk.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==93) then
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "FOOD", "EAT_Burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "eats some Christmas Pudding.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==94) then
  			giveHealth(source, 20)
			exports.global:applyAnimation(source, "food", "eat_burger", 4000, false, true, true)
			toggleAllControls(source, true, true, true)
			triggerClientEvent(source, "onClientPlayerWeaponCheck", source)
			triggerEvent('sendAme', source, "snědl brambůrky Bohemia.")
			takeItemFromSlot(source, itemSlot)
			
		elseif (itemID==95) then -- Generic Drink
			giveHealth(source, 20)
			giveHealth(source, tonumber(getItemValue(itemID, itemValue)))
			exports.global:applyAnimation(source, "VENDING", "VEND_Drink_P", 4000, false, true, true)
			triggerEvent('sendAme', source, "vypil " .. itemValue .. ".")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==96) then -- PDA
			triggerEvent('sendAme', source, "si zapnul " .. ( itemValue == 1 and "notebook" or itemValue ) .. ".")
			triggerClientEvent(source, "useCompItem", source)
		elseif (itemID==97) then -- SFES Procedures Manual (book)
			local bookTitle = "SFES Procedure Manual"
			local bookName = "SFESProcedureManual"
			triggerEvent('sendAme', source, "čte ".. bookTitle ..".")
			triggerClientEvent( source, "showBook", source, bookName, bookTitle )
		elseif (itemID==98) then -- Garage Remote
			local id = tonumber( itemValue )
			if id and id >= 0 and id <= 49 then
				setGarageOpen(itemValue, not isGarageOpen(itemValue))

				local garages = {}
				for i = 0, 49 do
					garages[i] = isGarageOpen(i)
				end
				mysql:query_free("UPDATE settings SET value = '" .. mysql:escape_string( toJSON( garages ) ) .. "' WHERE name = 'garagestates'" )
			end
		elseif (itemID==99) then --[ADDED: 2/22/10 by herbjr] tray
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "food", "eat_burger", 4000, false, true, true)
			toggleAllControls(source, true, true, true)
			triggerClientEvent(source, "onClientPlayerWeaponCheck", source)
			triggerEvent('sendAme', source, "slízal nanuk.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==100) then --[ADDED: 2/22/10 by herbjr] milk
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "VENDING", "VEND_Drink_P", 4000, false, true, true)
			toggleAllControls(source, true, true, true)
			triggerClientEvent(source, "onClientPlayerWeaponCheck", source)
			triggerEvent('sendAme', source, "vypil malou krabičku mlíka.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==101) then --[ADDED: 2/22/10 by herbjr] juice
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "VENDING", "VEND_Drink_P", 4000, false, true, true)
			toggleAllControls(source, true, true, true)
			triggerClientEvent(source, "onClientPlayerWeaponCheck", source)
			triggerEvent('sendAme', source, "vypil malou krabičku džusu.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==102) then --[ADDED: 2/23/10 by herbjr] Cabbage (Asked for by Misha)
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "food", "eat_burger", 4000, false, true, true)
			toggleAllControls(source, true, true, true)
			triggerClientEvent(source, "onClientPlayerWeaponCheck", source)
			triggerEvent('sendAme', source, "snědl head of Cabbage.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==104) then -- portable TV
			triggerEvent("useTV", source, source)
			local isTvUsed = getElementData(source, "isTvUsed")
			if isTvUsed == nil or isTvUsed == false then
				triggerEvent('sendAme', source, "zapnul malou přenosnou televizi.")
				exports.anticheat:changeProtectedElementDataEx(source, "isTvUsed", true, false)
			else
				exports.anticheat:changeProtectedElementDataEx(source, "isTvUsed", false, false)
			end
		elseif (itemID == 105) then -- Pack of cigarettes. Withdraw one if it still has one
			if (itemValue > 0) then
				if (hasSpaceForItem(source, 106, 1)) then
					takeItemFromSlot(source, itemSlot)
					giveItem(source, itemID, itemValue - 1)
					giveItem(source, 106, 1)
					triggerEvent('sendAme', source, "otevřel krabičku cigaret a jednu vytáhl.")
				else
					outputChatBox( "Tvůj inventář je plný.", source, 255, 0, 0 )
				end
			else
				triggerEvent('sendAme', source, "otevřel krabičku cigaret, ale ta je prázdná.")
			end
			
		elseif (itemID == 2020) then -- Cigarette
			if hasItem( source, 107 ) then
				triggerEvent('sendAme', source, "si zapálil doutník.")
				outputChatBox( "(( /throwaway pro zahození, /switchhand pro přehození do druhé ruky ))", source )
				triggerEvent("realism:startsmoking", source, 0) -- 0 = left hand -- 1 = right hand
				takeItemFromSlot(source, itemSlot)
			else
				triggerEvent('sendAme', source, "si prohlíží doutník.")
				outputChatBox( "Nemáš zapalovač.", source, 255, 0, 0 )
			end				


		elseif (itemID == 106) then -- Cigarette
			if hasItem( source, 107 ) then
				triggerEvent('sendAme', source, "si zapálil cigaretu.")
				outputChatBox( "(( /throwaway pro zahození, /switchhand pro přehození do druhé ruky ))", source )
				triggerEvent("realism:startsmoking", source, 0) -- 0 = left hand -- 1 = right hand
				takeItemFromSlot(source, itemSlot)
			else
				triggerEvent('sendAme', source, "si prohlíží cigaretu.")
				outputChatBox( "Nemáš zapalovač.", source, 255, 0, 0 )
			end
		elseif (itemID == 107) then
			triggerEvent('sendAme', source, "hodil zapalovač do vzduchu a zase ho chytil.")
		elseif (itemID==108) then -- donut
			giveHealth(source, 20)
			exports.global:applyAnimation(source, "FOOD", "EAT_Burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "snědl palačinky.")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==109) or (itemID==110) then -- Fruit
			giveHealth(source, 20)
			giveHealth(source, tonumber(getItemValue(itemID, itemValue)))
			exports.global:applyAnimation(source, "food", "eat_burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "snědl " .. itemName .. ".")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID == 113) then -- Pack of glowsticks, Withdraw one if it still has one
			if (itemValue > 0) then
				if (hasSpaceForItem(source, 28, 1)) then
					glowStickColour = 1 + ( ( glowStickColour or 0 ) + 1 ) % 7

					takeItemFromSlot(source, itemSlot)
					giveItem(source, itemID, itemValue - 1)
					giveItem(source, 28, glowStickColour)
					triggerEvent('sendAme', source, "otevřel balíček glowsticků a jeden vytáhl.")
				else
					outputChatBox( "Tvůj inventář je plný.", source, 255, 0, 0 )
				end
			else
				triggerEvent('sendAme', source, "otevřel balíček glowsticků, ale ten je prázdný.")
			end
		elseif itemID == 114 then
			local vehicle = getPedOccupiedVehicle(source)
			local noUpgrades = { Boat = true, Helicopter = true, Plane = true, Train = true, BMX = true }

			if vehicle and not noUpgrades[getVehicleType(vehicle)] --[[and getElementDimension(vehicle) > 0]] and getItemDescription(itemID, itemValue) ~= "?" then
				addUpgrade( source, vehicle, itemSlot, itemID, itemValue )
			else
				outputChatBox("Toto je vylepšení do vozidla, aplikuje se ve vozidle.", source, 255, 194, 14)
			end
		elseif itemID == 126 then
			outputChatBox("Služební opasek, slouží pro zachycení zbraní.", source, 255, 220, 150)
		elseif itemID == 130 then
			outputChatBox("Polož alarm do vozidla, aby jsi ho nainstaloval.", source, 0, 255, 0)
		elseif itemID == 132 then
			takeItemFromSlot(source, itemSlot)
			outputChatBox("Vzal jsi si prášek " .. itemValue .. ".", source)
			triggerEvent('sendAme', source, "otevřel krabičku léků a vzal si prášek.")
			exports.global:applyAnimation(source, "VENDING", "VEND_Drink_P", 4000, false, true, true)
		elseif itemID == 134 then
			outputChatBox("" .. exports.global:formatMoney(itemValue) .. "$ v hotovosti.", source)
		elseif itemID == 137 then -- New snake cam, Adams
			triggerEvent('snakecam:toggleSnakeCam', root, source)
		elseif itemID == 138 then
			outputChatBox("Polož tohle zařízeni do vozidla, aby jsi ho nainstaloval.", source, 0, 255, 0)
		elseif itemID == 160 then -- Briefcase
			triggerEvent("artifacts:toggle", source, source, "briefcase")
		elseif itemID == 163 then
			triggerEvent("artifacts:toggle", source, source, "dufflebag")
		elseif badges[itemID] then
			toggleBadge(source, badges, itemID ,itemValue) --TO BE ABLE TO USED BY MULTIPLE SYSTEMS / MAXIME
		elseif masks[itemID] then
			local data = masks[itemID]
			local mask = getElementData(source, data[1])

			if mask then
				triggerEvent('sendAme', source, data[3]:gsub("#name",itemName) .. ".")
				exports.anticheat:changeProtectedElementDataEx(source, data[1], false, true)

				if itemID == 90 then -- Helmet
					triggerEvent("artifacts:remove", source, source, "helmet")
				elseif itemID == 26 then -- Gas mask
					triggerEvent("artifacts:remove", source, source, "gasmask")
				elseif itemID == 171 then -- Biker Helmet
					triggerEvent("artifacts:remove", source, source, "bikerhelmet")
				elseif itemID == 172 then -- Full Face Helmet
					triggerEvent("artifacts:remove", source, source, "fullfacehelmet")
				end
			elseif getPedOccupiedVehicle(source) and getElementData(getPedOccupiedVehicle(source), "job") > 0 and getVehicleOccupant(getPedOccupiedVehicle(source)) == source then
				outputChatBox("Nelze použít v civilním vozidle.", source, 255, 0, 0)
			else
				triggerEvent('sendAme', source, data[2]:gsub("#name",itemName) ..".")
				exports.anticheat:changeProtectedElementDataEx(source, data[1], true, true)

				if itemID == 90 then -- Helmet
					if getElementData(source, "bikerhelmet") then
						exports.anticheat:changeProtectedElementDataEx(source, "bikerhelmet", false, true)
						triggerEvent("artifacts:remove", source, source, "bikerhelmet")
					end
					if getElementData(source, "fullfacehelmet") then
						exports.anticheat:changeProtectedElementDataEx(source, "fullfacehelmet", false, true)
						triggerEvent("artifacts:remove", source, source, "fullfacehelmet")
					end
					local customTexture = getItemTexture(itemID, itemValue)
					triggerEvent("artifacts:add", source, source, "helmet", false, customTexture)
				elseif itemID == 26 then -- Gas mask
					triggerEvent("artifacts:add", source, source, "gasmask")
				elseif itemID == 171 then -- Biker Helmet
					if getElementData(source, "helmet") then
						exports.anticheat:changeProtectedElementDataEx(source, "helmet", false, true)
						triggerEvent("artifacts:remove", source, source, "helmet")
					end
					if getElementData(source, "fullfacehelmet") then
						exports.anticheat:changeProtectedElementDataEx(source, "fullfacehelmet", false, true)
						triggerEvent("artifacts:remove", source, source, "fullfacehelmet")
					end
					local customTexture = getItemTexture(itemID, itemValue)
					triggerEvent("artifacts:add", source, source, "bikerhelmet", false, customTexture)
				elseif itemID == 172 then -- Full Face Helmet
					if getElementData(source, "helmet") then
						exports.anticheat:changeProtectedElementDataEx(source, "helmet", false, true)
						triggerEvent("artifacts:remove", source, source, "helmet")
					end
					if getElementData(source, "bikerhelmet") then
						exports.anticheat:changeProtectedElementDataEx(source, "bikerhelmet", false, true)
						triggerEvent("artifacts:remove", source, source, "bikerhelmet")
					end
					local customTexture = getItemTexture(itemID, itemValue)
					triggerEvent("artifacts:add", source, source, "fullfacehelmet", false, customTexture)
				end
			end
		elseif itemID == 139 then
			outputChatBox("((Potřebuješ admina, aby jsi tohle nainstaloval do vozidla.))", source, 255, 0, 0)
		elseif itemID == 143 then
			outputChatBox("Polož tohle zařízeni do vozidla, aby jsi ho nainstaloval.", source, 0, 255, 0)
		elseif itemID == 145 then
			outputChatBox("Broken.", source, 255, 0, 0)
		elseif itemID == 173 then
			local px, py, pz = getElementPosition ( source )
			local distance = getDistanceBetweenPoints3D(px, py, pz, -2078.353515625, -95.5927734375, 35.1640625)
			if distance < 25 then
				triggerClientEvent(source, "build_carsale_gui", source)
			else
				outputChatBox("Pro prodej vozidla musíš být před licenčním úřadem.", source, 0, 255, 0)
			end
		elseif itemID == 151 then
            local px, py, pz = getElementPosition ( source )

            for i,v in ipairs ( getElementsByType ( "object" ) ) do
                local x, y, z = getElementPosition ( v )
                local distance = getDistanceBetweenPoints3D ( px, py, pz, x, y, z )

                if distance < 30 and getElementData ( v, "dbid" ) == tonumber ( itemValue ) and not getElementData ( v, "lift.moving" ) then
                    local lift = getElementData ( v, "lift" )
                    local lx, ly, lz = getElementPosition ( lift )

                    setElementData ( v, "lift.moving", true )

                    if not getElementData ( v, "lift.up" ) then
                        setElementData ( v, "lift.up", true )
                        moveObject ( lift, 4000, lx, ly, lz + 2.33 )
                        triggerEvent('sendAme',  source, "zmačkl tlačítko na ovladači a rampa jde nahoru" )
                        mysql:query_free ( "UPDATE ramps SET state = 1 WHERE id = " .. getElementData ( v, "dbid" ) )
                    else
                        setElementData ( v, "lift.up", false )
                        moveObject ( lift, 4000, lx, ly, lz - 2.33 )
                        triggerEvent('sendAme',  source, "zmačkl tlačítko na ovladači a rampa jde dolů" )
                        mysql:query_free ( "UPDATE ramps SET state = 0 WHERE id = " .. getElementData ( v, "dbid" ) )
                    end

                    setTimer ( setElementData, 4000, 1, v, "lift.moving", false )
                end
            end
        elseif itemID == 181 then
        	triggerEvent("sendAme", source, "všem ukazuje balíček papírků.")
    	elseif (itemID == 182) then
            if hasItem( source, 107 ) then -- If da player has a lighter, how else would he smoke it dawg
                exports.global:sendLocalMeAction(source, "si zapálil joint.")
                outputChatBox( "(( /throwaway pro zahození, /switchhand pro přehození ruky, /passjoint pro předání jointu ))", source )
                setElementData(source, "realism:joint", true) -- For the cigarette + new joint system
                triggerEvent("realism:startsmoking", source, 0) -- For the cigarette + new joint system
                takeItemFromSlot(source, itemSlot)
            else
                exports.global:sendLocalMeAction(source, "si prohlíží joint.")
                outputChatBox("Potřebuješ zapalovač.", source, 255, 0, 0)
            end
        elseif (itemID == 209) then
        	triggerEvent("gunlicense:weaponlicenses", root, source)
		elseif (itemID==210) then -- Coca-Cola Christmas Edition
			--if(getElementData(source,"drinking")) then
			--	return
			--end
			--setElementData(source, "drinking", true)
			if cokeBottles[source] then
				return
			end
			takeItemFromSlot(source, itemSlot)
			local x, y, z = getElementPosition(source)
			local int = getElementInterior(source)
			local dim = getElementDimension(source)
			local bottleObj = createObject(2880, x, y, z)
			cokeBottles[source] = bottleObj
			setElementInterior(bottleObj, int)
			setElementDimension(bottleObj, dim)
			setObjectScale(bottleObj, 1)
			setElementDoubleSided(bottleObj, false)
			exports.bone_attach:attachElementToBone(bottleObj,source,11,0,0,0,0,0,0)
			thePlayer = source
			setTimer(function()
				exports.global:applyAnimation(thePlayer, "VENDING", "VEND_Drink_P", 4000, false, true, true)
				toggleAllControls(thePlayer, true, true, true)
				triggerClientEvent(thePlayer, "onClientPlayerWeaponCheck", thePlayer)
				exports.global:sendLocalMeAction(thePlayer, "vypil kolu.")
				setTimer(giveHealth,4000,1,thePlayer,5)
				--setTimer(christmasCoke,4000,1,thePlayer) --DISABLE THIS LINE WHEN ITS NOT CHRISTMAS OR XMAS RESOUCE NOT RUNNING
				--setTimer(destroyElement,5000,1,bottleObj)
				setTimer(function()
					destroyElement(cokeBottles[thePlayer])
				end,4000,1)
				setTimer(function()
					cokeBottles[thePlayer] = nil
				end,5000,1)
				--setTimer(setElementData,6000,1,thePlayer,"drinking",false)
			end,3000,1)
			return
		elseif (itemID==213) then --pinnekjott
			giveHunger(source, 45)
			takeThirst(source, 3)
			exports.global:applyAnimation(source, "FOOD", "EAT_Burger", 4000, false, true, true)
			triggerEvent('sendAme', source, "snědl pinnekjott.")
			takeItemFromSlot(source, itemSlot)
			--local thisAnimFunc = exports.global:applyAnimation
			setTimer(function()
				exports.global:applyAnimation(source, "BSKTBALL", "BBALL_Jump_Shot", 4000, false, true, true)
			end, 5000, 1)
			if getResourceState(getResourceFromName("xmas")) == "running" then
				setTimer(triggerClientEvent, 7000, 1, "xmas:santaSound", getRootElement(), "hoho", source)
			end
		elseif (itemID==214) then
			triggerEvent('sendAme', source, "si vzal ".. itemName ..".")
			takeItemFromSlot(source, itemSlot)
		elseif (itemID==215) then
			triggerEvent('sendAme', source, "nese termální vrtačku.")
		elseif (itemID==216) then
			cistsmlouvu(source, itemValue)
		elseif (itemID==259) then -- Made by RecuvaPumDEV
			exports.global:sendLocalMeAction(source, "vytáhl z kapsy Tablet.")
            exports.recu_tablet:tablet_openi(source)
		elseif (itemID==221) then
			takeItemFromSlot(source, itemSlot)
			
			if(math.random(1,2)==1)then
				exports.global:giveItem(source, 220, 1)
			end
			if(math.random(1,2)==1)then
				exports.global:giveItem(source, 220, 1)
			end
			
			exports.global:giveItem(source, 30, 1)
			exports.global:giveItem(source, 30, 1)
			
			if(math.random(1,3)==1)then
				exports.global:giveItem(source, 30, 1)
			end
			if(math.random(1,3)==1)then
				exports.global:giveItem(source, 30, 1)
			end
			if(math.random(1,3)==1)then
				exports.global:giveItem(source, 30, 1)
			end
			if(math.random(1,3)==1)then
				exports.global:giveItem(source, 30, 1)
			end
		elseif itemID == 225 then
			takeItemFromSlot(source, itemSlot)
			outputChatBox("Vzal jsi si pilulku s označením " .. itemValue .. ".", source)
			triggerEvent('sendAme', source, "si vzal pilulku.")
			exports.global:applyAnimation(source, "VENDING", "VEND_Drink_P", 4000, false, true, true)
		elseif itemID == 226 then -- Reflexní vesta
			triggerEvent("artifacts:toggle", source, source, "reflexnivesta")
		elseif itemID == 227 then -- Vojenský batoh
			triggerEvent("artifacts:toggle", source, source, "backpack-military")
		elseif itemID == 228 then -- Medaile
			local medaile = {
				"medaile-cti",
				"medaile-hrdinstvi",
				"medaile-statecnost",
				"medaile-obrana",
				"medaile-zasluhy",
				"medaile-zasluhy2",
				"medaile-bezpecnost",
     }
			
			if(medaile[itemValue])then
				triggerEvent("artifacts:toggle", source, source, medaile[itemValue])
			end
		else 
			-- WHY? This does not really mean there's a bug. Just that we didnt add any click functionality to the item. Thus, commented out. --Exciter 2014-07-11
			--outputChatBox("Error J" .. ("%04d"):format(tonumber(itemID) or 9999) .. " - Report on http://forums.owlgaming.net/forms.php?do=form&fid=2", source, 255, 0, 0)
		end
	end
end
addEvent("useItem", true)
addEventHandler("useItem", getRootElement(), useItem)
addCommandHandler("useitem",
	function(thePlayer, commandName, itemID, ...)
		if tonumber( itemID ) then
			local args = {...}
			local itemValue
			if #args > 0 then
				itemValue = table.concat(args, " ")
				itemValue = tonumber(itemValue) or itemValue
			end

			local has, slot = hasItem(thePlayer, tonumber( itemID ), itemValue)
			if has then
				triggerEvent("useItem", thePlayer, slot)
			end
		end
	end
)

function npcUseItem(element, itemID)
	local source = element
	if itemID then	
		local hasItem, key, itemValue, itemIndex = hasItem(element, tonumber(itemID))
		--outputDebugString(" hasItem="..tostring(hasItem).." key="..tostring(key).." itemValue="..tostring(itemValue).." itemIndex="..tostring(itemIndex))
		if(hasItem) then
			local pedname = getElementData(element, "rpp.npc.name")
			if badges[itemID] then
				if ( getElementData( source, badges[itemID][1] ) ) then
					exports.anticheat:changeProtectedElementDataEx(source, badges[itemID][1], false, true)
					if pedname then
						--exports.global:sendLocalMeAction(source, "removes " .. badges[itemID][2] .. ".")
						exports.global:sendLocalText(source, "* "..tostring(pedname).." si sundal "..badges[itemID][2]..".", 255, 51, 102, 5)
					end
				else
					for key, badge in pairs ( badges ) do
						if key ~= itemID then
							if ( getElementData ( source, badge[1] ) ) then
								exports.anticheat:changeProtectedElementDataEx( source, badge[1], false, true )
								if pedname then
									--exports.global:sendLocalMeAction( source, "removes " .. badge[2] .. "." )
									exports.global:sendLocalText(source, "* "..tostring(pedname).." si sundal "..badge[2]..".", 255, 51, 102, 5)
								end
							end
						end
					end

					exports.anticheat:changeProtectedElementDataEx( source, badges[itemID][1], removeOOC(tostring(itemValue)), true )
					if pedname then
						--exports.global:sendLocalMeAction( source, "puts on " .. badges[itemID][2] .. "." )
						exports.global:sendLocalText(source, "* "..tostring(pedname).." si nasadil "..badges[itemID][2]..".", 255, 51, 102, 5)
					end
					return true
				end
				--exports.global:updateNametagColor(source)
			elseif masks[itemID] then
				local data = masks[itemID]
				local mask = getElementData(source, data[1])

				if mask then
					--exports.global:sendLocalMeAction(source, data[3] .. ".")
					exports.anticheat:changeProtectedElementDataEx(source, data[1], false, true)
					if pedname then
						exports.global:sendLocalText(source, "* "..tostring(pedname).." "..data[3]..".", 255, 51, 102, 5)
					end
					return false
				elseif getPedOccupiedVehicle(source) and getElementData(getPedOccupiedVehicle(source), "job") > 0 and getVehicleOccupant(getPedOccupiedVehicle(source)) == source then
					--outputChatBox("You can't use this in a Civilian vehicle.", source, 255, 0, 0)
					return false
				else
					--exports.global:sendLocalMeAction(source, data[2] ..".")
					exports.anticheat:changeProtectedElementDataEx(source, data[1], true, true)
					if pedname then
						exports.global:sendLocalText(source, "* "..tostring(pedname).." "..data[2]..".", 255, 51, 102, 5)
					end
					return true
				end
			else
				return false
			end
		else
			outputDebugString("The ped does not have that item")
			return false
		end
	end
end

function isBadge(item)
	if badges[item] then
		return true
	else
		return false		
	end
end
function isWearingBadge(element, item)
	if item then
		if isBadge(item) then
			if(getElementData(source, badges[item][1])) then
				return true
			else
				for key, badge in pairs ( badges ) do
					if key ~= item then
						if ( getElementData ( source, badge[1] ) ) then
							return true
						end
					end
				end
			end
		end
	else
		for key, badge in pairs ( badges ) do
			if ( getElementData ( source, badge[1] ) ) then
				return true
			end
		end		
	end
	return false
end

function addPlayerArtifacts(player)
	if not player then player = client or source end
	if hasItem(player,48) then --backpack
		triggerEvent("artifacts:add", player, player, "backpack", true)
	end
	if hasItem(player,227) then --backpack
		triggerEvent("artifacts:add", player, player, "backpack-military", true)
	end
	if hasItem(player,162) then --body armour
		triggerEvent("artifacts:add", player, player, "kevlar")
	end
	if hasItem(player,163) then --duffle bag
		triggerEvent("artifacts:add", player, player, "dufflebag")
	end
	if hasItem(player,164) then --medical bag
		triggerEvent("artifacts:add", player, player, "medicbag")
	end
end
addEvent("item-system:addPlayerArtifacts", true)
addEventHandler("item-system:addPlayerArtifacts", getRootElement(), addPlayerArtifacts)
function addAllArtifacts()
	for k,v in ipairs(getElementsByType("player")) do
		addPlayerArtifacts(v)
	end
end
addEvent("item-system:addAllArtifacts", true)
addEventHandler("item-system:addAllArtifacts", getRootElement(), addAllArtifacts)
addEventHandler("onCharacterLogin", getRootElement(), function()
	if not source then source = client end
	addPlayerArtifacts(source)
end)


function explodeFlash(obj)
	local players = exports.global:getNearbyElements(obj, "player")

	destroyElement(obj)
	for key, value in ipairs(players) do
		local gasmask = getElementData(value, "gasmask")

		if not (gasmask) then
			playSoundFrontEnd(value, 47)
			fadeCamera(value, false, 0.5, 255, 255, 255)
			setTimer(cancelEffect, 5000, 1, value)
			setTimer(playSoundFrontEnd, 1000, 1, value, 48)
		end
	end
end

function cancelEffect(thePlayer)
	fadeCamera(thePlayer, true, 6.0)
end

tags = {1524, 1525, 1526, 1527, 1528, 1529, 1530, 1531 }

function destroyGlowStick(marker)
	destroyElement(marker)
end

function destroyItem(itemID)
	if isPedDead(source) or getElementData(source, "injuriedanimation") then return end
	local itemName = ""
	if itemID and itemID > 0 then
		local itemSlot = itemID
		local item = getItems( source )[itemSlot]
		if item then
			local itemID = item[1]
			local itemValue = item[2]

			if itemID == 48 and countItems( source, 48 ) == 1 then -- backpack
				if getCarriedWeight( source ) - getItemWeight( 48, 1 ) > 10 then
					return
				end
			end
			
			if itemID == 227 and countItems( source, 227 ) == 1 then -- vojenský batoh
				if getCarriedWeight( source ) - getItemWeight( 227, 1 ) > 10 then
					return
				end
			end

			if itemID == 126 and countItems( source, 126 ) == 1 then -- duty belt
				if getCarriedWeight( source ) - getItemWeight( 126, 1 ) > 10 then
					return
				end
			end

			if itemID == 134 then
				exports.global:takeMoney(source, itemValue)
			end

			itemName = getItemName( itemID, itemValue )
			takeItemFromSlot(source, itemSlot)

			triggerClientEvent(source, "item:updateclient", source)

			doItemGiveawayChecks(source, itemID)
		else
			return
		end
	else
		if itemID == -100 then
			setPedArmor(source, 0)
			itemName = "neprůstřelnou vestu"
		else
			exports.global:takeWeapon(source, tonumber(-itemID))
			itemName = getWeaponNameFromID( -itemID )
		end
	end
	outputChatBox("Zničil jsi " .. string.lower(itemName) .. ".", source, 255, 194, 14)
	triggerEvent('sendAme', source, "zničil "..string.lower(itemName)..".")
end
addEvent("destroyItem", true)
addEventHandler("destroyItem", getRootElement(), destroyItem)

function isVowel(text)
	if not text or text == "" then
		return false
	end
	text = string.sub(text, 1, 1)
	text = string.lower(text)
	return text == "a" or text == "o" or text == "i" or text == "u" or text == "e"
end

function showItem(itemName)
	if isPedDead(source) or getElementData(source, "injuriedanimation") then return end
	triggerEvent('sendAme', source, "všem ukazuje " .. removeOOC(itemName) .. ".")
end
addEvent("showItem", true)
addEventHandler("showItem", getRootElement(), showItem)

function resetAnim(thePlayer)
	exports.global:removeAnimation(thePlayer)
end

function showInventoryRemote(thePlayer, commandName, targetPlayer)
	if exports.integration:isPlayerTrialAdmin(thePlayer) then
		if not (targetPlayer) then
			outputChatBox("SYNTAX: /" .. commandName .. " [Čast jmena / ID]", thePlayer, 255, 194, 14)
		else
			local targetPlayer = exports.global:findPlayerByPartialNick(thePlayer, targetPlayer)
			if targetPlayer then
				triggerEvent("subscribeToInventoryChanges",thePlayer,targetPlayer)
				triggerClientEvent(thePlayer,"showInventory",thePlayer,targetPlayer)
			end
		end
	end
end
addCommandHandler("showinv", showInventoryRemote, false, false)



--
-- are we watching TV?
--
function isWatchingTV( player )
	return exports['freecam-tv']:isPlayerFreecamEnabled( player )
end

function sortMoney(thePlayer, commandName, moneyAmountCurrent, moneyAmountSort)
	if not (moneyAmountCurrent) or not (moneyAmountSort) or tonumber(moneyAmountCurrent) < 0 or tonumber(moneyAmountSort) < 0 then
		outputChatBox("SYNTAX: /" .. commandName .. " [Počet peněz které máš] [Počet peněz které chceš rozdělit]", thePlayer, 255, 194, 14)
	else
		local playerMoney = getElementData(thePlayer, "money")
		if tonumber(moneyAmountCurrent) <= tonumber(playerMoney) and tonumber(moneyAmountSort) <= tonumber(playerMoney) then
			if exports.global:hasItem(thePlayer, 134, tonumber(moneyAmountCurrent)) then
				outputChatBox("You sorted $" .. exports.global:formatMoney(moneyAmountSort) .. " out of $" .. exports.global:formatMoney(moneyAmountCurrent) .. ".", thePlayer)
				exports.global:takeItem(thePlayer, 134, tonumber(moneyAmountCurrent))
				exports.global:giveItem(thePlayer, 134, tonumber(moneyAmountSort))
				exports.global:giveItem(thePlayer, 134, tonumber(moneyAmountCurrent)-tonumber(moneyAmountSort))
			else
				outputChatBox("Nemaš tam dostatek peněz v rozdělenem itemu.", thePlayer, 255, 0, 0)
			end
		else
			outputChatBox("Nemaš tolik peněz.", thePlayer, 255, 0, 0)
		end
	end
end
addCommandHandler("sortmoney", sortMoney)

function combineMoney(thePlayer, commandName)
		for i = 134, 134 do
			while exports['item-system']:takeItem(thePlayer, i) do
			end
		end
		local playerMoney = getElementData(thePlayer, "money")
		if tonumber(playerMoney) > 0 then
			exports.global:giveItem(thePlayer, 134, playerMoney)
			outputChatBox("Rozložil si $" .. exports.global:formatMoney(playerMoney) .. ".", thePlayer)
		else
			outputChatBox("Nemůžeš rozdělit peníze které nemáš!", thePlayer, 255, 0, 0)
		end
end
addCommandHandler("combinemoney", combineMoney)

function toggleBadge(source, badges, itemID , itemValue)
	if ( getElementData( source, badges[itemID][1] ) ) then
		exports.anticheat:changeProtectedElementDataEx(source, badges[itemID][1], false, true)
		if itemID == 122 or itemID == 123 or itemID == 124 or itemID == 125 or itemID == 135 or itemID == 136 or itemID == 158 or itemID == 168 or itemID == 246 or itemID == 251 or itemID == 245 then
			triggerEvent('sendAme',  source, "si sundal " .. badges[itemID][2] .. " z krku." )
		else
			triggerEvent('sendAme', source, "si odepnul " .. badges[itemID][2] .. ".")
		end
	else
		for key, badge in pairs ( badges ) do
			if key ~= itemID then
				if ( getElementData ( source, badge[1] ) ) then
					exports.anticheat:changeProtectedElementDataEx( source, badge[1], false, true )
					if itemID == 122 or itemID == 123 or itemID == 124 or itemID == 125 or itemID == 135 or itemID == 136 or itemID == 158 or itemID == 168 or itemID == 246 or itemID == 251 or itemID == 245 then
						triggerEvent('sendAme',  source, "si sundal " .. badge[2] .. " z krku." )
					else
						triggerEvent('sendAme',  source, "si odepnul " .. badge[2] .. "." )
					end
				end
			end
		end

		if itemID == 122 or itemID == 123 or itemID == 124 or itemID == 125 or itemID == 135 or itemID == 136 or itemID == 158 or itemID == 168 or itemID == 246 or itemID == 245 then
			exports.anticheat:changeProtectedElementDataEx( source, badges[itemID][1], true )
			triggerEvent('sendAme',  source, "si dal " .. badges[itemID][2] .. " na krk." )
		else
			exports.anticheat:changeProtectedElementDataEx( source, badges[itemID][1], removeOOC(itemValue), true )
			triggerEvent('sendAme',  source, "si nasadil " .. badges[itemID][2] .. "." )
		end
	end
	exports.global:updateNametagColor(source)
end
addEvent("item-system:toggleBadge", true)
addEventHandler("item-system:toggleBadge", getRootElement(), toggleBadge)


---------------------------------------
-- START CHRISTMAS BOTTLES (Exciter) --
---------------------------------------
--SETTINGS:
local santaCharID = 19379
local santaCokeID = 210
local santaLotteryTicketID = 211

local christmasLotteryPrizes = {
	--itemID,value
	{210,"1"}, --A coke bottle
	{17,"1"}, --Watch
	{10,"1"}, --Dice
	{55,"Santa Claus. 1, North Pole."}, --Business Card
	{113,"3"}, --Pack of glowsticks
	{59,"1"}, --Mudkip
	{160,"1"}, --Briefcase
	{91,"1"}, --Eggnog
	{92,"1"}, --Turkey
	{93,"1"}, --Christmas Pudding
	{94,"1"}, --Christmas Present
	{213,"1"}, --Pinnekjott

}
function giveHunger( player, amount )
	--if player and amount then
		--local playerHunger = getElementData(player, "hunger")
		--if playerHunger + tonumber(amount) >= 100 then
			--setElementData(player, "hunger", 100)
		--else
			--setElementData(player, "hunger", playerHunger + tonumber(amount))
		--end
	--end
end

function giveThirst( player, amount )
	--[[if player and amount then
		local playerThirst = getElementData(player, "thirst")
		if playerThirst + tonumber(amount) >= 100 then
			setElementData(player, "thirst", 100)
		else
			setElementData(player, "thirst", playerThirst + tonumber(amount))
		end
	end]]
end

function takeHunger( player, amount )
	--[[if player and amount then
		local playerHunger = getElementData(player, "hunger")
		if playerHunger - tonumber(amount) <= 0 then
			setElementData(player, "hunger", 0)
		else
			setElementData(player, "hunger", playerHunger - tonumber(amount))
		end
	end]]
end

function takeThirst( player, amount )
	--[[if player and amount then
		local playerThirst = getElementData(player, "thirst")
		if playerThirst - tonumber(amount) <= 0 then
			setElementData(player, "thirst", 0)
		else
			setElementData(player, "thirst", playerThirst - tonumber(amount))
		end
	end]]
end
function christmasCoke(thePlayer)
	local santaCars = {}
	for k,v in ipairs(getElementsByType("Vehicle")) do
		if(tonumber(getElementData(v,"owner")) == santaCharID and getElementData(v,"faction") == -1) then
			table.insert(santaCars,v)
		end
	end
	if(#santaCars > 0) then
		local chance = 2 --percentage chance of getting a car
		local chanceSuper = 1 --percentage chance of getting a supercar
		for k,v in ipairs(santaCars) do
			local vehID = tonumber(getElementData(v,"dbid"))
			local thisChance = 0
			if(vehID == 2439) then --enter supercar ids here
				thisChance = chanceSuper
			--elseif(getElementData(thePlayer,"username") == "Exciter") then
			--	thisChance = 50
			elseif(getPlayerName(thePlayer) == "Santa_Claus") then
					thisChance = 100
			else
				thisChance = chance
			end

			if math.random(100) >= thisChance then --if no car won
				--do nothing, we'll give the chance of other prizes at the end of this func
			else
				outputChatBox("Našel si klič od auta ve flašce!",thePlayer,0,255,0)
				local gender = tonumber(getElementData(thePlayer, "gender")) or 0
				local gendertext
				if gender > 0 then
					gendertext = "her"
				else
					gendertext = "his"
				end
				exports.global:sendLocalMeAction(thePlayer, "našel klič od auta v"..tostring(gendertext).." vánočni coca-cole.")
				giveItem(thePlayer, 3, vehID) --give the vehicle key
				return
			end
		end
	end

	if math.random(100) >= 40 then
		--no prize
	else
		local prizes = christmasLotteryPrizes
		local prize = math.random(1,#prizes)
		local ticketValue = prize+89027548971875
		outputChatBox("Našel si vanočni loterírni ticket ve flašce",thePlayer,0,255,0)
		giveItem(thePlayer, santaLotteryTicketID, tostring(ticketValue)) --give a christmas lottery ticket
		local gender = tonumber(getElementData(thePlayer, "gender")) or 0
		local gendertext
		if gender > 0 then
			gendertext = "her"
		else
			gendertext = "his"
		end
		exports.global:sendLocalMeAction(thePlayer, "našel loterírni ticket v  "..tostring(gendertext).." vánoční coca-cole.")
	end
end

function christmasLotteryUseTicket(santa)
	local thePlayer = client
	local hasItem, itemSlot, itemValue = exports.global:hasItem(thePlayer, santaLotteryTicketID)
	if hasItem then
		takeItemFromSlot(thePlayer, itemSlot)
		local prizes = christmasLotteryPrizes
		local prize = tonumber(itemValue)-89027548971875
		if prizes[prize] then
			giveItem(thePlayer, prizes[prize][1], prizes[prize][2])
			local itemName = g_items[prizes[prize][1]][1]
			local playerName = getPlayerName(thePlayer):gsub("_", " ")
			exports.global:sendLocalMeAction(santa, "dal "..tostring(playerName).." a "..tostring(itemName)..".")
		else
			outputChatBox("Promiň, nic si nevyhral na tom ticketu.",thePlayer,255,0,0)
			outputDebugString("item-system/s_item_system: Prize was "..tostring(prize).." (invalid)")
		end
	end
end
addEvent("item-system:useChristmasLotteryTicket", true)
addEventHandler("item-system:useChristmasLotteryTicket", getRootElement(), christmasLotteryUseTicket)

function christmasGetCokeFromSanta(santa)
	local thePlayer = client
	--local cokesGotten = tonumber(getElementData(thePlayer, "cokesgotten")) or 0
	--if(cokesGotten > 5) then
	--	return
	--end
	giveItem(thePlayer, santaCokeID, "1")
	--setElementData(thePlayer, "cokesgotten", cokesGotten+1)
	local playerName = getPlayerName(thePlayer):gsub("_", " ")
	exports.global:sendLocalMeAction(santa, "gives "..tostring(playerName).." a coke.")
end
addEvent("item-system:santaGetCoke", true)
addEventHandler("item-system:santaGetCoke", getRootElement(), christmasGetCokeFromSanta)

function christmasInitialize()
	for k,v in ipairs(getElementsByType("Player")) do
		setElementData(v,"drinking",false)
	end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), christmasInitialize)

addEventHandler("onPlayerQuit", getRootElement(),
function()
	if cokeBottles[source] then
		destroyElement(cokeBottles[source])
		cokeBottles[source] = nil
	end
end)

addEventHandler("accounts:characters:change", getRootElement(),
function()
	if cokeBottles[client] then
		destroyElement(cokeBottles[client])
		cokeBottles[client] = nil
	end
end)