About text draw

Started by MacTavish, Dec 22, 2014, 12:11 AM

Previous topic - Next topic

MacTavish

How to erase a text draw and recreate it on move

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

.

Can you please be more specific? I have a feeling of what you're trying to achieve but I don't see it's purpose. Which is why I'm asking you to be more specific in case I misunderstood your intentions.
.

MacTavish

i added Fps textdraw in my server but Fps just stuck on 24.77 not showing any other value. so i want it to auto refresh

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

.

I remember doing something similar to this for someone else in the old forum:
local g_FPS = [];

function DrawFPS()
{
foreach (val in g_FPS)
{
if (val.Text != null) val.Text.Delete();
val.Text = CreateTextdraw("FPS: " + val.Player.FPS, 0, 0, 0xFFB0B0B0);
if (val.Text != null) val.Text.ShowForPlayer(val.Player);
}
}

function onServerStart()
{
NewTimer("DrawFPS", 5000, 0);
}

function onPlayerJoin(i_player)
{
g_FPS.push({Player = i_player, Text = null});
}

function onPlayerPart(i_player, reason)
{
for (local i = g_FPS.len()-1; i >= 0; i--)
{
if (g_FPS[i].Player.ID == i_player.ID)
{
if (g_FPS[i].Text != null) g_FPS[i].Text.Delete();
g_FPS.remove(i);
break;
}
}
}

Quote from: S.L.CNOTE: The FPS value updates once every 10 seconds internaly, so there's no reason to draw something every second. I've set the draw function to run every 5 seconds instead of 10 to not risk printing an outdated value because the start point of our timer doesn't match with the internal timer on the FPS update function. This should make the draw function have on foot in the previous time lapse and another in the next time lapse but never have both feet in the same time lapse (so to speak). Similar to rounding floating point numbers if you've ever encountered such needs.



As for your question you cannot change text but you can delete it and re-create it again.
.

MacTavish

#4
thanks but where the i_player came from

does it work if i use player instead i_player

and can i use the same way to update district name in text draw

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

.

Quote from: RATHORE on Dec 22, 2014, 12:34 AMthanks but where the i_player came from

does it work if i use player instead i_player

i_player it's just a variable name and nothing more. I chose to prefix my variables in order to know their types. Since Squirrel is a dynamically typed language (meaning that one variable can hold any data type) it makes it easier to know what data type is in that variable. i_player and the i_ stands for (i)nstance because it holds a player instance and I could have named that however I wanted. The first variable is g_FPS and the g_ stands for (g)lobal because it's a global variable (also notice it's uppercase).

Quote from: RATHORE on Dec 22, 2014, 12:34 AMand can i use the same way to update district name in text draw

Yeah sure.
.

MacTavish

thank i will try it and report back here soon :)

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

MacTavish

Its giving me errors in console on every event where it is added like Spawn, Join etc...

Can you make it very very simple without adding g_FBS and i_player

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Thijn

Post your edited code. The code S.L.C. posted works fine.

MacTavish

#9
Well i made an external .nut file for S.L.C draw system the fps appeared but other systems got bugged


On just Simply copy paste
my functions ( player < because in onPlayerJoin all other stuff use player...   i_player < for fps system
function onPlayerJoin( player, i_player )
{
g_FPS.push({Player = i_player, Text = null});
}


i did all stuff like this but still this error but this time Fps not appeared



Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Thijn

Its pretty easy to adapt it for your script if you actually knew how to script.

Add this at the top of your script (Outside any function):
local g_FPS = [];

In your Functions.nut file (Which by the name looks to be holding your misc functions) add this:
function DrawFPS()
{
 foreach (val in g_FPS)
 {
  if (val.Text != null) val.Text.Delete();
  val.Text = CreateTextdraw("FPS: " + val.Player.FPS, 0, 0, 0xFFB0B0B0);
  if (val.Text != null) val.Text.ShowForPlayer(val.Player);
 }
}

Then, where ever your onServerStart function is defined (If you don't have it, add it) add:
NewTimer("DrawFPS", 5000, 0);

In your onPlayerJoin function add
g_FPS.push({Player = player, Text = null});

In your onPlayerPart function add
for (local i = g_FPS.len()-1; i >= 0; i--)
 {
  if (g_FPS[i].Player.ID == player.ID)
  {
   if (g_FPS[i].Text != null) g_FPS[i].Text.Delete();
   g_FPS.remove(i);
   break;
  }
 }

MacTavish

Well Thijn Sir Thanks It Worked Now

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P