PDA

View Full Version : Onlie Players


Micko123
03/11/2016, 09:19 PM
Hey guys. I want to make online player count. Is there any way to do it without timer??
I tried like this

public OnPlayerConnect(playerid)
{
format(string1, sizeof(string1), "%d", Iter_Count(Player));
PlayerTextDrawSetString(playerid, OnlineRecordTD[playerid][2], string1);
return 1;
}


But it is not working

Do I need to use timer??

oMa37
03/11/2016, 09:51 PM
Make it a global textdraw, This function will change the textdraw string ONLY for the player that have joined.

Ner0x96
04/11/2016, 01:22 AM
Make it a global textdraw, This function will change the textdraw string ONLY for the player that have joined.

Agree hehe.
But you have to put it in OnPlayerDisconnect to (the count will be '--' and the TD will have to get updated)

Micko123
04/11/2016, 06:57 AM
I have this

new PlayersOnline; //global

public OnPlayerConnect(playerid)
{
new string2[5];
PlayersOnline ++;
format(string2, sizeof(string2), "%d%", PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], string2);
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
PlayersOnline --;
format(string2, sizeof(string2), "%d%", PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], string2);
return 1;
}

But still not working I created TD like this

OnlineRecordTD[2] = TextDrawCreate(112.666671, 290.551269, "1000");
TextDrawLetterSize(OnlineRecordTD[2], 0.400000, 1.600000);
TextDrawAlignment(OnlineRecordTD[2], 1);
TextDrawColor(OnlineRecordTD[2], 16777215);
TextDrawSetShadow(OnlineRecordTD[2], 0);
TextDrawSetOutline(OnlineRecordTD[2], 0);
TextDrawBackgroundColor(OnlineRecordTD[2], 255);
TextDrawFont(OnlineRecordTD[2], 1);
TextDrawSetProportional(OnlineRecordTD[2], 1);
TextDrawSetShadow(OnlineRecordTD[2], 0);

When I join it says 1000.. Any ideas?

Hunud
04/11/2016, 07:01 AM
create an loop for this textdraw

Micko123
04/11/2016, 07:03 AM
Wut?

Hunud
04/11/2016, 07:06 AM
new PlayersOnline[MAX_PLAYERS];

On each an created textdraw onlinerecordTd add [playerid] and put that textdraw in loop

Micko123
04/11/2016, 07:09 AM
This is wheat they said..

Make it a global textdraw, This function will change the textdraw string ONLY for the player that have joined.

And I tried with player textdraw.. same problem

RoboN1X
04/11/2016, 07:27 AM
Try this:

new PlayersOnline;
public OnGameModeInit()
{

OnlineRecordTD[2] = TextDrawCreate(112.666671, 290.551269, "0");
TextDrawLetterSize(OnlineRecordTD[2], 0.400000, 1.600000);
TextDrawAlignment(OnlineRecordTD[2], 1);
TextDrawColor(OnlineRecordTD[2], 16777215);
TextDrawSetShadow(OnlineRecordTD[2], 0);
TextDrawSetOutline(OnlineRecordTD[2], 0);
TextDrawBackgroundColor(OnlineRecordTD[2], 255);
TextDrawFont(OnlineRecordTD[2], 1);
TextDrawSetProportional(OnlineRecordTD[2], 1);
TextDrawSetShadow(OnlineRecordTD[2], 0);

return 1;
}

public OnPlayerConnect(playerid)
{

if(!IsPlayerNPC(playerid))
{
new pcount[5];
valstr(pcount, ++PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], pcount);
TextDrawShowForPlayer(playerid, OnlineRecordTD[2]);
}

return 1;
}

public OnPlayerDisconnect(playerid, reason)
{

if(!IsPlayerNPC(playerid))
{
new pcount[5];
valstr(pcount, --PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], pcount);
}

return 1;
}
EDIT: Of course, you have to declare new OnlineRecordTD[] as global as well.

Sorry for my bad english.

Micko123
04/11/2016, 07:34 AM
Hold on..

EDIT: Nope.. same

Threshold
04/11/2016, 07:47 AM
Iter_Count(Player) + 1 ...?

Micko123
04/11/2016, 07:58 AM
Iter_Count(Player) + 1 ...?

I did it like this and still not working

new PlayersOnline; //global

public OnPlayerConnect(playerid)
{
new string2[5];
PlayersOnline ++;
format(string2, sizeof(string2), "%d%", PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], string2);
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
PlayersOnline --;
format(string2, sizeof(string2), "%d%", PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], string2);
return 1;
}

RoboN1X
04/11/2016, 08:15 AM
Try this:

new PlayersOnline;
public OnGameModeInit()
{

OnlineRecordTD[2] = TextDrawCreate(112.666671, 290.551269, "0");
TextDrawLetterSize(OnlineRecordTD[2], 0.400000, 1.600000);
TextDrawAlignment(OnlineRecordTD[2], 1);
TextDrawColor(OnlineRecordTD[2], 16777215);
TextDrawSetShadow(OnlineRecordTD[2], 0);
TextDrawSetOutline(OnlineRecordTD[2], 0);
TextDrawBackgroundColor(OnlineRecordTD[2], 255);
TextDrawFont(OnlineRecordTD[2], 1);
TextDrawSetProportional(OnlineRecordTD[2], 1);
TextDrawSetShadow(OnlineRecordTD[2], 0);

return 1;
}

public OnPlayerConnect(playerid)
{

if(!IsPlayerNPC(playerid))
{
new pcount[5];
valstr(pcount, ++PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], pcount);
TextDrawShowForPlayer(playerid, OnlineRecordTD[2]);
}

return 1;
}

public OnPlayerDisconnect(playerid, reason)
{

if(!IsPlayerNPC(playerid))
{
new pcount[5];
valstr(pcount, --PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], pcount);
}

return 1;
}
EDIT: Of course, you have to declare new OnlineRecordTD[] as global as well.

Sorry for my bad english.

Hold on..

EDIT: Nope.. same

Are you sure?
http://i.imgur.com/5MD6Wuu.gif

Threshold
04/11/2016, 08:27 AM
Please be more specific than 'not working'. RoboN1X's code looks fine to me, I'd suggest you use that. You're missing TextDrawShowForPlayer in your codes, so I would expect some disparity.

Micko123
04/11/2016, 09:35 AM
This is what I have..

new Text:OnlineRecordTD[4]; //TD Online - Record

new PlayersOnline;

public OnPlayerConnect(playerid)
{
Mission1Started[playerid] = 0;
if(IsPlayerConnected(playerid))
{
new string[40];
format(string, sizeof(string), "Player "SERVERBLUE"%s "WHITE"connected to server", GetName(playerid));
SCMTA(-1, string);
new pcount[5];
valstr(pcount, ++PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], pcount);
TextDrawShowForPlayer(playerid, OnlineRecordTD[2]);
}
SendDeathMessage(INVALID_PLAYER_ID, playerid, ICON_CONNECT);
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
DestroyOnlineRecord();
new string[60];
format(string, sizeof(string), "Player "SERVERBLUE"%s "WHITE"disconnected", GetName(playerid));
SCMTA(-1, string);
new pcount[5];
valstr(pcount, --PlayersOnline);
TextDrawSetString(OnlineRecordTD[2], pcount);
Mission1Started[playerid] = 0;
SendDeathMessage(INVALID_PLAYER_ID,playerid, ICON_DISCONNECT);
return 1;
}


Still nothing.. When I join it says 1000

Bolex_
04/11/2016, 09:38 AM
Example

http://forum.sa-mp.com/showthread.php?t=168818