Random Announcement Lobby Interface

Results 1 to 10 of 10
  1. #1
    Orby? Orby ? @-@ Orby is online now
    MemberRank
    Oct 2015 Join Date
    AstraLocation
    278Posts

    note Random Announcement Lobby Interface

    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 Code:
      <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
    Last edited by Orby; 18-10-21 at 02:13 AM.


  2. #2
    Doggie And Rice. Military is offline
    MemberRank
    Jun 2009 Join Date
    Here and AboutLocation
    3,301Posts

    Re: Random Announcement Lobby Interface

    Why not use a switch statement instead?

  3. #3
    Orby? Orby ? @-@ Orby is online now
    MemberRank
    Oct 2015 Join Date
    AstraLocation
    278Posts

    Re: Random Announcement Lobby Interface

    Quote Originally Posted by Military View Post
    Why not use a switch statement instead?
    thanks for the idea @Military Updated the code.

  4. #4
    Enthusiast sharpshot is offline
    MemberRank
    May 2014 Join Date
    36Posts

    Re: Random Announcement Lobby Interface

    Quote Originally Posted by Orby View Post
    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 Code:
      <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
    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.

  5. #5
    Apprentice zkxjzmswkwl is offline
    MemberRank
    Jul 2021 Join Date
    18Posts

    Re: Random Announcement Lobby Interface

    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.

  6. #6
    RailGunZ Soon! megol is online now
    MemberRank
    Jun 2012 Join Date
    260Posts

    Re: Random Announcement Lobby Interface

    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.

  7. #7
    Orby? Orby ? @-@ Orby is online now
    MemberRank
    Oct 2015 Join Date
    AstraLocation
    278Posts

    Re: Random Announcement Lobby Interface

    The code is there for you, you can update the way you want.

    - - - Updated - - -

    Quote Originally Posted by megol View Post
    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.

  8. #8
    Account Upgraded | Title Enabled! Enough is offline
    MemberRank
    Oct 2012 Join Date
    299Posts

    Re: Random Announcement Lobby Interface

    Quote Originally Posted by zkxjzmswkwl View Post
    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?

  9. #9
    Member douth is offline
    MemberRank
    Feb 2011 Join Date
    61Posts

    Re: Random Announcement Lobby Interface

    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 by douth; 18-10-21 at 04:43 PM. Reason: typo

  10. #10
    Apprentice zkxjzmswkwl is offline
    MemberRank
    Jul 2021 Join Date
    18Posts

    Re: Random Announcement Lobby Interface

    Quote Originally Posted by Enough View Post
    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.



Advertisement