Objects/FuelStationTrigger.lua

FuelStationTrigger is a static counterpart of FuelTank, which is required to refuel vehicles.

  24  FuelStationTrigger                  = FuelStationTrigger or {};

FuelStationTrigger.onCreate(id)

Initializes a new FuelStationTrigger. We do not create any instance, which makes it a rather convenient and performance-saving object.

This will usually be called by the object's onCreate Component.

  29  function FuelStationTrigger.onCreate(id)
  30      Trigger.addTrigger(id,
  31          function(otherId) FuelStationTrigger.setMayRefuel(id, otherId, true); end,
  32          function(otherId) FuelStationTrigger.setMayRefuel(id, otherId, false); end,
  33          -- react to colliders only
  34          true,
  35          false
  36      );
  37  
  38      -- no lua instance created => no need to care about destroy listeners
  39  end;

FuelStationTrigger.setMayRefuel(triggerId, otherId, state)

Checks whether otherId (int) actually is a vehicle, and if yes, calls FuelTank:setIsFuelStationInRange using the specified state (bool).

  42  function FuelStationTrigger.setMayRefuel(triggerId, otherId, state)
  43      local rigidBodyId               = Rigidbody.getFromCollider(otherId);
  44      local vehicle                   = VehicleManager:getVehicleById(rigidBodyId or 0);
  45  
  46      if vehicle ~= nil and vehicle.setIsFuelStationInRange ~= nil then
  47          vehicle:setIsFuelStationInRange(triggerId, otherId, state or false);
  48      end;
  49  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.