SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/08/2018, 10:09 PM   #1
severance
Little Clucker
 
Join Date: Apr 2015
Posts: 40
Reputation: 0
Default how to check players online

Whenever he comes with 0 players connected it says "uh, looks like the server is empty... except you" ?
severance is offline   Reply With Quote
Old 12/08/2018, 10:30 PM   #2
RedRex
Huge Clucker
 
RedRex's Avatar
 
Join Date: Jan 2016
Location: Portugal <3
Posts: 478
Reputation: 29
Default Re: how to check players online

Next time search.
Here you go: http://forum.sa-mp.com/showthread.php?t=168818
__________________
Laverton's Cops and Robbers
LCNR Soon
We are working on it. JUST WAIT US!! Soon updating to hosted tap!
RedRex is offline   Reply With Quote
Old 12/08/2018, 10:33 PM   #3
severance
Little Clucker
 
Join Date: Apr 2015
Posts: 40
Reputation: 0
Default Re: how to check players online

Quote:
Originally Posted by RedRex View Post
Next time search.
Here you go: http://forum.sa-mp.com/showthread.php?t=168818
How can you detected if there's 1 connected (showing message) and hide when there's 2 online?
severance is offline   Reply With Quote
Old 12/08/2018, 10:34 PM   #4
RedRex
Huge Clucker
 
RedRex's Avatar
 
Join Date: Jan 2016
Location: Portugal <3
Posts: 478
Reputation: 29
Default Re: how to check players online

There is a full tutoiral you can check there bro . If u need a help just start new topic or countiue with this topic.
__________________
Laverton's Cops and Robbers
LCNR Soon
We are working on it. JUST WAIT US!! Soon updating to hosted tap!
RedRex is offline   Reply With Quote
Old 12/08/2018, 10:35 PM   #5
Jing_Chan
Huge Clucker
 
Join Date: Jan 2011
Posts: 227
Reputation: 23
Default Re: how to check players online

Quote:
Originally Posted by severance View Post
How can you detected if there's 1 connected?
Code:
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?
__________________
Base Roleplay Website:
baseroleplay.com

Base Roleplay Forum:
forums.baseroleplay.com

B-RP Server IP:
104.192.227.106:8770

Server Location:
Los Santos

B-RP Discord:
https://discord.gg/4bu2T8T
Jing_Chan is online now   Reply With Quote
Old 12/08/2018, 10:44 PM   #6
severance
Little Clucker
 
Join Date: Apr 2015
Posts: 40
Reputation: 0
Default Re: how to check players online

Quote:
Originally Posted by Jing_Chan View Post
Code:
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.
severance is offline   Reply With Quote
Old 12/08/2018, 10:57 PM   #7
Jing_Chan
Huge Clucker
 
Join Date: Jan 2011
Posts: 227
Reputation: 23
Default Re: how to check players online

Code:
GetOnlinePlayers();
if(OnLine == 1) ...

I believe that would work?
__________________
Base Roleplay Website:
baseroleplay.com

Base Roleplay Forum:
forums.baseroleplay.com

B-RP Server IP:
104.192.227.106:8770

Server Location:
Los Santos

B-RP Discord:
https://discord.gg/4bu2T8T
Jing_Chan is online now   Reply With Quote
Old 13/08/2018, 12:41 AM   #8
Sew_Sumi
Godfather
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,342
Reputation: 522
Default Re: how to check players online

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

Last edited by Sew_Sumi; 13/08/2018 at 03:53 AM.
Sew_Sumi is offline   Reply With Quote
Old 13/08/2018, 08:42 AM   #9
severance
Little Clucker
 
Join Date: Apr 2015
Posts: 40
Reputation: 0
Default Re: how to check players online

Thanks Sew, your the one that actually explains something in that forum. I will try what i can and i hope it will work.
severance is offline   Reply With Quote
Old 13/08/2018, 10:28 AM   #10
brauf
Little Clucker
 
brauf's Avatar
 
Join Date: Jul 2018
Posts: 9
Reputation: 14
Default Re: how to check players online

You should try this. I have explained everything to you below.

PHP Code:
/*
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 iMAX_PLAYERSi++) // 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;

__________________
and now my watch has ended.
brauf is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check online. SukMathcuck Scripting Help 0 12/12/2016 01:32 AM
check all online players for a skin NicholasA Scripting Help 2 09/04/2013 03:00 PM
How to check online players MadafakaPro Scripting Help 14 11/03/2013 05:09 PM
How to check if anyone is online? ValentinLaw Scripting Help 3 23/08/2012 03:29 PM
How to check if someone is online through php? Luis- Scripting Help 10 08/12/2011 05:40 PM


All times are GMT. The time now is 10:21 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.