ChainsBoy

[M2-Online] Drawing label in world

Mar 12th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. addEventHandler( "onClientFrameRender",
  2.     function (post) {
  3.         if (post) {
  4.  
  5.             // Text to display
  6.             local label_text = "Hello world! I'm a neat little label :)";
  7.             // Where in the world to display this text
  8.             local label_pos = [733.508911, 884.242554, -11.00];
  9.             // Set the font
  10.             local font = "arial";
  11.             // Set the text size
  12.             local scale = 1.0;
  13.  
  14.             /**
  15.              * What color it should be
  16.              *Color layout, might not be 100% right, if I remember correctly the Red Green and Blue color orders might be in wrong order
  17.              *0xFF << First two codes set the alpha channel
  18.              *0xFF 33 << Set the red color
  19.              *0xFF33 FF << Set the green color
  20.              *0xFF33FF 99 << And finally set the blue color
  21.              */
  22.             local color = 0xFF33FF99;
  23.  
  24.  
  25.             // Get the screen position of a point from the game world
  26.             local screen = getScreenFromWorld(label_pos[0],label_pos[1],label_pos[2]);
  27.             // The the player position
  28.             local position = getPlayerPosition(getLocalPlayer());
  29.             // Get the distance between the player and the label position
  30.             local render_distance = getDistanceBetweenPoints3D(label_pos[0],label_pos[1],label_pos[2], position[0], position[1], position[2]);
  31.  
  32.             // How near does the player have to be before label is displayed
  33.             if (render_distance <= 15.0) {  
  34.                 // If the label is infront of the player (if I remember correctly)
  35.                 if (screen[2] < 1.0) {
  36.                     // Draw the text label, parameters: string text, float x, float y, int color, bool shadow, string font [, float scale = 1.0]
  37.                     dxDrawText(label_text, screen[0], screen[1], color, true, font, scale);
  38.                 }
  39.             }
  40.  
  41.         }
  42.     }
  43. );
Advertisement
Add Comment
Please, Sign In to add comment