Announce does not work

Started by Mateus, Mar 16, 2019, 06:21 PM

Previous topic - Next topic

Mateus

The announce does not work, and no error message is displayed.

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

function AnnTest(player)
{
    Announce( "Test", player, 0 );
}

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

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:

function onPlayerJoin(player)
{
      Announce( "" + player.Name + ", FPS " + player.FPS + ", Ping " + player.Ping + ", IP " + player.IP + ".", player, 0 );
}

Milos

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);
}


DizzasTeR

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

Quote from: Doom_Kill3R on Mar 17, 2019, 05:30 AMYou 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.

Mötley

#4
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.

// 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

Mateus

Quote from: Milos on Mar 16, 2019, 10:36 PMfunction 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);
}



Solved.