SetPorteEvent = {};
SetPorteEvent_mt = Class(SetPorteEvent, Event);

InitEventClass(SetPorteEvent, "SetPorteEvent");

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

function SetPorteEvent:new(vehicle, Porte)
    local self = SetPorteEvent:emptyNew()
    self.vehicle = vehicle;
	self.Porte = Porte;
    return self;
end;

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

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

function SetPorteEvent:run(connection)   
	self.vehicle:setPorte(self.Porte, true);
    if not connection:getIsServer() then
        g_server:broadcastEvent(SetPorteEvent:new(vehicle, self.Porte), nil, connection, self.vehicle);
    end;
end;

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