SetTapisEvent = {};
SetTapisEvent_mt = Class(SetTapisEvent, Event);

InitEventClass(SetTapisEvent, "SetTapisEvent");

function SetTapisEvent:emptyNew()
    local self = Event:new(SetTapisEvent_mt);
    self.className="SetTapisEvent";
    return self;
end;

function SetTapisEvent:new(vehicle, Tapis)
    local self = SetTapisEvent:emptyNew()
    self.vehicle = vehicle;
	self.Tapis = Tapis;
    return self;
end;

function SetTapisEvent:readStream(streamId, connection)
    local id = streamReadInt32(streamId);
	self.Tapis = streamReadBool(streamId);
    self.vehicle = networkGetObject(id);
    self:run(connection);
end;

function SetTapisEvent:writeStream(streamId, connection)
    streamWriteInt32(streamId, networkGetObjectId(self.vehicle));
	streamWriteBool(streamId, self.Tapis);
end;

function SetTapisEvent:run(connection)   
	self.vehicle:setTapis(self.Tapis, true);
    if not connection:getIsServer() then
        g_server:broadcastEvent(SetTapisEvent:new(vehicle, self.Tapis), nil, connection, self.vehicle);
    end;
end;

function SetTapisEvent.sendEvent(vehicle, Tapis, noEventSend)
	if noEventSend == nil or noEventSend == false then
		if g_server ~= nil then
			g_server:broadcastEvent(SetTapisEvent:new(vehicle, Tapis), nil, nil, vehicle);
		else
			g_client:getServerConnection():sendEvent(SetTapisEvent:new(vehicle, Tapis));
		end;
	end;
end;