stom66

Tabletop Simulator: Check for Object Dropped on top

Mar 25th, 2025 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. local isSpaceshipOnTop = false
  2.  
  3. function onObjectDrop(colorName, object)
  4.  
  5.     --use the objects description field to store the guid, helps during dev when guid changes:
  6.     --local spaceshipGuid = self.getDescription()
  7.    
  8.     -- hard coded guid:
  9.     local spaceshipGuid = "aaaaaa"
  10.    
  11.     local objects = Physics.cast({
  12.         origin    = self.getPosition(),
  13.         direction = vector(0, 10, 0),
  14.         type      = 1,
  15.         debug     = true
  16.     })
  17.  
  18.     isSpaceshipOnTop = false
  19.     for _, obj in ipairs(objects) do
  20.         if obj.hit_object.guid == spaceshipGuid then
  21.             isSpaceshipOnTop = true
  22.         end
  23.     end
  24. end
  25.  
  26. -- test function to periodically check if the spacehip is on top of the object, runs every 2 seconds
  27. function DoThing()
  28.     if isSpaceshipOnTop then
  29.         print("Spaceship is on top")
  30.     else
  31.         print("No Spaceship found")
  32.     end
  33. end
  34. Wait.time(DoThing, 2, -1)
Advertisement
Add Comment
Please, Sign In to add comment