Python1320

Python1320

Feb 21st, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. require("oosocks")
  2.  
  3. local Calltypes = {
  4.     [SCKCALL_CONNECT] = "Connect", -- SCKCALL_CONNECT
  5.     [SCKCALL_REC_SIZE] = "Rec Size", -- SCKCALL_REC_SIZE
  6.     [SCKCALL_REC_LINE] = "Rec Line", -- SCKCALL_REC_LINE
  7.     [SCKCALL_SEND] = "Send", -- SCKCALL_SEND
  8.     [SCKCALL_BIND] = "Bind", -- SCKCALL_BIND
  9.     [SCKCALL_ACCEPT] = "Accept", -- SCKCALL_ACCEPT
  10.     [SCKCALL_LISTEN] = "Listen", -- SCKCALL_LISTEN 
  11.     [SCKCALL_REC_DATAGRAM] = "Datagram", -- SCKCALL_REC_DATAGRAM
  12. }
  13.  
  14. local Errtypes = {
  15.     [SCKERR_OK] = "Ok", -- SCKERR_OK
  16.     [SCKERR_BAD] = "Bad", -- SCKERR_BAD
  17.     [SCKERR_CONNECTION_RESET] = "Con Rest", -- SCKERR_CONNECTION_RESET
  18.     [SCKERR_NOT_CONNECTED] = "Not Con", -- SCKERR_NOT_CONNECTED
  19.     [SCKERR_TIMED_OUT] = "Timed Out", -- SCKERR_TIMED_OUT
  20. }
  21. --deep magic
  22. local function convert(x)
  23.     local sign = 1
  24.     local mantissa = string.byte(x, 3) % 128
  25.     for i = 2, 1, -1 do mantissa = mantissa * 256 + string.byte(x, i) end
  26.     if string.byte(x, 4) > 127 then sign = -1 end
  27.     local exponent = (string.byte(x, 4) % 128) * 2 +
  28.                 math.floor(string.byte(x, 3) / 128)
  29.     if exponent == 0 then return 0 end
  30.     mantissa = (math.ldexp(mantissa, -23) + 1) * sign
  31.     return math.ldexp(mantissa, exponent - 127)
  32.  end
  33.  
  34.  
  35.  if connection then connection:Close() end
  36.  
  37. connection = OOSock(IPPROTO_UDP);
  38.  
  39. --local e1=Entity ( 373)
  40. --local e2=Entity ( 207)
  41. --local ox,oy,oz=0,0,0
  42. --local x,y,z=0,0,0
  43. connection:SetCallback(function(socket, callType, callId, err, binread, peer, peerPort)  
  44.     if(callType == SCKCALL_BIND && err == SCKERR_OK) then
  45.         print("Bound.");
  46.         //connection:Send("rofl", "127.0.0.1", 37777);
  47.         connection:ReceiveDatagram();
  48.     end
  49.      
  50.     if(callType == SCKCALL_SEND && err == SCKERR_OK) then
  51.         print("Sent.");
  52.     end
  53.      
  54.     if(callType == SCKCALL_REC_DATAGRAM && err == SCKERR_OK) then
  55.         local len= binread:GetSize()
  56.        -- print("Got packet len="..len.."  from  " .. peer .. ":" .. tostring(peerPort));
  57.        
  58.         if len == 12 then
  59.              x = binread:ReadFloat()
  60.              y = binread:ReadFloat()
  61.              z = binread:ReadFloat()
  62.  
  63.         else
  64.             print"Data unknown, discarding"
  65.         end
  66.         socket:ReceiveDatagram();
  67.     end
  68.      
  69.     if(err != SCKERR_OK) then
  70.         socket:Close()
  71.     end
  72. end);
  73.  
  74. local newang = Angle(0,0,0)
  75. hook.Add('Think',1,function()
  76.     ox = math.Approach(ox,x,math.abs(ox-x)^2)
  77.     oy = math.Approach(oy,y,math.abs(oy-y)^2)
  78.     oz = math.Approach(oz,z,math.abs(oz-z)^2)
  79.  
  80.  
  81.     -- MAHGIC SHIT HERE
  82.  
  83.  
  84.     /*local sensvec= Vector(ox,0,0)
  85.     e1:SetPos(e2:GetPos()+sensvec*10)
  86.     local ang = sensvec:Angle()
  87.     ang.p=ang.p+90
  88.     e1:SetAngles(ang)
  89. */
  90. --  Ply'Pyth':SetEyeAngles(ang)
  91.  
  92. end)
  93. connection:SetBinaryMode( true )
  94. -- an IP of "" binds to all interfaces.
  95. connection:Bind("", 12345);
Advertisement
Add Comment
Please, Sign In to add comment