InitVanillaEvent(class, eventName)

Inits a new event. Always use this function in vanilla game code (less overhead when synchronizing the game). Never call this function from a mod.

  31  function InitVanillaEvent(class, eventName)
  32      if g_isHotReload then
  33          if EventIds.eventsByName[eventName] then
  34              return;
  35          end;
  36          -- otherwise we are registering a new event, which is okay during runtime (as long as the id has been added at the very bottom of the list)
  37      else
  38          assert(g_scenario == nil, "Cannot add a new event while the game is running.");
  39      end;
  40      
  41      local id                        = assert(VanillaEventIds[eventName],  "Invalid vanilla event name: '" .. tostring(eventName) .. "'");
  42      -- make sure that the event id is not yet used
  43      assert(EventIds.eventsByName[eventName] == nil, string.format("Event '%s' is already in use",   eventName));
  44  
  45      -- assign them
  46      EventIds.vanillaEvents[id]          = class;
  47      --EventIds.eventsByName[eventName]  = class;
  48  
  49      if not g_isHotReload or class.eventId == nil then
  50          EventIds:assignEventId(class, id);
  51      end;
  52  end;
  53  

InitModEvent(class, name)

Inits a new event (called by a mod). Exclusively use this function for any non-vanilla content (DLCs, mods, etc.).

  57  function InitModEvent(class, name)
  58      assert(g_scenario == nil, "Cannot add a new event while the game is running.");
  59  
  60      -- just add it as event by name, will be registered when starting the game
  61      EventIds.eventsByName[name] = class;
  62  end;
  63  

EventIds:getEventId(event)

Returns the id of the event's type.

  67  function EventIds:getEventId(event)
  68      assert(type(event) == "table", "argument 1 must be a table");
  69      return event.eventId;
  70  end;
  71  

EventIds:getEventById(id)

Returns the event that has event id.

  74  function EventIds:getEventById(id)
  75      -- get the according event
  76      local event             = EventIds.events[id or 0];
  77  
  78      assert(event ~= nil, "Event " .. tostring(id) .. " does not exist on this client.");
  79      return event;
  80  end;
  81  

EventIds:assignAllEventIds()

Assigns valid event ids to all mod events. Vanilla events will not be changed.

  84  function EventIds:assignAllEventIds()
  85      -- assign event ids upon the start of the game
  86      -- must be called on the server before the game starts!
  87      for name, class in pairs(self.eventsByName) do
  88          self:assignEventId(class, EventIds.lastEventId + 1);
  89      end;
  90  end;
  91  

EventIds:assignEventId(class, id)

Assigns the event id id to the specified class.

  95  function EventIds:assignEventId(class, id)
  96      assert(id ~= nil,                           "Cannot add event with event id 'nil' (second argument must be an integer)");
  97      assert(EventIds.events[id] == nil,  string.format("Event id %d is already in use",      id));
  98  
  99      -- get type id of that class (and not of a parent class) => rawget
 100      if rawget(class, "eventId") == nil then
 101          -- we need to register this one
 102          EventIds.events[id]     = class;
 103          EventIds.lastEventId        = math.max(EventIds.lastEventId, id);
 104          
 105          -- assign event id to that class
 106          class.eventId               = id;
 107      end;
 108  
 109      return id;
 110  end;
 111  

EventIds:revertAssigning()

Reverts all assigned ids. Call this upon closing the game.

 115  function EventIds:revertAssigning()
 116      -- reset any assigned events upon closing the game
 117      -- revert all assigned ids
 118      for className, class in pairs(self.eventsByName) do
 119          if class.eventId ~= nil and self.vanillaEvents[class.eventId] == nil then
 120              -- unregister the event id of that class
 121              rawset(class, "eventId", nil);
 122          end;
 123      end;
 124      
 125      -- remove the old list of assigned ids
 126      self.events             = TableUtil.deepCopy(EventIds.vanillaEvents);
 127  
 128      -- also determine the highest event id in that table
 129      local highestId                 = 0;
 130  
 131      for id, class in pairs(self.events) do
 132          highestId                   = math.max(highestId, id);
 133      end;
 134  
 135      self.lastEventId            = highestId;
 136  end;
 137  

EventIds:writeResyncEventIds()

Writes all event ids to the other player.

 141  function EventIds:writeResyncEventIds()
 142      -- synchronize all dynamic event ids
 143      -- note that EventIds:assignAllEventIds() must be called beforehand!
 144  
 145      local eventId;
 146  
 147      -- get the number of events beforehand
 148      local eventCount            = count(self.eventsByName);
 149      streamWriteUInt16(eventCount);
 150  
 151      for name, class in pairs(self.eventsByName) do
 152          eventId             = rawget(class, "eventId");
 153          streamWriteString(name);
 154          streamWriteUInt16(eventId);
 155      end;
 156  end;
 157  
 158  

EventIds:readResyncEventIds()

