SetEchelleEvent = {};
SetEchelleEvent_mt = Class(SetEchelleEvent, Event);

InitEventClass(SetEchelleEvent, "SetEchelleEvent");

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

function SetEchelleEvent:new(vehicle, Echelle)
    local self = SetEchelleEvent:emptyNew()
    self.vehicle = vehicle;
	self.Echelle = Echelle;
    return self;
end;

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

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

function SetEchelleEvent:run(connection)   
	self.vehicle:setEchelle(self.Echelle, true);
    if not connection:getIsServer() then
        g_server:broadcastEvent(SetEchelleEvent:new(vehicle, self.Echelle), nil, connection, self.vehicle);
    end;
end;

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