This is the code in v1.40 that parses the messages to control the flag hud. It is also far more complicated than it needs to be.
Code: Select all
function Legacy::flagEvents( %msg ) {
if (%msg == "You couldn't buy Flag")
return "mute";
%event = "";
%id = 0;
if( ( %idx = String::FindSubStr( %msg, " took the" ) ) != -1 ) {
%name = String::GetSubStr(%msg, 0, %idx);
if ( %name == "You")
%name = Client::getName(getManagerId());
%id = getClientByName( %name );
%team = Client::GetTeam( %id ) ^ 1;
%event = "FlagTaken";
} else if ( ( %idx = String::FindSubStr( %msg, " dropped the" ) ) != -1 ) {
%name = String::GetSubStr(%msg, 0, %idx);
if ( %name == "You")
%name = Client::getName(getManagerId());
%id = getClientByName( %name );
%team = Client::GetTeam( %id ) ^ 1;
%event = "FlagDropped";
} else if ( ( %idx = String::FindSubStr(%msg, " returned the" ) ) != -1 ) {
%name = String::GetSubStr(%msg, 0, %idx);
if ( %name == "You")
%name = Client::getName(getManagerId());
%id = getClientByName( %name );
%team = Client::GetTeam( %id );
%event = "FlagReturned";
} else if( ( %idx = String::FindSubStr( %msg, " captured the" ) ) != -1 ) {
%name = String::GetSubStr(%msg, 0, %idx);
if ( %name == "You")
%name = Client::getName(getManagerId());
else if ( %name == "Your Team" )
return;
%id = getClientByName( %name );
%team = Client::GetTeam( %id ) ^ 1;
%event = "FlagCaptured";
} else if ( (%idx = String::FindSubStr( %msg, " left the mission" ) ) != -1 ) {
%name = String::GetSubStr(%msg, 0, %idx);
if ( %name == "You")
%name = Client::getName(getManagerId());
%id = getClientByName( %name );
%team = Client::GetTeam( %id ) ^ 1;
%event = "FlagReturned";
}
if ( %id == 0 || %event == "" )
return false;
*"remote"~%event( 2048, %team, %id );
return true;
}
This function is only called if the message contains the word "flag".
It searches the message for the following phrases: " took the", " dropped the", " returned the", " captured the", " left the mission".
If found, it truncates the message where the phrase was found, isolating what should be a player's name.
Then it gets the client Id using the player's name, and gets the team number using the client Id.
Last, it evaluates a different function for each of those phrases: "remoteFlagTaken", "remoteFlagDropped", "remoteFlagReturned", "remoteFlagCaptured", or "remoteFlagReturned"
Each of these functions update the flag hud and some auto waypoint if configured to do so.
Despite the fact that this code is extra complicated, it works most of the time. The only reason I can think of for it to fail is if the server was modified to change the flag related announcements. And that's the case with the BR server, which announces the armor description of the flag carrier.
While it's nice to know which armor the flag carrier is wearing, this feature has probably broken every flag hud script in existence.
I'd have to write a new one to compensate, and while I'd like to make it far less complicated than the two convoluted examples posted here, I fear that I'll have to make them somewhat complicated for compatibility with the two configs mentioned.
Unfortunately, this takes me a bit out of my zone of expertise. I know server side scripting, AKA darkstar script. I attempted to teach myself HUD coding awhile back, but wasn't very successful. The GUI interface seemed convoluted to me.
This is not something I can fix in a matter of seconds, although, I originally thought it was.