Random Announcement Lobby Interface

Experienced Elementalist
Joined
Oct 14, 2015
Messages
293
Reaction score
86
I bring you random announcement the lobby interface, and something very simple to add.

Open
: ZGameInterface.cpp
Search for: void ZGameInterface::OnDrawStateLobbyNStage(MDrawContext* pDC)
Added:
Code:
	pLabel = (MLabel*)pRes->FindWidget("Lobby_RandomAnnounce");
	int RandomMsg = (timeGetTime() / (3 * 60 * 1000) % 2); // 3 min 
	int i = 0;
	for (i = 0; i < RandomMsg; i++);
	switch (i)
	{
	case 0:
  sprintf(buf, "Update: 0.0.0.1");
  break;
	case 1:
  sprintf(buf, "Welcome The Gunz!");
  break;
	}
	if (pLabel) pLabel->SetText(buf);

Open: Lobby.xml
Added:
PHP:
  <LABEL item="Lobby_RandomAnnounce" parent="Lobby">
  <FONT>FONTa8_O2Wht</FONT>
  <TEXTCOLOR>
   <R>210</R>
   <G>210</G>
   <B>210</B>
  </TEXTCOLOR>
  <BOUNDS>
   <X>15</X>
   <Y>566</Y>
   <W>380</W>
   <H>20</H>
  </BOUNDS>
  <TEXT></TEXT>
  </LABEL>

Credits: Avrora :w00t:
 

Attachments

You must be registered for see attachments list
Last edited:
Newbie Spellweaver
Joined
May 3, 2014
Messages
47
Reaction score
30

Hey! The current logic is wrong, the switch statement inside the for loop might print multiple messages and not a random one.
You should just roll a random number between 1 and your Max Announcements amount, and then switch case statement on the number you rolled.
I also recommend to move the "if(pLabel)" condition to the very beginning because otherwise its redundant to run all the logic.
 

Attachments

You must be registered for see attachments list
Newbie Spellweaver
Joined
Jul 11, 2021
Messages
26
Reaction score
9
What Sharp said is correct.

Also if for some reason you want to do this and not just use a web endpoint, store the strings in system.mrs\strings.xml and pull them from there. Supports localization/don't need to patch the executable if you'd like to change the strings.

That being said it's infinitely better to use a web endpoint that handles the "random" logic itself, and just send a request out to that when a user joins for the first time that session. Then you'd not have to update any files on a player's machine in order to change the announcements.

Or just have the MatchServer store the strings locally in a text file and request a random line from that text file via tcp and output it that way.
 
Banned
Banned
Joined
Jun 26, 2012
Messages
254
Reaction score
10
and I think it would be even better to work with some xml in case you use the game's language system, so you will have it in different languages.
example:
Code:
		pLabel = (MLabel*)pRes->FindWidget("Lobby_RandomAnnounce");
		int RandomMsg = (timeGetTime() / (3 * 60 * 1000) % 2); // 3 min 
		int i = 0;
		for (i = 0; i < RandomMsg; i++);
		switch (i)
		{
		case 0:
			sprintf(buf, "%s", ZMsg(MSG_ANNOUNCE_1));
			break;
		case 1:
			sprintf(buf, "%s", ZMsg(MSG_ANNOUNCE_2));
			break;
		}
		if (pLabel) pLabel->SetText(buf);

also create a command similar to admin_wall to print what you write in that system would also be good, you can vary many things there depends on the creativity of each person, I already gave an idea.
 
Experienced Elementalist
Joined
Oct 14, 2015
Messages
293
Reaction score
86
The code is there for you, you can update the way you want.




Sorry megol my dislike was by accident.
 
Skilled Illusionist
Joined
Oct 29, 2012
Messages
312
Reaction score
26

But for this case, would it be necessary to restart the matchserver every time a local string (within the serverfiles) was changed?
 
Newbie Spellweaver
Joined
Feb 16, 2011
Messages
53
Reaction score
2
You could've just...

Code:
const std::vector<std::string> messages{ "Announce 1", "Announce 2", "Announce 3" };
const auto announceId = std::rand() % messages.size();
const auto announce = messages[announceId];

...

std::sprintf(buf, announce.c_str());

...
 
Last edited:
Newbie Spellweaver
Joined
Jul 11, 2021
Messages
26
Reaction score
9
But for this case, would it be necessary to restart the matchserver every time a local string (within the serverfiles) was changed?

No, not at all. Just close and re-open the file handle every 5 minutes or so. You can update the announcement file and it'll apply within ~5 minutes maximum. Seems fine to me.