Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Random Announcement Lobby Interface

Experienced Elementalist
Joined
Oct 14, 2015
Messages
290
Reaction score
83
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>
LL9zM7H - Random Announcement Lobby Interface - RaGEZONE Forums

Credits: Avrora :w00t:
 

Attachments

You must be registered for see attachments list
Last edited:
Initiate Mage
Joined
May 3, 2014
Messages
46
Reaction score
30
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>
LL9zM7H - Random Announcement Lobby Interface - RaGEZONE Forums

Credits: Avrora :w00t:

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
Initiate Mage
Joined
Jul 11, 2021
Messages
25
Reaction score
7
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
290
Reaction score
83
The code is there for you, you can update the way you want.



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.

Sorry megol my dislike was by accident.
 
Skilled Illusionist
Joined
Oct 29, 2012
Messages
311
Reaction score
25
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.

But for this case, would it be necessary to restart the matchserver every time a local string (within the serverfiles) was changed?
 
Initiate Mage
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:
Initiate Mage
Joined
Jul 11, 2021
Messages
25
Reaction score
7
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.
 
Back
Top