Page 1 of 1

How to get who is spectating who?

Posted: 10 May 2015, 13:18
by undef.de
I know this, but with that i can only display a note at the spectating player, but i want to do something like this:
Image

Is there a possible way to get a list who is spectating who?

Re: How to get who is spectating who?

Posted: 10 May 2015, 21:56
by Dommy
Attach custom interface layer that send netwrite data with spectated player login. In mode read this data for all spectators and merge data in array Text [Text] SpectatedPlayer[SpectatorLogin]. Send to the same layer netwrite with all data merged. Then you can easily access array with data who is spectating who.

Re: How to get who is spectating who?

Posted: 11 May 2015, 08:59
by undef.de
Thanks, that i already know... but i wanted to know if there is a easier way. 8-)

Re: How to get who is spectating who?

Posted: 24 May 2015, 14:40
by undef.de
I'm working on that splitted getting and viewing thingy, my code looks like (simplified):

Getter

Code: Select all

main () {
	declare netwrite Text[Text] Net_RecordsEyepiece_SpectatingPlayers for Teams[0];
	Net_RecordsEyepiece_SpectatingPlayers[""^InputPlayer.Login] = ""^GUIPlayer.Login;
}
Widget

Code: Select all

main () {
	declare netread Text[Text] Net_RecordsEyepiece_SpectatingPlayers for Teams[0];
	log(Now ^" : "^ Net_RecordsEyepiece_SpectatingPlayers);
}
With for Teams[0] i get the error:

Code: Select all

The objects of type CGameTeamProfile does not support declaration of attribute Net_RecordsEyepiece_SpectatingPlayers.
With for Players[0] i get the error:

Code: Select all

The objects of type CTrackManiaPlayer does not support declaration of attribute Net_RecordsEyepiece_SpectatingPlayers.
With for UI i get the result:

Code: Select all

[]
Btw.: This codes are running in one of my plugins for UASECO.
EDIT: Is the above then CTmMlScriptIngame?

Re: How to get who is spectating who?

Posted: 24 May 2015, 15:14
by Dommy
In manialink script

Code: Select all

main() {
    // Sends to gamemode spectated player login
    declare netwrite Text Net_PlayerSpectatorTarget for UI;
    
    // Receives from gamemode combined targets list: TargetLogin[SpectatorLogin];
    declare netread Text[Text] Net_SpectatedPlayers for Teams[0];
    
    while (True) {
        yield;
        
        if (IsSpectatorMode && GUIPlayer != Null) {
            Net_PlayerSpectatorTarget = GUIPlayer.User.Login;
        } else {
            Net_PlayerSpectatorTarget = "";
        }
        
        foreach (SpectatorLogin => TargetLogin in Net_SpectatedPlayers) {
            // ...
        }
    }
}
In gamemode script

Code: Select all

***StartServer***
***
// Send combined information about spectators
declare netwrite Text[Text] Net_SpectatedPlayers for Teams[0];
***

***PlayLoop***
***
// Clear array (avoid sending disconnected spectators logins)
Net_SpectatedPlayers.clear();

foreach (Player in Spectators) {
    // Receive who is spectated by player
    declare UI for Player <=> UIManager.GetUI(Player);
    
    if (UI != Null) {
        declare netread Text Net_PlayerSpectatorTarget for UI;
        // Add logins to combined array
        Net_SpectatedPlayers[Player.User.Login] = Net_PlayerSpectatorTarget;
    }
}
***

Re: How to get who is spectating who?

Posted: 24 May 2015, 15:18
by undef.de
for UI doesn't exist in my case and i also didn't have a gamemode script where i can add this (it should be used in all existing gamemodes), it is just a plugin in UASECO which sends a Manialink to the clients.

Re: How to get who is spectating who?

Posted: 24 May 2015, 15:25
by Dommy
Then it's not possible :P

Re: How to get who is spectating who?

Posted: 25 May 2015, 09:31
by spaii
undef.de wrote: Getter

Code: Select all

main () {
	declare netwrite Text[Text] Net_RecordsEyepiece_SpectatingPlayers for Teams[0];
	Net_RecordsEyepiece_SpectatingPlayers[""^InputPlayer.Login] = ""^GUIPlayer.Login;
}
Widget

Code: Select all

main () {
	declare netread Text[Text] Net_RecordsEyepiece_SpectatingPlayers for Teams[0];
	log(Now ^" : "^ Net_RecordsEyepiece_SpectatingPlayers);
}
Not tested inside a controller, but this works inside a title, datas declared with "This" are present on all layers/manialinks, then this could be :
Getter

Code: Select all

main () {
	declare  Net_RecordsEyepiece_SpectatingPlayers for This = Text[Text];
	Net_RecordsEyepiece_SpectatingPlayers[InputPlayer.Login] = GUIPlayer.Login;
}
Widget

Code: Select all

main () {
	declare Net_RecordsEyepiece_SpectatingPlayers for This = Text[Text];
	log(Now ^" : "^ Net_RecordsEyepiece_SpectatingPlayers);
}
Bon courage ;)

Re: How to get who is spectating who?

Posted: 25 May 2015, 10:32
by undef.de
spaii wrote: Not tested inside a controller, but this works inside a title, datas declared with "This" are present on all layers/manialinks, then this could be :
Getter

Code: Select all

main () {
	declare  Net_RecordsEyepiece_SpectatingPlayers for This = Text[Text];
	Net_RecordsEyepiece_SpectatingPlayers[InputPlayer.Login] = GUIPlayer.Login;
}
Widget

Code: Select all

main () {
	declare Net_RecordsEyepiece_SpectatingPlayers for This = Text[Text];
	log(Now ^" : "^ Net_RecordsEyepiece_SpectatingPlayers);
}
Does not work, because the Getter has to be run at a remote player client (Player A) and the Widget is your client (Player B). Otherwise GUIPlayer is not the spectated Player from Player A (see here for details).
spaii wrote:"This" are present on all layers/manialinks
Thanks for that info... good to know! :thx:

Re: How to get who is spectating who?

Posted: 03 Jul 2015, 19:03
by undef.de
Small update: The error messages mentioned in viewtopic.php?p=245342#p245342 are always only for netwrite, because this code works in the Widget:

Code: Select all

declare netread Net_LibUI_Settings for Teams[0];
log(Net_LibUI_Settings);

Code: Select all

[
	TimeGap_Mode=>BestRace,
	TimeGap_Display=>True,
	TimeGap_Position=>23. -90. 5.,
	Chrono_Display=>True,
	Chrono_Position=>110.3 -80.5 5.,
	CheckpointTime_Mode=>BestRace,
	CheckpointTime_DisplayTimeDiff=>True,
	CheckpointTime_Display=>True,
	CheckpointTime_Position=>-8. 31.8 -10.,
	PrevBestTime_Display=>False,
	PrevBestTime_Position=>158. -67. 5.,
	SpeedAndDistance_Display=>False,
	SpeedAndDistance_Position=>158. -79.5 5.,
	Countdown_Display=>True,
	Countdown_Position=>105. -76.5 5.,
	IndependantLaps=>True,
	Countdown_CutOffTimeLimit=>26544717
]