Question about player's marker

Started by Kenneth Law, Nov 25, 2020, 04:45 AM

Previous topic - Next topic

Kenneth Law

How to make the marker of a specific player visible for just part of players? Note that NEITHER FOR NONE OF PLAYERS NOR FOR ALL PLAYERS. Something like player.RemoveMarker() or player.IsOnRadar = false can only hide the marker for all which is not what I want. I know changing their world helps but I want them to be in one world.
Also, I am not talking about the function SetShowOnlyTeamMarkers(true). Let's just talk about the situation that players are grouped into two teams which are separately A and B, and I want to make A visible for B while B invisible for A.

DizzasTeR


Inferno

If you are giving an example of 2 groups, then SetShowOnlyTeamMarkers(true) is the only function that can be helpful for you.
Viva la VU
VFS Developer
VCCNR Administrator

habi

Quote from: Kenneth Law on Nov 25, 2020, 04:45 AMHow to make the marker of a specific player visible for just part of players? Note that NEITHER FOR NONE OF PLAYERS NOR FOR ALL PLAYERS. Something like player.RemoveMarker() or player.IsOnRadar = false can only hide the marker for all which is not what I want. I know changing their world helps but I want them to be in one world.
Also, I am not talking about the function SetShowOnlyTeamMarkers(true). Let's just talk about the situation that players are grouped into two teams which are separately A and B, and I want to make A visible for B while B invisible for A.

See how he has nicely explained to us about it...

Spiller

This is not much of a solution but you can do something like this. (but at what cost?)

https://youtu.be/Gzskg2PrZT0

Code
SetShowOnRadar(false);
enum MARKER_CONFIG
{
RADIUS = 50, // Radius in which markers will be visible
UPDATE_TIME = 1000 // Markers are updated at this rate (ms)
};

PlayerIDs <- [];
MarkerData <- array(GetMaxPlayers(), null);

class MarkerClass
{
playerID = 0;
Marker = null;

Markers = null;
HasMarker = null;

constructor(pID)
{
this.playerID = pID;

Markers = [];
HasMarker = [];
}

function HasMarkerFor(pID)
{
if(this.HasMarker.find(pID) == null)
return false;

return true;
}

function CreateMarkerFor(pID)
{
local player = ::FindPlayer(this.playerID), target = ::FindPlayer(pID);
if(!player || !target) return 1;

local NewMarker = ::CreateMarker(player.UniqueWorld, target.Pos, 3, target.Colour, 0);
this.Markers.append(NewMarker);
this.HasMarker.append(pID);
}

function RemoveMarkerFor(pID)
{
local Position = this.HasMarker.find(pID);
if(Position == null) return 1;

::DestroyMarker(this.Markers[Position]);
this.Markers.remove(Position);
this.HasMarker.remove(Position);
}

function Destroy()
{
foreach(val in this.Markers)
::DestroyMarker(val);

this = null;
}
}

function MarkerHandler()
{
foreach(i, Entity in PlayerIDs)
{
local player = FindPlayer(Entity);
if(player)
{
foreach(Entity_ in PlayerIDs)
{
if(Entity_ == Entity)
continue;

if(CheckRadius(Entity, Entity_))
{
if(!MarkerData[Entity].HasMarkerFor(Entity_))
MarkerData[Entity].CreateMarkerFor(Entity_);
}
else
{
if(MarkerData[Entity].HasMarkerFor(Entity_))
MarkerData[Entity].RemoveMarkerFor(Entity_);
}
}

foreach(i, Marker in MarkerData[Entity].Markers)
{
DestroyMarker(Marker);

local target = FindPlayer(MarkerData[Entity].HasMarker[i]);
if(!target) return 1;

CreateMarker(player.UniqueWorld, target.Pos, 3, target.Colour, 0);
}
}
}
}
NewTimer("MarkerHandler", MARKER_CONFIG.UPDATE_TIME, 0);

function CheckRadius(Entity, Entity_)
{
local p1 = FindPlayer(Entity),
p2 = FindPlayer(Entity_);

if(p1 && p2)
{
if(!p1.IsSpawned || !p2.IsSpawned) return false;

if(sqrt(((p1.Pos.x - p2.Pos.x)*(p1.Pos.x - p2.Pos.x)) + ((p1.Pos.y - p2.Pos.y)*(p1.Pos.y - p2.Pos.y))) < MARKER_CONFIG.RADIUS)
return true;
}

return false;
}

onPlayerJoin
function onPlayerJoin( player )
{
PlayerIDs.append(player.ID);
MarkerData[player.ID] = MarkerClass(player.ID);
}

