Vehicles/VehicleScripts/NetworkEvents/EventVehicleSeats.lua

This file contains all event that are relevant for Seats.

  25  
  26  local function local_streamWriteSeat(entity, seatId)
  27      if streamWriteBool(type(entity) == "string") then
  28          -- first argument may be a string - in that case it is a key
  29          streamWriteString(entity);
  30      else
  31          streamWriteEntityId(entity);
  32          streamWriteUInt16(seatId);
  33      end;
  34  end;
  35  
  36  local function local_streamReadSeat()
  37      if streamReadBool() then
  38          -- this is a string
  39          local key                   = streamReadString();
  40          return VehicleSeat.getStaticSeatByKey(key);
  41  
  42      else
  43          local entity                = streamReadEntityId();
  44          local seatId                = streamReadUInt16();
  45  
  46          if entity ~= nil then
  47              if entity.getSeatById == nil then
  48                  print("Warning: Entity with entity id '" .. tostring(entity.entityId) .. "' does not have a getSeatById function!");
  49              else
  50                  -- find the seat of that entity
  51                  return entity:getSeatById(seatId);
  52              end;
  53          end;
  54      end;
  55  end;
  56  
  57  
  58  EventRequestEnterVehicleSeat        = EventRequestEnterVehicleSeat or ExtensionOf(BaseEvent);
  59  
  60  InitVanillaEvent(EventRequestEnterVehicleSeat, "EventRequestEnterVehicleSeat");
  61  
  62  function EventRequestEnterVehicleSeat:sendData(entity, seatId)
  63      assert(g_isClient, "Client -> Server only event");
  64  
  65      local_streamWriteSeat(entity, seatId);
  66  end;
  67  
  68  function EventRequestEnterVehicleSeat:receiveData(connection)
  69      if g_isClient then
  70          print("Warning: Received invalid 'EventRequestEnterVehicleSeat' event on this client.");
  71          return;
  72      end;
  73  
  74      local seat                      = local_streamReadSeat();
  75      if seat ~= nil then
  76          seat:enterRequest(g_networkGame:getPlayerByConnection(connection));
  77      end;
  78  end;
  79  
  80  EventRequestLeaveVehicleSeat        = EventRequestLeaveVehicleSeat or ExtensionOf(BaseEvent);
  81  
  82  InitVanillaEvent(EventRequestLeaveVehicleSeat, "EventRequestLeaveVehicleSeat");
  83  
  84  function EventRequestLeaveVehicleSeat:sendData(isEnteringOtherVehicle, entity, seatId)
  85      assert(g_isClient, "Client -> Server only event");
  86  
  87      local_streamWriteSeat(entity, seatId);
  88      streamWriteBool(isEnteringOtherVehicle);
  89  end;
  90  
  91  function EventRequestLeaveVehicleSeat:receiveData(connection)
  92      if g_isClient then
  93          print("Warning: Received invalid 'EventRequestLeaveVehicleSeat' event on this client.");
  94          return;
  95      end;
  96  
  97      local seat                      = local_streamReadSeat();
  98      isEnteringOtherVehicle          = streamReadBool();
  99      if seat ~= nil then
 100          seat:leaveRequest(g_networkGame:getPlayerByConnection(connection), isEnteringOtherVehicle);
 101      end;
 102  end;
 103  
 104  EventSetVehicleSeatUser     = EventSetVehicleSeatUser or ExtensionOf(BaseEvent);
 105  
 106  InitVanillaEvent(EventSetVehicleSeatUser, "EventSetVehicleSeatUser");
 107  
 108  function EventSetVehicleSeatUser:sendData(player, entity, seatId)
 109      assert(g_isServer, "Server -> Client only event");
 110  
 111      local_streamWriteSeat(entity, seatId);
 112      streamWriteUInt8(g_networkGame:getPlayerId(player));
 113  end;
 114  
 115  function EventSetVehicleSeatUser:receiveData(connection)
 116      if g_isServer then
 117          print("Warning: Received invalid 'EventSetVehicleSeatUser' event on this server.");
 118          return;
 119      end;
 120  
 121      local seat                      = local_streamReadSeat();
 122      local playerId                  = streamReadUInt8();
 123      local player                    = g_networkGame:getPlayerById(playerId);
 124  
 125      if seat ~= nil then
 126          seat:setCurrentUser(player, true);
 127      end;
 128  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.