Counterpart of above function, reads what EventIds:writeResyncEventIds() has written to the stream.

 162  function EventIds:readResyncEventIds()
 163      local eventCount            = streamReadUInt16();
 164      
 165      local className, classId;
 166      for i=1, eventCount, 1 do
 167          className                   = streamReadString();
 168          classId                     = streamReadUInt16();
 169  
 170          -- register these two
 171          local class                 = self.eventsByName[className];
 172          
 173          if class == nil then
 174              print("Error while synchronizing event ids: Event '" .. tostring(className) .. "' exists on the server, but not on this client");
 175          else
 176              self:assignEventId(class, classId);
 177  
 178              if g_debugNetworking then
 179                  print("Event '" .. tostring(className) .. "' has id " .. classId);
 180              end;
 181          end;
 182      end;
 183  end;
 184  
 185  local lastId = 0;
 186  local nextId = function()
 187      lastId = lastId + 1;
 188      return lastId;
 189  end;
 190  
 191  VanillaEventIds                                 = {};
 192  
 193  VanillaEventIds.EventUpdateTime                 = nextId();
 194  VanillaEventIds.EventSetAnimatedPart            = nextId();
 195  VanillaEventIds.EventSetMovingPartPosition      = nextId();
 196  VanillaEventIds.EventSetRopeWinchRotation       = nextId();
 197  VanillaEventIds.EventSetIsRopeTensed            = nextId();
 198  VanillaEventIds.EventSetSnowGroomerPosition     = nextId();
 199  VanillaEventIds.EventSetSnowGroomerLocked       = nextId();
 200  VanillaEventIds.EventSetSnowGroomerFlaps        = nextId();
 201  VanillaEventIds.EventSetSnowGroomerRotation     = nextId();
 202  VanillaEventIds.EventChatMessage                = nextId();
 203  VanillaEventIds.EventSetCannonTurnedOn          = nextId();
 204  VanillaEventIds.EventSetCannonGroupId           = nextId();
 205  VanillaEventIds.EventSetCannonRotation          = nextId();
 206  VanillaEventIds.EventSetLightState              = nextId();
 207  VanillaEventIds.EventSetLightRotation           = nextId();
 208  VanillaEventIds.EventSetCustomLight             = nextId();
 209  VanillaEventIds.EventRequestEnterVehicleSeat    = nextId();
 210  VanillaEventIds.EventRequestLeaveVehicleSeat    = nextId();
 211  VanillaEventIds.EventSetVehicleSeatUser         = nextId();
 212  VanillaEventIds.EventRequestSwitchVehicle       = nextId();
 213  VanillaEventIds.EventLeaveVehicle               = nextId();
 214  VanillaEventIds.EventSetEntityCurrentUser       = nextId();
 215  VanillaEventIds.EventSetPlayerNameAndColor      = nextId();
 216  VanillaEventIds.EventSetPlayerCharacterColor    = nextId();
 217  VanillaEventIds.EventSnowBallThrow              = nextId();
 218  VanillaEventIds.EventSetRopeWinchConnection     = nextId();
 219  VanillaEventIds.EventPlaySingleSound            = nextId();
 220  VanillaEventIds.EventRefuelVehicle              = nextId();
 221  VanillaEventIds.EventVehicleSetColorValue       = nextId();
 222  VanillaEventIds.EventAttachVehicle              = nextId();
 223  VanillaEventIds.EventDetachVehicle              = nextId();
 224  VanillaEventIds.EventVehicleSetMotorOn          = nextId();
 225  VanillaEventIds.EventVehicleCruiseControlEnable = nextId();
 226  
 227  VanillaEventIds.EventGroomTriangle              = nextId();
 228  VanillaEventIds.EventPlowSnow                   = nextId();
 229  VanillaEventIds.EventDisplaceSnow               = nextId();
 230  VanillaEventIds.EventAddSlopeUsage              = nextId();
 231  VanillaEventIds.EventGroomSlope                 = nextId();
 232  VanillaEventIds.EventAddSnowCircular            = nextId();
 233  VanillaEventIds.EventSetHeightCircular          = nextId();
 234  
 235  VanillaEventIds.EventRequestWeatherForecast     = nextId();
 236  VanillaEventIds.EventSendWeatherForecast        = nextId();
 237  VanillaEventIds.EventUpdateSnow                 = nextId();
 238  VanillaEventIds.EventSetWeather                 = nextId();
 239  
 240  VanillaEventIds.EventRefreshDigitalSignage              = nextId();
 241  VanillaEventIds.EventRefreshDigitalSignageScrollText    = nextId();
 242  
 243  -- ingame objects (identified via savegame key)
 244  VanillaEventIds.EventDoorController             = nextId();
 245  VanillaEventIds.EventToggleObject               = nextId();
 246  VanillaEventIds.EventTouchLightControl          = nextId();
 247  
 248  VanillaEventIds.RWEventTriggerGlobalSound       = nextId();
 249  VanillaEventIds.RWEventPlaySignalSound          = nextId();
 250  VanillaEventIds.RWEventStopSignalSound          = nextId();
 251  VanillaEventIds.RWEventPlayAnnouncement         = nextId();
 252  VanillaEventIds.RWEventStopAnnouncement         = nextId();
 253  VanillaEventIds.RWEventStartMoving              = nextId();
 254  
 255  VanillaEventIds.RWEventTriggerAlarm             = nextId();
 256  VanillaEventIds.RWEventTriggerButtonCallback    = nextId();
 257  VanillaEventIds.RWEventTriggerSwitchCallback    = nextId();
 258  VanillaEventIds.RWEventQuitAlarms               = nextId();
 259  VanillaEventIds.RWEventSetTurnout               = nextId();
 260  VanillaEventIds.RWEventSetMovingPart            = nextId();
 261  VanillaEventIds.RWEventSetCarrierMovingPart     = nextId();
 262  VanillaEventIds.RWEventTouchScreenPressed       = nextId();
 263  VanillaEventIds.EventConnectHMISetPage          = nextId();
 264  VanillaEventIds.EventConnectHMISetShutdownPage  = nextId();
 265  VanillaEventIds.EventConnectHMICallSubpageScreen= nextId();
 266  VanillaEventIds.EventConnectHMIButtonPressed    = nextId();
 267  VanillaEventIds.RWEventSetIsOwned               = nextId();
 268  VanillaEventIds.RWEventResyncRopeway            = nextId();
 269  VanillaEventIds.RWEventRequestSetAccessGatesOpen= nextId();

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.