-- Container Tags
-- Author: Dismellion


CTags = {}
CTags.version = '1.0.0';
CTags.build = '41.78';
CTags.drawData = {};

function CTags:tableContains(t, e)
	for _, value in pairs(t) do
		if value == e then
			return true
		end
	end
	return false
end

function CTags:splitString(inputstr, sep)
	if sep == nil then
		sep = "%s"
	end
	local t={}
	for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
		table.insert(t, str)
	end
	return t
end

function CTags:inSafehouse(object)
	if (getWorld():getGameMode() == "Multiplayer") then
		if not SandboxVars.CTags.restirctSafehouse then return true end; 
		local square = object:getSquare();
		local safehouses = SafeHouse:getSafehouseList();
		local username = getPlayer():getUsername();
		for i=0,SafeHouse.getSafehouseList():size()-1 do
			local safe = SafeHouse.getSafehouseList():get(i);
			local doesContain = safe:containsLocation(square:getX(), square:getY()) and safe:getPlayers():contains(username); 
			if doesContain then return true end;
		end
		return false;
	end
	return true
end

function CTags:sleepDo(seconds, func, condition)
	local time = os.time();
	local targetTime = time + seconds;
	if condition == nil then condition = true end; -- Optional 


	local function OnSleepTick()
		local timeNew = os.time();
		if not condition then 
			Events.OnTick.Remove(OnSleepTick);
			return
		end
		if timeNew >= targetTime then
			Events.OnTick.Remove(OnSleepTick);
			func();
		end
	end
	Events.OnTick.Add(OnSleepTick)
end