Vehicles/VehicleScripts/NetworkEvents/EventEnterVehicle.lua

This file contains all revelant events for entering and leaving vehicles. Clients will send a EventRequestSwitchVehicle event to the server when the player presses the Tab key, and they will send an EventLeaveVehicle when the player wants to leave the current vehicle. The rest of leaving/entering is handled via the network entity system.

  25  EventRequestSwitchVehicle           = EventRequestSwitchVehicle or ExtensionOf(BaseEvent);
  26  
  27  InitVanillaEvent(EventRequestSwitchVehicle, "EventRequestSwitchVehicle");
  28  
  29  function EventRequestSwitchVehicle:sendData(delta)
  30      assert(g_isClient, "Client -> Server only event");
  31  
  32      streamWriteBool(delta > 0);
  33  end;
  34  
  35  function EventRequestSwitchVehicle:receiveData(connection)
  36      if g_isClient then
  37          print("Warning: Received invalid 'EventRequestSwitchVehicle' event on this client.");
  38          return;
  39      end;
  40  
  41      local delta                     = streamReadBool() and 1 or -1;
  42      local player                    = g_networkGame:getPlayerByConnection(connection);
  43  
  44      if player ~= nil then
  45          VehicleManager:switchVehicle(delta, player);
  46      end;
  47  end;
  48  
  49  
  50  EventLeaveVehicle                   = EventLeaveVehicle or ExtensionOf(BaseEvent);
  51  
  52  InitVanillaEvent(EventLeaveVehicle, "EventLeaveVehicle");
  53  
  54  function EventLeaveVehicle:sendData(entity, isEnteringOtherVehicle)
  55      assert(g_isClient, "Client -> Server only event");
  56  
  57      streamWriteEntityId(entity);
  58      streamWriteBool(getNoNil(isEnteringOtherVehicle, false));
  59  end;
  60  
  61  function EventLeaveVehicle:receiveData(connection)
  62      if g_isClient then
  63          print("Warning: Received invalid 'EventLeaveVehicle' event on this client.");
  64          return;
  65      end;
  66  
  67      local entity                    = streamReadEntityId();
  68      local isEnteringOtherVehicle    = streamReadBool();
  69  
  70      if entity ~= nil then
  71          entity:handleLeave(g_networkGame:getPlayerByConnection(connection), isEnteringOtherVehicle);
  72      end;
  73  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.