Code Select
~SLC: YES I'M A PIG!
~SLC: LET EVERYONE KNOW IT!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: Doom_Kill3R on Dec 14, 2015, 09:18 AMSo what is the advantage of this over the default functions?a couple of features have been added to textdraws
XTextdraw
.ID //ID of xtxd instance
.text //The text to be displayed
.pos //The array containing x,y coord of txd
.col //The hex color of txd.
.obj //The actual textdraw instance
.players //An array containing players to which an instance of xtextdraw is being visible
.ShowForAll()
.ShowForPlayer(player)
.HideFromAll()
.HideFromPlayer(player)
.SetRelativeForAll(boolean)
.Delete()
CreateXTextdraw(text,x,y,colour)
FindXTextdraw(id)
CreateXTextdraw("momo",400,500,0xFFFFFFFF);
local hi = FindXTextdraw(0);
hi.pos[1]-=10;
hi.col=0xFF3445FF;
class XTxd
{
text = null;
ID = null;
pos = null;
col = null;
obj = null;
players = null;
isvta = false;
isrfa = false;
//static for these
count = [0];
timer = [null];
objs = [];
constructor(str,x,y,colr) {
count[0]++;
if(pos==null)
{
pos = [0,0];
players = [];
}
text = str;
pos = [x,y];
col = colr;
obj = ::CreateTextdraw(str,x,y,colr);
local did=false;
for(local i=0;i<XTxd.objs.len();i++)
{
local dat = XTxd.objs[i];
if(dat==null)
{ XTxd.objs[i] = this; did=true; ID = i; break; }
}
if(did!=true)
{
XTxd.objs.push(this);
ID = XTxd.objs.len()-1;
}
if(count[0] == 1)
{
timer[0] = ::NewTimer("ref",1000,0);
}
}
static function refresh()
{
for(local i=0;i<objs.len();i++)
{
local o = objs[i];
if(o!=null)
{
o.obj.Delete();
o.obj = ::CreateTextdraw(o.text,o.pos[0],o.pos[1],o.col);
o.obj.SetRelativeForAll(o.isrfa);
if(o.isvta==true) o.obj.ShowForAll();
else if(o.players.len()>0)
{
foreach (plr in o.players)
{
o.obj.ShowForPlayer(plr);
}
}
}
}
}
function ShowForPlayer(player)
{
players.push(player);
}
function ShowForAll()
{
isvta = true;
}
function HideFromPlayer(player)
{
if(players.find(player)!=null)
{
players.remove(players.find(player));
}
}
function HideFromAll()
{
isvta = false;
}
function SetRelativeForAll(val)
{
isrfa = val;
}
function Delete()
{
obj.Delete();
objs[ID] = null;
--count[0];
}
}
function CreateXTextdraw(str,x,y,col)
{
return XTxd(str,x,y,col);
}
function FindXTextdraw(id)
{
for(local i=0;i<XTxd.objs.len();i++)
{
if(XTxd.objs[i]!=null && id == XTxd.objs[i].ID) return XTxd.objs[i];
}
return null;
}
function ref()
{
XTxd.refresh();
}
[/spoiler]
function onScriptLoad()
{
seterrorhandler( errorHandling );
}
function errorHandling( obj )
{
local callingStack = getstackinfos( 2 );
local funcName = callingStack.func;
local origin = callingStack.src;
local lineNo = callingStack.line;
local locals = "";
foreach( index, value in callingStack.locals )
{
if( index != "this" )
locals = locals + "\t[" + index + "]: " + value + "\n";
}
EchoMessage( "Error occurring in " + origin + ": " + lineNo + ", function: " + funcName + "." );
EchoMessage( ">> " + obj + "\n" );
EchoMessage( locals );
}
Note: seterrorhandler is built-in function. Make sure the EchoMessage function is defined in your script.
Quote from: Doom_Killer on Aug 19, 2015, 11:23 AMSince it is 'custom' object it is going to be downloaded first before creating it for player, then it doesn't matter if its xml or CreateObject since the object is already at your PC.
function onPlayerExitVehicle(player,vehicle)
{
if(vehicle.Locked==true) { vehicle.Locked = false; player.Vehicle = vehicle; vehicle.Locked = true; }
}
Its untested by the way.Quote from: Thijn on Jul 18, 2015, 11:38 AMDo you actually read replies before posting?Sorry, removed it.