Vice City Multiplayer

VC:MP 0.4 (Beta) => Script Discussion => Script Releases => Topic started by: Flockshot on September 27, 2014, 10:12:48 pm

Title: Position System
Post by: Flockshot on September 27, 2014, 10:12:48 pm
Hello Guys I present u with m Positioning System.

So what basically it do is that it shows you ur position + angle + district name at will.

Using F3 Key you can enable/disable it.

Images
(http://i1348.photobucket.com/albums/p730/msomaan/Screenshot9_zps9e254743.png) (http://s1348.photobucket.com/user/msomaan/media/Screenshot9_zps9e254743.png.html)
(http://i1348.photobucket.com/albums/p730/msomaan/Screenshot8_zps74214bee.png) (http://s1348.photobucket.com/user/msomaan/media/Screenshot8_zps74214bee.png.html)


Global Variable
Code: [Select]
local posofplr = []; //Place it in any file but out of any function because we want it to be a global variable not local.

OnServerStart
Code: [Select]
xyz <- BindKey(true,0x72,0,0); //we will bind key for it to make it easy for player, F3.
showpos <- array( GetMaxPlayers(), false );
NewTimer("PlayerPos", 300, 0); //starts the timer

OnPlayerJoin
Code: [Select]
posofplr.push({Player = player, x = null, y = null, z = null, angle = null, district=null}); //We will push the player in the array we created.

OnKeyDown
Code: [Select]
function onKeyDown(player, bindid)
{
   if(bindid == xyz ) // xyz because we named the binding to this name
   {
      if(!showpos[player.ID]) //player will have it false when it enters the game
      {
         showpos[player.ID] = true; //Means player has the position system on
         MessagePlayer("Showing Coordinates",player);
      }
      else
      {
         showpos[player.ID]= false; //If the positioning system was on and the key was press again it will disable
         
      }
     
   }
}

Timer
Code: [Select]
function PlayerPos()
{
foreach (val in posofplr)
{
local plr = val.Player;

if(plr)
{

if(showpos[plr.ID])
{
if (val.x != null) val.x.Delete();
if (val.y != null) val.y.Delete();
if (val.z != null) val.z.Delete();
if (val.angle != null) val.angle.Delete();
if (val.district != null) val.district.Delete();

val.x = CreateTextdraw("X: " + val.Player.Pos.x, 0, 300, 0xFFB0B0B0);
val.y = CreateTextdraw("Y: " + val.Player.Pos.y, 0, 315, 0xFFB0B0B0);
val.z = CreateTextdraw("Z: " + val.Player.Pos.z, 0, 330, 0xFFB0B0B0);
val.angle = CreateTextdraw("Angle: " + val.Player.Angle, 0, 345, 0xFFB0B0B0);
val.district = CreateTextdraw("District: " + GetDistrictName( val.Player.Pos.x, val.Player.Pos.y ), 0, 360, 0xFFB0B0B0);

if (val.x != null) val.x.ShowForPlayer(val.Player);
if (val.y != null) val.y.ShowForPlayer(val.Player);
if (val.z != null) val.z.ShowForPlayer(val.Player);
if (val.angle != null) val.angle.ShowForPlayer(val.Player);
if (val.district != null) val.district.ShowForPlayer(val.Player);
}
}
else
{
if (val.x != null){ val.x.Delete();
val.x = null;}

if (val.y != null){ val.y.Delete();
val.y = null;}

if (val.z != null){ val.z.Delete();
val.z = null;}

if (val.angle != null){ val.angle.Delete();
val.angle = null;}

if (val.district != null){ val.district.Delete();
val.district = null;}
}
}
}

This is it for the Positioning system

Example Script: https://www.mediafire.com/?a6k18yne5m35ket (https://www.mediafire.com/?a6k18yne5m35ket)

Special Thanks to : S.L.C for teaching me how to use the .push thingy.
Title: Re: Position System
Post by: Mariu22S on September 27, 2014, 10:33:52 pm
Very nice :)
Title: Re: Position System
Post by: sseebbyy on September 27, 2014, 11:54:52 pm
It looks good, but isn't it overlat on chat ? :/
Title: Re: Position System
Post by: [AoD]NC on September 28, 2014, 02:00:12 am
Mana :D.
Title: Re: Position System
Post by: Flockshot on September 28, 2014, 08:07:23 am
It looks good, but isn't it overlat on chat ? :/
Yeah i know so i changed it position to much lower

now its fine
(http://i1348.photobucket.com/albums/p730/msomaan/Screenshot10_zpsce5e89dd.png) (http://s1348.photobucket.com/user/msomaan/media/Screenshot10_zpsce5e89dd.png.html)

Mana :D.
Thats just another thing.
Title: Re: Position System
Post by: sseebbyy on September 28, 2014, 11:06:38 am
Much better.  :D
Title: Re: Position System
Post by: heekz.shadow on September 28, 2014, 12:49:35 pm
I don't find it any clean that you're creating a new timer after a timer ends.

You should run an infinite timer, and please, not 100 miliseconds, that'll just lag a server with a decent playercount.
Title: Re: Position System
Post by: thijn on September 28, 2014, 01:04:27 pm
Code: [Select]
if(showpos[player.ID]==false)
Should be
Code: [Select]
if(!showpos[player.ID])

Same with true, you don't need that there.
Also, there's no point in checking if it's true in an else if if the previous statement was false. It's either true or false.
Code: [Select]
if(!showpos[player.ID]) //player will have it false when it enters the game
{
}
else
{
}

And obviously what heekzs said, the timers are bad. Really bad.
Title: Re: Position System
Post by: Flockshot on September 28, 2014, 03:14:28 pm
I don't find it any clean that you're creating a new timer after a timer ends.

You should run an infinite timer, and please, not 100 miliseconds, that'll just lag a server with a decent playercount.

Code: [Select]
if(showpos[player.ID]==false)
Should be
Code: [Select]
if(!showpos[player.ID])

Same with true, you don't need that there.
Also, there's no point in checking if it's true in an else if if the previous statement was false. It's either true or false.
Code: [Select]
if(!showpos[player.ID]) //player will have it false when it enters the game
{
}
else
{
}

And obviously what heekzs said, the timers are bad. Really bad.

Updated the code.
Made the timer infinite and also changed the if and else .
Title: Re: Position System
Post by: thijn on September 28, 2014, 05:04:56 pm
Ouch, that will spawn an infinite timer every time a player presses F3 two times.
It's better if you use one, infinite timer that will loop through all the players and update the text if they have the system enabled. That way you'll only end up with one timer overall, instead of a million after your server has run for an hour or two.
Title: Re: Position System
Post by: Flockshot on September 28, 2014, 06:16:07 pm
Ouch, that will spawn an infinite timer every time a player presses F3 two times.
It's better if you use one, infinite timer that will loop through all the players and update the text if they have the system enabled. That way you'll only end up with one timer overall, instead of a million after your server has run for an hour or two.
In that case i will just make a infinite timer on server start.
Well updated the code