SetRamaEvent = {};
SetRamaEvent_mt = Class(SetRamaEvent, Event);

InitEventClass(SetRamaEvent, "SetRamaEvent");

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

function SetRamaEvent:new(vehicle, ramaState)
    local self = SetRamaEvent:emptyNew()
    self.vehicle = vehicle;
	self.ramaState = ramaState;
    return self;
end;

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

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

function SetRamaEvent:run(connection)   
	self.vehicle:toggleRama(self.ramaState, true);
    if not connection:getIsServer() then
        g_server:broadcastEvent(SetRamaEvent:new(self.vehicle, self.ramaState), nil, connection, self.vehicle);
    end;
end;

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