onPlayerPart
function onPlayerPart( player, reason )
{
PlayerIDs.remove(PlayerIDs.find(player.ID));
MarkerData[player.ID].Destroy();
}

Hastebin, if the formatting in above code appears messed up.

P.S. Didn't test much.

Kenneth Law

Quote from: Spiller on Nov 26, 2020, 11:15 AMThis is not much of a solution but you can do something like this. (but at what cost?)

https://youtu.be/Gzskg2PrZT0

Code
SetShowOnRadar(false);
enum MARKER_CONFIG
{
RADIUS = 50, // Radius in which markers will be visible
UPDATE_TIME = 1000 // Markers are updated at this rate (ms)
};

PlayerIDs <- [];
MarkerData <- array(GetMaxPlayers(), null);

class MarkerClass
{
playerID = 0;
Marker = null;

Markers = null;
HasMarker = null;

constructor(pID)
{
this.playerID = pID;

Markers = [];
HasMarker = [];
}

function HasMarkerFor(pID)
{
if(this.HasMarker.find(pID) == null)
return false;

return true;
}

function CreateMarkerFor(pID)
{
local player = ::FindPlayer(this.playerID), target = ::FindPlayer(pID);
if(!player || !target) return 1;

local NewMarker = ::CreateMarker(player.UniqueWorld, target.Pos, 3, target.Colour, 0);
this.Markers.append(NewMarker);
this.HasMarker.append(pID);
}

function RemoveMarkerFor(pID)
{
local Position = this.HasMarker.find(pID);
if(Position == null) return 1;

::DestroyMarker(this.Markers[Position]);
this.Markers.remove(Position);
this.HasMarker.remove(Position);
}

function Destroy()
{
foreach(val in this.Markers)
::DestroyMarker(val);

this = null;
}
}

function MarkerHandler()
{
foreach(i, Entity in PlayerIDs)
{
local player = FindPlayer(Entity);
if(player)
{
foreach(Entity_ in PlayerIDs)
{
if(Entity_ == Entity)
continue;

if(CheckRadius(Entity, Entity_))
{
if(!MarkerData[Entity].HasMarkerFor(Entity_))
MarkerData[Entity].CreateMarkerFor(Entity_);
}
else
{
if(MarkerData[Entity].HasMarkerFor(Entity_))
MarkerData[Entity].RemoveMarkerFor(Entity_);
}
}

foreach(i, Marker in MarkerData[Entity].Markers)
{
DestroyMarker(Marker);

local target = FindPlayer(MarkerData[Entity].HasMarker[i]);
if(!target) return 1;

CreateMarker(player.UniqueWorld, target.Pos, 3, target.Colour, 0);
}
}
}
}
NewTimer("MarkerHandler", MARKER_CONFIG.UPDATE_TIME, 0);

function CheckRadius(Entity, Entity_)
{
local p1 = FindPlayer(Entity),
p2 = FindPlayer(Entity_);

if(p1 && p2)
{
if(!p1.IsSpawned || !p2.IsSpawned) return false;

if(sqrt(((p1.Pos.x - p2.Pos.x)*(p1.Pos.x - p2.Pos.x)) + ((p1.Pos.y - p2.Pos.y)*(p1.Pos.y - p2.Pos.y))) < MARKER_CONFIG.RADIUS)
return true;
}

return false;
}

onPlayerJoin
function onPlayerJoin( player )
{
PlayerIDs.append(player.ID);
MarkerData[player.ID] = MarkerClass(player.ID);
}

onPlayerPart
function onPlayerPart( player, reason )
{
PlayerIDs.remove(PlayerIDs.find(player.ID));
MarkerData[player.ID].Destroy();
}

Hastebin, if the formatting in above code appears messed up.

P.S. Didn't test much.
I've tried the way similar to the codes you gave, but there is still another problem which is the limitation of number of markers you can create in VCMP server. It has a restriction of 100. Give the example that 10 players are in server, in which I might have to create 9 markers for each player. That's totally 90 markers already. It could be insufficient for me to use.

Spiller

Quote from: Kenneth Law on Nov 27, 2020, 12:55 AMI've tried the way similar to the codes you gave, but there is still another problem which is the limitation of number of markers you can create in VCMP server. It has a restriction of 100. Give the example that 10 players are in server, in which I might have to create 9 markers for each player. That's totally 90 markers already. It could be insufficient for me to use.

Totally, that's why I mentioned this is not much of a solution.
Besides Doom already stated that this can't be done exactly how you want it to be.

Kenneth Law

Alright hopefully developers could give some solution to this in the next update. Meanwhile I found some bugs in SetShowOnlyTeamMarkers(). I will post it on Bugs Report Board later.