how to check players online -
severance - 12.08.2018
Whenever he comes with 0 players connected it says "uh, looks like the server is empty... except you" ?
Re: how to check players online -
RedRex - 12.08.2018
Next time search.
Here you go:
https://sampforum.blast.hk/showthread.php?tid=168818
Re: how to check players online -
severance - 12.08.2018
Quote:
Originally Posted by RedRex
|
How can you detected if there's 1 connected (showing message) and hide when there's 2 online?
Re: how to check players online -
RedRex - 12.08.2018
There is a full tutoiral you can check there bro

. If u need a help just start new topic or countiue with this topic.
Re: how to check players online -
Jing_Chan - 12.08.2018
Quote:
Originally Posted by severance
How can you detected if there's 1 connected?
|
pawn Код:
stock GetOnLinePlayers()
{
new OnLine;
for(new i, g = GetMaxPlayers(); i < g; i++)
if(IsPlayerConnected(i))
OnLine++;
return OnLine;
}
Why do you want to specifically know if there's 1 connected?
Re: how to check players online -
severance - 12.08.2018
Quote:
Originally Posted by Jing_Chan
pawn Код:
stock GetOnLinePlayers() { new OnLine; for(new i, g = GetMaxPlayers(); i < g; i++) if(IsPlayerConnected(i)) OnLine++; return OnLine; }
Why do you want to specifically know if there's 1 connected?
|
Because there's going to be a message shown if the player is alone in the server, and when the second player joins, the message should be hidden to next players. I want to understand how can you detect a certain amount of players from online list. Example: "5 players needed to start the gamemode" and then it hides the message and players can play.
Re: how to check players online -
Jing_Chan - 12.08.2018
pawn Код:
GetOnlinePlayers();
if(OnLine == 1) ...
I believe that would work?
Re: how to check players online -
Sew_Sumi - 13.08.2018
Quote:
Originally Posted by Jing_Chan
pawn Код:
GetOnlinePlayers(); if(OnLine == 1) ...
I believe that would work?
|
You're dead wrong, and don't throw out guesses like that again... Reason being that the GetOnlinePlayers function, isn't going to hand the variables it made, as they aren't global, to the rest of the script.
OnLine ONLY exists 'within' that function.
You use what it returns to point out what happened to the code that called it.
Код:
if(GetOnlinePlayers()>5){Commence}
else if{Don't}
^^ This check very likely doesn't actually work, but it's the idea that the actual variable isn't visible to the code at that level, and thus it should error out saying the variable isn't defined when you compiled it.
Re: how to check players online -
severance - 13.08.2018
Thanks Sew, your the one that actually explains something in that forum. I will try what i can and i hope it will work.
Re: how to check players online -
brauf - 13.08.2018
You should try this. I have explained everything to you below.
PHP код:
/*
Script Documentation:
Made by: brauf
Tested: Yes
*/
#include <a_samp>
new PlayersOnline; // this variable stores a integer of the players online
GetPlayersOnServer() // function to get players on server
{
PlayersOnline = 0; // reset online players each time when trying to fetch it otherwise "PlayersOnline" will just keep increasing each time (++) with each check
for(new i; i < MAX_PLAYERS; i++) // do a loop of all player slots available (1, 2, 3 - 1000), if player slot 1 or 2 or 3 has a valid player connected (IsPlayerConnected) then increase "PlayersOnline" by 1 (++)
{
if(IsPlayerConnected(i)) // a check to see if player is online on that id
{
PlayersOnline++; // increase "PlayersOnline" by 1 if there is a online player on
return PlayersOnline; // return "PlayersOnline" which tells the server how much players are on
}
}
return PlayersOnline; // return "PlayersOnline" which stores the value of how much players are on
}
public OnPlayerConnect(playerid)
{
GetPlayersOnServer(); // execute this function "OnPlayerConnect" so when a player logs in, it tries to detect how much players are on
if(PlayersOnline == 1) // if online players = 1, then there is only 1 player online
{
SendClientMessage(playerid, -1, "Looks like the server is empty, except you."); // send a message
}
return 1;
}