Advertisement
Guest User

Interaction detection

a guest
Jan 25th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. local objectList = {
  2.     ['2291']          = true,
  3.     ['2343']          = true,
  4.     ['2723']          = true,
  5.     ['2724']          = true,
  6.     ['2356']          = true,
  7.     ['1761']          = true,
  8.     ['1762']          = true,
  9.     ['2290']          = true,
  10.     ['2124']          = true,
  11.     ['1708']          = true,
  12.     ['1713']          = true,
  13.     ['1739']          = true,
  14.     ['2090']          = true,
  15.     ['2298']          = true,
  16.     ['1798']          = true  
  17. };
  18.  
  19. local showingBar = false;
  20.  
  21. function hideBar()
  22.     toggleInfoBar();
  23.     showingBar = false;
  24. end
  25.  
  26. function checkInteractableObjects( )
  27.     local x, y, z, lx, ly, lz, roll, fov = getCameraMatrix()
  28.     local fromX, fromY, fromZ = getElementPosition(getLocalPlayer())
  29.     local toX = fromX + (lx - x)*3
  30.     local toY = fromY + (ly - y)*3
  31.     local toZ = fromZ + (lz - z)*3
  32.     local hit, hitX, hitY, hitZ, hitlineElement, normalX, normalY, normalZ, material, lighting, piece, wmid, wmx, wmy, wmz, wmrx, wmry, wmrz   = processLineOfSight(fromX, fromY, fromZ+1, toX, toY, toZ, true, false, false, true, false, false, false, true, getLocalPlayer(), true)
  33.  
  34.     if hit then
  35.         if hitlineElement then
  36.             model = getElementModel( hitlineElement );
  37.         elseif wmid ~= false then
  38.             model = wmid;
  39.         end
  40.        
  41.         if not showingBar and objectList[tostring(model)] == true then
  42.              toggleInfoBar("Press 'B' to interact with this object!");
  43.              setTimer(hideBar, 5000, 1);
  44.             showingBar = true;
  45.         end
  46.     end
  47. end
  48.  
  49. addEventHandler("onClientHUDRender", getRootElement(), checkInteractableObjects);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement