Objects/CarrierTrigger.lua

As soon as any object or player enters a carrier trigger, it will be linked to the carrier trigger, and it will move along its new parent object. You can use this feature e.g. to put packages onto the trunk of a car, or to move the player accordingly when he enters a ropeway carrier.

Note that CarrierTrigger does not require instancing as it completely relies on static functions

  27  CarrierTrigger                      = CarrierTrigger or {};
  28  

CarrierTrigger.onCreate(id, ignorePlayer, includeVehicles)

Call this function from your object's OnCreateLuaScript component.

  • id (transform id): id of the trigger. We therefore recommend to create the OnCreateLuaScript component right on the trigger.
  • ignorePlayer (bool): if true, the player will not be influenced by this trigger. Set to true for vehicles and false for ropeways or elevators.
  • includeVehicles (bool): if true, vehicles will also be influenced by this trigger. Set to false for vehicles and true for ropeways or elevators.
  35  function CarrierTrigger.onCreate(id, ignorePlayer, includeVehicles)
  36      CarrierTrigger.newTrigger(id, ignorePlayer, includeVehicles);
  37  end;

CarrierTrigger.newTrigger(id, ignorePlayer, includeVehicles)

CarrierTrigger.onCreate will be internally forwarded to this function to allow for later changes. Therefore, please do not call this function from your mod.

  40  function CarrierTrigger.newTrigger(id, ignorePlayer, includeVehicles)
  41      -- adds a carrier trigger to this object id
  42      Trigger.addTrigger(id,
  43          function(otherId)
  44              if g_scenario.player ~= nil and not CarrierTrigger.isOwnRigidBodyPart(id, otherId) then
  45                  g_scenario.player:setObjectParent(otherId, id, ignorePlayer, includeVehicles);
  46              end;
  47          end,
  48          function(otherId)
  49              if g_scenario.player ~= nil and not CarrierTrigger.isOwnRigidBodyPart(id, otherId) then
  50                  g_scenario.player:setObjectParent(otherId, 0, ignorePlayer, includeVehicles);
  51              end;
  52          end,
  53          false,  -- colliders and rigid bodies
  54          true
  55      );
  56  
  57      -- do not destroy objects inside here upon deletion
  58      addDestroyListener(id, CarrierTrigger.onDestroy);
  59  
  60      -- note that we do not need any updateable/object/etc because we do not actually create a lua object
  61      -- (we only add a C# component that will be destroyed automatically)
  62  end;

CarrierTrigger.onDestroy(id)

Called by addDestroyListener upon destroyal of the trigger. The trigger will then unparent its children to avoid sweeping the child objects to their death as well. (E.g. if a player is in a ropeway carrier, we do not want the player to get destroyed when he deletes the ropeway.)

  66  function CarrierTrigger.onDestroy(id)
  67      -- save the children
  68      for i=getNumOfChildren(id)-1, 0, -1 do
  69          setParent(getChildAt(id, i), 0);
  70      end;
  71  end;

CarrierTrigger.isOwnRigidBodyPart(id, otherId)

Avoids that parts from the carrier trigger's own rigid body might get influenced by the carrier trigger (e.g. if a car door opens into the trigger, it shall not be linked to the carrier trigger).

  75  function CarrierTrigger.isOwnRigidBodyPart(id, otherId)
  76      local rigidbodyId               = Rigidbody.getFromCollider(id);
  77      if rigidbodyId == 0 then
  78          return false;
  79      end;
  80  
  81      return isChildOf(otherId, id);
  82  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.