Announce does not work

Mateus

  • Newbie
  • Posts: 1
Announce does not work
«  »
The announce does not work, and no error message is displayed.

Code: [Select]
function onPlayerJoin(player)
{
Announce( "Test" + GetFullTime() + "." ,player, 0 );
NewTimer( "AnnTest", 5000, 1, player );
}

Code: [Select]
function AnnTest(player)
{
    Announce( "Test", player, 0 );
}

An error message is displayed and the server exits when Announce is:

Code: [Select]
function AnnTest(player)
{
    Announce( "" + player.Name + ", FPS " + player.FPS + ", Ping " + player.Ping + ", IP " + player.IP + ".", player, 0 );
}

But this does not display any error messages, and the server does not shut down:

Code: [Select]
function onPlayerJoin(player)
{
      Announce( "" + player.Name + ", FPS " + player.FPS + ", Ping " + player.Ping + ", IP " + player.IP + ".", player, 0 );
}

Milos

  • Jr. Member
  • Posts: 77
Re: Announce does not work
« Reply #1,  »
Code: [Select]
function onPlayerJoin(player) {
NewTimer( "AnnTest", 5000, 1, player.ID );
}

function AnnTest(playerid) {
local player = FindPlayer(playerid);
if (!player) return;
Announce(player.Name + ", FPS " + player.FPS + ", Ping " + player.Ping + ", IP " + player.IP + ".", player, 0);
}


Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,088
Re: Announce does not work
« Reply #2,  »
You can't pass player instances in timers, it crashes the server, pass player ID and and find the player on callback function

Mahmoud Tornado

  • Full Member
  • Posts: 220
Re: Announce does not work
« Reply #3,  »
Quote from Doom_Kill3R on March 17th, 05:30 AM
You can't pass player instances in timers, it crashes the server, pass player ID and and find the player on callback function
That's was one of my problems when i made Anti-Spawnkill.

Bob

  • Hero Member
  • Posts: 778
Re: Announce does not work
« Reply #4,  »Last edited
You should have a server timer for all of these things and loop through the players by now in seconds. Then you just need a bunch of boolean values for the player so the timer can run a check. Using multiple timers in a server can be bad. And I don't personally trust auto execution of timers server side.

Code: [Select]
// Seconds storage
Player_Seconds <- array( GetMaxPlayers(), 0 );

// Minutes storage
Player_Minutes <- array( GetMaxPlayers(), 0 );

max_hints <- 4;

hint <- [
"Hint 0",
"Hint 1",
"Hint 2",
"Hint 3"
];
NewTimer("Server_Loop", 1000, 0);
function Server_Loop() {

  for (local i=0;i<GetMaxPlayers();i++) {
    local player = FindPlayer(i);
   
    if (player) {
      // Increase the time in seconds
      Player_Seconds[player.ID]++;
     
      /*

      Do anything here in seconds

      */
      //Announce("Time: " + Player_Minutes[player.ID] + ":" + Player_Seconds[player.ID], player, 0 );

      // Check time
      if (Player_Seconds[player.ID] == 60) {
        Player_Minutes[player.ID]++;
   
        // Clear the seconds
        Player_Seconds[player.ID] = 0;
     
        //hints
        /*local iRandom = rand() % max_hints;
        Announce( hint[iRandom], player, 0 );*/
        //hints

        /*
        You can do anything here. Add a check for every five minutes to anything really
        */
      }
      // Check time

    }
  }
}

You should use a class instead of those arrays. Some might say this isn't the right way. But better than many! timers