Advertisement
Guest User

XTextdraw

a guest
Dec 13th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.24 KB | None | 0 0
  1. class XTxd
  2. {
  3.     text = null;
  4.     ID = null;
  5.     pos = null;
  6.     col = null;
  7.     obj = null;
  8.     players = null;
  9.     isvta = false;
  10.     isrfa = false;
  11.  
  12.     //static for these
  13.     count = [0];
  14.     timer = [null];
  15.     objs = [];
  16.  
  17.     constructor(str,x,y,colr) {
  18.       count[0]++;
  19.       if(pos==null)
  20.       {
  21.         pos = [0,0];
  22.         players = [];
  23.       }
  24.       text = str;
  25.       pos = [x,y];
  26.       col = colr;
  27.       obj = ::CreateTextdraw(str,x,y,colr);
  28.  
  29.       local did=false;
  30.       for(local i=0;i<XTxd.objs.len();i++)
  31.       {
  32.         local dat = XTxd.objs[i];
  33.         if(dat==null)
  34.         { XTxd.objs[i] = this; did=true; ID = i; break; }
  35.       }
  36.       if(did!=true)
  37.       {
  38.         XTxd.objs.push(this);
  39.         ID = XTxd.objs.len()-1;
  40.       }
  41.  
  42.       if(count[0] == 1)
  43.       {
  44.         timer[0] = ::NewTimer("ref",1000,0);
  45.       }
  46.  
  47.     }
  48.  
  49.     static function refresh()
  50.     {
  51.       for(local i=0;i<objs.len();i++)
  52.       {
  53.         local o =   objs[i];
  54.         if(o!=null)
  55.         {
  56.             o.obj.Delete();
  57.             o.obj = ::CreateTextdraw(o.text,o.pos[0],o.pos[1],o.col);
  58.             o.obj.SetRelativeForAll(o.isrfa);
  59.             if(o.isvta==true) o.obj.ShowForAll();
  60.             else if(o.players.len()>0)
  61.             {
  62.               foreach (plr in o.players)
  63.                {
  64.                 o.obj.ShowForPlayer(plr);
  65.                }
  66.             }
  67.         }
  68.       }
  69.     }
  70.  
  71.     function ShowForPlayer(player)
  72.     {
  73.       players.push(player);
  74.     }
  75.     function ShowForAll()
  76.     {
  77.       isvta = true;
  78.     }
  79.     function HideFromPlayer(player)
  80.     {
  81.       if(players.find(player)!=null)
  82.       {
  83.         players.remove(players.find(player));
  84.       }
  85.     }
  86.     function HideFromAll()
  87.     {
  88.       isvta = false;
  89.     }
  90.     function SetRelativeForAll(val)
  91.     {
  92.       isrfa = val;
  93.     }
  94.     function Delete()
  95.     {
  96.       obj.Delete();
  97.       objs[ID] = null;
  98.       --count[0];
  99.     }
  100.  
  101. }
  102.  
  103. function CreateXTextdraw(str,x,y,col)
  104. {
  105.   return XTxd(str,x,y,col);
  106. }
  107. function FindXTextdraw(id)
  108. {
  109.   for(local i=0;i<XTxd.objs.len();i++)
  110.   {
  111.     if(XTxd.objs[i]!=null && id == XTxd.objs[i].ID) return XTxd.objs[i];
  112.   }
  113.   return null;
  114. }
  115.  
  116. function ref()
  117. {
  118.   XTxd.refresh();
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement