Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Mateus on Mar 16, 2019, 06:21 PM

Title: Announce does not work
Post by: Mateus on Mar 16, 2019, 06:21 PM
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 );
}
Title: Re: Announce does not work
Post by: Milos on Mar 16, 2019, 10:36 PM
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);
}

(https://i.postimg.cc/mkB3cPrq/2019-03-16-19-32-56-0477.png)
Title: Re: Announce does not work
Post by: DizzasTeR on Mar 17, 2019, 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
Title: Re: Announce does not work
Post by: Mahmoud Tornado on Mar 21, 2019, 05:35 PM
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.
Title: Re: Announce does not work
Post by: Mötley on Mar 22, 2019, 03:20 PM
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
Title: Re: Announce does not work
Post by: Mateus on Aug 20, 2019, 05:40 PM
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);
}

(https://i.postimg.cc/mkB3cPrq/2019-03-16-19-32-56-0477.png)

Solved.