Vehicles/VehicleScripts/NetworkEvents/EventAttacherSystem.lua

This file contains all revelant events for the attacher system implemented in Attacher and Attachable.

  25  EventAttachVehicle                  = EventAttachVehicle or ExtensionOf(BaseEvent);
  26  
  27  InitVanillaEvent(EventAttachVehicle, "EventAttachVehicle");
  28  
  29  function EventAttachVehicle:sendData(master, slave)
  30      streamWriteEntityId(master.vehicle);
  31      streamWriteUInt8(master.networkId);
  32      streamWriteEntityId(slave.vehicle);
  33      streamWriteUInt8(slave.networkId);
  34  end;
  35  
  36  function EventAttachVehicle:receiveData(connection)
  37      local masterVehicle             = streamReadEntityId();
  38      local masterNetworkId           = streamReadUInt8();
  39      local slaveVehicle              = streamReadEntityId();
  40      local slaveNetworkId            = streamReadUInt8();
  41  
  42      if masterVehicle ~= nil and slaveVehicle ~= nil then
  43          local master                = masterVehicle.masterAttachers[masterNetworkId];
  44          local slave                 = slaveVehicle.slaveAttachers[slaveNetworkId];
  45  
  46          if master ~= nil and slave ~= nil then
  47              -- client -> server: request
  48              -- server -> client: confirmation
  49              masterVehicle:attach(master, slave, true);
  50          end;
  51      end;
  52  end;
  53  
  54  EventDetachVehicle                  = EventDetachVehicle or ExtensionOf(BaseEvent);
  55  
  56  InitVanillaEvent(EventDetachVehicle, "EventDetachVehicle");
  57  
  58  function EventDetachVehicle:sendData(master)
  59      streamWriteEntityId(master.vehicle);
  60      streamWriteUInt8(master.networkId);
  61  end;
  62  
  63  function EventDetachVehicle:receiveData(connection)
  64      local masterVehicle             = streamReadEntityId();
  65      local masterNetworkId           = streamReadUInt8();
  66  
  67      if masterVehicle ~= nil then
  68          local master                = masterVehicle.masterAttachers[masterNetworkId];
  69  
  70          if master ~= nil then
  71              -- client -> server: request
  72              -- server -> client: confirmation
  73              masterVehicle:detach(master, true);
  74          end;
  75      end;
  76  end;

All contents of this page may be used for modding use for Winter Resort Simulator - Season 2 only. Any use exceeding this regulation is not permitted.

Copyright (C) HR Innoways, 2021. All Rights Reserved.