SetDoManualUnloadEvent = {};
SetDoManualUnloadEvent_mt = Class(SetDoManualUnloadEvent, Event);

InitEventClass(SetDoManualUnloadEvent, "SetDoManualUnloadEvent");

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

function SetDoManualUnloadEvent:new(vehicle, state)
    local self = SetDoManualUnloadEvent:emptyNew()
    self.vehicle = vehicle;
	self.state = state;
	return self;
end;

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

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

function SetDoManualUnloadEvent:run(connection)
	self.vehicle:setdoManualUnload(self.state, true);
	--if self.state == false then
		--self.vehicle:setManualUnloading(false, true);
	--end;
	--setManualUnloading
	if not connection:getIsServer() then
		g_server:broadcastEvent(SetDoManualUnloadEvent:new(self.vehicle, self.state), nil, connection, self.object);
	end;
end;

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