-- New Env_Item by Rian2_idih

function useequip(id,weapon)
	id = tonumber(id)
	weapon = tonumber(weapon)
	parse("equip "..id.." "..weapon)
end

function useswitch(id,weapon)
	id = tonumber(id)
	weapon = tonumber(weapon)
	for _, weap in pairs(playerweapons(id)) do
		if weap==weapon then
			parse("setweapon "..id.." "..weapon)
		end
	end
end

function usestrip(id,weapon)
	id = tonumber(id)
	weapon = tonumber(weapon)
	for _, weap in pairs(playerweapons(id)) do
		if weap==weapon then
			parse("strip "..id.." "..weapon)
		end
	end
end

function useexists(id,weapon)
	id = tonumber(id)
	weapon = tonumber(weapon)
	exists = false
	for _, weap in pairs(playerweapons(id)) do
		if weap==weapon then
			exists = true
		end
	end
	if exists==true then
		msg2(id,string.char(169).."000255000You have "..itemtype(weapon,"name"))
	elseif exists==false then
		msg2(id,string.char(169).."255000000You don't have "..itemtype(weapon,"name"))
	end
end

addhook("movetile","_movetile")
function _movetile(id,x,y)
	if entity(x,y,"typename")=="Env_Item" then
		list = {equip = false,switch = false,strip = false,exitst = false}
		commands = entity(x,y,"trigger")
		weapon = entity(x,y,"int0")
		if commands:find("equip")~=nil then
			list.equip=true
		end
		if commands:find("switch")~=nil then
			list.switch=true
		end
		if commands:find("strip")~=nil then
			list.strip=true
		end
		if commands:find("exists")~=nil then
			list.exists=true
		end
		if list.equip then
			useequip(id,weapon)
		end
		if list.switch then
			useswitch(id,weapon)
		end
		if list.strip then
			usestrip(id,weapon)
		end
		if list.exists then
			useexists(id,weapon)
		end
	end
end