IsPlayerConnected <- Not working
#1

pawn Код:
if(dInfo[playerid][dVar1] == 0)
            {
                new pID = GetPlayerID(inputtext);
                if(IsPlayerConnected(pID)) // Not working as its suppose to
                {
                    new suspected[4];
                    new house = GetUserHouse(pID);
                    if(pInfo[pID][pWanteds] >= 1) { suspected="Yes"; } else { suspected="No"; }
                    new string[64];
                    format(string, sizeof(string), "Persons Name: %s\nSuspected: %d\nHouse: %d\n", inputtext, suspected, house);
                    ShowPlayerDialog(playerid, GUI_MDC, DIALOG_STYLE_MSGBOX, "MDC - Person Information", string, "Ok", "");
                }
                else {
                    new query[300];
                    format(query, sizeof(query), "SELECT * FROM %splayers WHERE name = '%s'", SQL_PREFIX, inputtext);
                    mysql_query(query);
                    new rows = strval(query);
                    if(rows == 1)
                    {
                        format(query, sizeof(query), "SELECT Wanteds FROM %splayers WHERE name = '%s'", SQL_PREFIX, inputtext);
                        mysql_query(query);
                        new wanteds = strval(query);
                        new string[64];
                        format(string, sizeof(string), "Persons Name: %s\nSuspected: %d", inputtext, wanteds);
                        ShowPlayerDialog(playerid, GUI_MDC, DIALOG_STYLE_MSGBOX, "MDC - Person Information", string, "Ok", "");
                    }
                    else {
                         ShowInfoDialog(playerid, "MDC - Error", "This name does not exist in the police database.");
                    }
                }
            }
IsPlayerConnected isnt working, GetPlayerID works as it returns the data correctly, but it doesnt check if the player is currently online. as it returns with this:

ShowInfoDialog(playerid, "MDC - Error", "This name does not exist in the police database.");
Reply
#2

strval?

show GetPlayerID
Reply
#3

pawn Код:
new pID = strval(inputtext);
Reply
#4

Quote:
Originally Posted by DrTHE
Посмотреть сообщение
pawn Код:
new pID = strval(inputtext);
Ow.. I keep on forgetting stuff like that. thanks

EDIT: 1 thing though, inputtext is a name, not an ID.


pawn Код:
stock GetPlayerID(const Name[])
{
    for(new i; i<MAX_PLAYERS; i++)
    {
      if(IsPlayerConnected(i))
      {
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(i, pName, sizeof(pName));
        if(strcmp(Name, pName, true)==0)
        {
          return i;
        }
      }
    }
    return -1;
}
Reply
#5

pawn Код:
if(GetPlayerID(inputtext) == -1) return SendClientMessage(playerid, -1, "Error, invalid name connected!");
new pID = GetPlayerID(inputtext);
pawn Код:
stock GetPlayerID(Name[])
{
    for(new i; i<MAX_PLAYERS; i++)
    {
      if(IsPlayerConnected(i))
      {
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(i, pName, sizeof(pName));
        if(strcmp(Name, pName, true) == 0)
    {
    break;
    return i;
    }
      }
    }
    return -1;
}
I think it should work.

Sorry for the bad indentation, I'm on the phone.
Reply
#6

Why a stock, when it's already a function by a_samp.inc?
Returns: The ID of the player OR -1,
pawn Код:
new pID = GetPlayerID(inputtext);
if( pID != -1 )
{
    // he's connected;
}
else
{
    //he's not
}
Reply
#7

Quote:
Originally Posted by Dwane
Посмотреть сообщение
Why a stock, when it's already a function by a_samp.inc?
Returns: The ID of the player OR -1,
pawn Код:
new pID = GetPlayerID(inputtext);
if( pID != -1 )
{
    // he's connected;
}
else
{
    //he's not
}
False

https://sampwiki.blast.hk/wiki/GetPlayerID

Quote:

Important Note: This is a custom function, which can be found in Useful_Functions.

Max
Reply
#8

My apologies!
Use the stock at the bottom of your script, and do the rest I have.
Reply
#9

Ok, thanks guys. Its working.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)