Experienced Elementalist
- Joined
- Oct 14, 2015
- Messages
- 293
- Reaction score
- 86
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);
<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>
thanks for the idea Military Updated the code.Why not use a switch statement instead?
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:
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);
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.
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.
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());
...
But for this case, would it be necessary to restart the matchserver every time a local string (within the serverfiles) was changed?