Advertisement
geldoronie

Get Lua Info by C++ Leadwerks

Jan 19th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. //-----------------------------------------------------------------------------
  2. // Purpose:
  3. //-----------------------------------------------------------------------------
  4. void PickupController::HandleInteraction()
  5. {
  6. #ifndef LEADWERKS_5
  7.     // If we are holding something, drop whatever we are holding.
  8.     if (HoldingObject())
  9.     {
  10.         if (m_pCarryEntity->GetAABB().IntersectsPoint(GetEntity()->GetPosition(), 0.2f))
  11.             return;
  12.  
  13.         ForceDropObject();
  14.         return;
  15.     }
  16.  
  17.     auto pickinfo = PickInfo();
  18.     //if (VR::Enabled()) entity->SetQuaternion(VR::headsetrotation); // HACK: Camera's quat doesn't update with the hmd.
  19.     auto p0 = GetEntity()->GetPosition(true);
  20.     auto p1 = Transform::Point(0, 0, m_flPickDistance, entity, nullptr);
  21.     bool test = entity->GetWorld()->Pick(p0, p1, pickinfo, 0, true, COLLISION_DEBRIS);
  22.     if (!test)
  23.     {
  24.         EmitSoundScript("Use.Deny");
  25.         return;
  26.     }
  27.  
  28.  
  29. #ifdef DEBUG
  30.     m_pEntEndpoint->SetPosition(p1);
  31.     m_pEntEndpoint->Show();
  32. #endif
  33.  
  34.     // Use Test:
  35.     if (test)
  36.     {
  37. #ifdef DEBUG
  38.         m_pEntEndpoint->SetPosition(pickinfo.position);
  39.         m_pEntEndpoint->Show();
  40. #endif
  41.  
  42.         if (QueryObject(pickinfo.entity) == true)
  43.         {
  44.             PickupObject(pickinfo.entity);
  45.         }
  46.         else
  47.         {
  48.             // Disable interacting/use for now.
  49.             if (GetEntityKeyValue(pickinfo.entity, "classname") != "")
  50.             {
  51.                 auto actor = (BaseActor*)pickinfo.entity->GetActor();
  52.                 if (actor != NULL)
  53.                 {
  54.                     actor->Use(this);
  55.                 }
  56.                 else
  57.                 {
  58.                     pickinfo.entity->CallFunction("Use");
  59.                 }
  60.  
  61.                 //EmitSoundScript("Use.Success");
  62.             }
  63.             else
  64.             {
  65.                 if (pickinfo.entity->CallFunction("Use") == false)
  66.                 {
  67.                     EmitSoundScript("Use.Deny");
  68.                 }
  69.             }
  70.         }
  71.     }
  72. #else
  73.     // If we are holding something, drop whatever we are holding.
  74.     if (HoldingObject())
  75.     {
  76.         if (m_pCarryEntity->aabb.IntersectsPoint(GetEntity()->GetPosition(), 0.2f))
  77.             return;
  78.  
  79.         ForceDropObject();
  80.         return;
  81.     }
  82.  
  83.     auto pickinfo = PickInfo();
  84.     //if (VR::Enabled()) entity->SetQuaternion(VR::headsetrotation); // HACK: Camera's quat doesn't update with the hmd.
  85.     auto p0 = GetEntity()->GetPosition(true);
  86.     auto p1 = TransformPoint(0, 0, m_flPickDistance, GetEntity(), nullptr);
  87.  
  88. #ifdef DEBUG
  89.     m_pEntEndpoint->SetPosition(p1);
  90.     m_pEntEndpoint->Show();
  91. #endif
  92.  
  93.     // Use Test:
  94.     if (GetEntity()->GetWorld()->Pick(p0, p1, pickinfo, 0, true, COLLISION_DEBRIS))
  95.     {
  96. #ifdef DEBUG
  97.         m_pEntEndpoint->SetPosition(pickinfo.position);
  98.         m_pEntEndpoint->Show();
  99. #endif
  100.  
  101.         if (QueryObject(pickinfo.entity) == true)
  102.         {
  103.             PickupObject(pickinfo.entity);
  104.         }
  105.         else
  106.         {
  107.             // Disable interacting/use for now.
  108. #if 0
  109.             if (GetEntityKeyValue(pickinfo.entity, "classname") != "")
  110.             {
  111.                 auto actor = (BaseActor*)pickinfo.entity->GetActor();
  112.                 if (actor != NULL)
  113.                 {
  114.                     actor->Use(this);
  115.                 }
  116.                 else
  117.                 {
  118.                     pickinfo.entity->CallFunction("Use");
  119.                 }
  120.             }
  121.             else
  122.             {
  123.                 pickinfo.entity->CallFunction("Use");
  124.             }
  125. #endif
  126.         }
  127.     }
  128. #endif
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement