[Help] OnPlayerConnect public.
#1

PHP код:
public OnPlayerConnect(playerid)
{
    
TextDrawShowForPlayer(playeridTextdrawConnect0); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect1); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect2); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect3); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect4); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect5); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect6); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect7); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect8); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect9); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect10); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect11); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect12); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect13); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect14); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect15); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect16); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect17); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect18); // Connect Textdraw
    
TextDrawShowForPlayer(playeridTextdrawConnect19); // Connect Textdraw
    
TextDrawShowForPlayer(playeridCredit); // Credits
    
new name[MAX_PLAYER_NAME]; // Player Name Textdraw
    
GetPlayerName(playerid,name,MAX_PLAYER_NAME);// Player Name Textdraw
    
PlayerN=TextDrawCreate(115,416,name);// Player Name Textdraw
    
TextDrawShowForPlayer(playeridPlayerN);// Player Name Textdraw
    
TextDrawColor(PlayerN,0xFFFFFFAA);// Player Name Textdraw
    
TextDrawFont(PlayerN,3);// Player Name Textdraw
    
TextDrawSetShadow(PlayerN,1);// Player Name Textdraw
    
        
pLogged[playerid] = 0;
    
#if defined AUTOLOGIN
        
new tmpIP[16];
        
GetPlayerIp(playerid,tmpIP,sizeof(tmpIP)); //Getting IP
    #endif
    
if(fexist(PlayerPath(playerid)))
    {
        
INI_ParseFile(PlayerPath(playerid), "UserDataLoad_%s", .bExtra true, .extra playerid); //Calling loading callback
        #if defined AUTOLOGIN
            
if(strcmp(tmpIP,pIP[playerid],true) == 0)//Checking if the IPs match
            

                
pLogged[playerid] = 1;
                
SetPlayerScore(playerid,pInfo[playerid][Score]);
                
GivePlayerMoney(playerid,pInfo[playerid][Cash]);
                
SendClientMessage(playerid,lime,"You've been auto-logged in. [IP match]");
                return 
1;
            }
        
#endif
        
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
    }
     else
          {
        
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","Please register by entering a password below.","Register","Leave");
    }
        if(
dini_Exists(MsgFile()))
        {
        new 
string[128];
        
format(string,128,"Server Message: {ffffff}%s",dini_Get(MsgFile(),"MSG"));
        
SendClientMessage(playerid,0x00ff00ff,string);
        return 
1;
        }
    
    
PlayAudioStreamForPlayer(playerid,"http://k005.kiwi6.com/hotlink/0hn592rrdn/Alex_Mica_Dalinda_Official_Radio_Edit.mp3");
      
Radio[playerid] = false;
      
     return 
1;

Few day's ago i just added the register system after i read a tutorial in the sub fourm, anyway i think there's a problem in the public that i can not see.

A. The music not playing. (WORKED before three day's)
B. The server message doesn't shown up.


Thanks!
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
Do you know what "return" does?
Yes it's passes a value.
Reply
#3

Yes but what does "return" actually do?
It has something to do with returning...
Reply
#4

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Yes but what does "return" actually do?
It has something to do with returning...
Well i don't know what you excatly mean...
Can you help me? Thanks.
Reply
#5

'return' returns to the point where the function it's used in is called.

For example:
pawn Код:
if(!strcmp(cmdtext, "/hello", true))
{
    Hello();
    return 1;
}
pawn Код:
stock Hello()
{
    return 0;
}
Running 'Hello()' will return 0 for processing by wherever it was called, in this case, OnPlayerCommandText. You can then use the returned 0 for something such as SendClientMessage. Note that it has returned to OnPlayerCommandText (via return 0), therefore anything AFTER the 'return' is ignored and the function is cut short.

pawn Код:
stock Hello()
{
    return 0;
    return 1;
}
...will return 0, not 1.


Think of it as a person. A player types /hello, the person goes into OnPlayerCommandText to grab whatever is in /hello. "Hello()" is in /hello, so said person then goes into the Hello() function to grab whatever is in there. In this case, the man is told to return with a 0. He returns to /hello with a 0, as given by the Hello() function, where it can be used in processing in the /hello command. /hello no longer needs the Hello() information and so tells the man to return with a 1. The man returns to the server holding a 1, as given by the /hello command.


Applying this to your script...

pawn Код:
if(strcmp(tmpIP,pIP[playerid],true) == 0)//Checking if the IPs match
            {  
                pLogged[playerid] = 1;
                SetPlayerScore(playerid,pInfo[playerid][Score]);
                GivePlayerMoney(playerid,pInfo[playerid][Cash]);
                SendClientMessage(playerid,lime,"You've been auto-logged in. [IP match]");
                return 1;
            }
The man checks the IP, automatically logs the player in and then continues through the if statement. The if statement tells the man to return to the server with a 1. He does, and doesn't go back.

In this case, remove the return 1; after the SendClientMessage.



pawn Код:
if(dini_Exists(MsgFile()))
        {
        new string[128];
        format(string,128,"Server Message: {ffffff}%s",dini_Get(MsgFile(),"MSG"));
        SendClientMessage(playerid,0x00ff00ff,string);
        return 1;
        }
The man wasn't automatically logged in and so he's not told to return. He continues on to this if statement. He goes through it, is told the message, then is told to return to the server and stop carrying out the rest of the function.
Again, remove the return 1; after the SendClientMessage.


Firstly, the man asks if the IPs match. They don't, so he is never told to return.
The man then asks if MsgFile exists. It does, so he goes into the if statement and is told to return.
Because the man has returned, he's never told to play music. Therefore, the music doesn't play.


In short, remove return 1; from the end of both statements I quoted.
Reply
#6

Quote:
Originally Posted by [FMJ]PowerSurge
Посмотреть сообщение
'return' returns to the point where the function it's used in is called.

For example:
pawn Код:
if(!strcmp(cmdtext, "/hello", true))
{
    Hello();
    return 1;
}
pawn Код:
stock Hello()
{
    return 0;
}
Running 'Hello()' will return 0 for processing by wherever it was called, in this case, OnPlayerCommandText. You can then use the returned 0 for something such as SendClientMessage. Note that it has returned to OnPlayerCommandText (via return 0), therefore anything AFTER the 'return' is ignored and the function is cut short.

pawn Код:
stock Hello()
{
    return 0;
    return 1;
}
...will return 0, not 1.


Think of it as a person. A player types /hello, the person goes into OnPlayerCommandText to grab whatever is in /hello. "Hello()" is in /hello, so said person then goes into the Hello() function to grab whatever is in there. In this case, the man is told to return with a 0. He returns to /hello with a 0, as given by the Hello() function, where it can be used in processing in the /hello command. /hello no longer needs the Hello() information and so tells the man to return with a 1. The man returns to the server holding a 1, as given by the /hello command.


Applying this to your script...

pawn Код:
if(strcmp(tmpIP,pIP[playerid],true) == 0)//Checking if the IPs match
            {  
                pLogged[playerid] = 1;
                SetPlayerScore(playerid,pInfo[playerid][Score]);
                GivePlayerMoney(playerid,pInfo[playerid][Cash]);
                SendClientMessage(playerid,lime,"You've been auto-logged in. [IP match]");
                return 1;
            }
The man checks the IP, automatically logs the player in and then continues through the if statement. The if statement tells the man to return to the server with a 1. He does, and doesn't go back.

In this case, remove the return 1; after the SendClientMessage.



pawn Код:
if(dini_Exists(MsgFile()))
        {
        new string[128];
        format(string,128,"Server Message: {ffffff}%s",dini_Get(MsgFile(),"MSG"));
        SendClientMessage(playerid,0x00ff00ff,string);
        return 1;
        }
The man wasn't automatically logged in and so he's not told to return. He continues on to this if statement. He goes through it, is told the message, then is told to return to the server and stop carrying out the rest of the function.
Again, remove the return 1; after the SendClientMessage.


Firstly, the man asks if the IPs match. They don't, so he is never told to return.
The man then asks if MsgFile exists. It does, so he goes into the if statement and is told to return.
Because the man has returned, he's never told to play music. Therefore, the music doesn't play.


In short, remove return 1; from the end of both statements I quoted.
Wow man, thanks!
But, now the auto login with IP doesn't work, it's saying "You've been auto-logged in. [IP match]" but then he asking the password from me, so it's not a autologin.
Reply
#7

pawn Код:
if(fexist(PlayerPath(playerid)))
    {
        INI_ParseFile(PlayerPath(playerid), "UserDataLoad_%s", .bExtra = true, .extra = playerid); //Calling loading callback
        #if defined AUTOLOGIN
            if(strcmp(tmpIP,pIP[playerid],true) == 0)//Checking if the IPs match
            {  
                pLogged[playerid] = 1;
                SetPlayerScore(playerid,pInfo[playerid][Score]);
                GivePlayerMoney(playerid,pInfo[playerid][Cash]);
                SendClientMessage(playerid,lime,"You've been auto-logged in. [IP match]");
            }
        #endif
        ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
    }
You never check if they're logged in before showing the dialog. You log them in then show them the dialog.

Try changing the ShowPlayerDialog to this:

pawn Код:
if(pLogged[playerid] == 0)
{
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
}
Reply
#8

Quote:
Originally Posted by [FMJ]PowerSurge
Посмотреть сообщение
pawn Код:
if(fexist(PlayerPath(playerid)))
    {
        INI_ParseFile(PlayerPath(playerid), "UserDataLoad_%s", .bExtra = true, .extra = playerid); //Calling loading callback
        #if defined AUTOLOGIN
            if(strcmp(tmpIP,pIP[playerid],true) == 0)//Checking if the IPs match
            {  
                pLogged[playerid] = 1;
                SetPlayerScore(playerid,pInfo[playerid][Score]);
                GivePlayerMoney(playerid,pInfo[playerid][Cash]);
                SendClientMessage(playerid,lime,"You've been auto-logged in. [IP match]");
            }
        #endif
        ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
    }
You never check if they're logged in before showing the dialog. You log them in then show them the dialog.

Try changing the ShowPlayerDialog to this:

pawn Код:
if(pLogged[playerid] == 0)
{
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
}
It's giving me 26 errors..
Reply
#9

pawn Код:
#endif
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
pawn Код:
#endif
if(pLogged[playerid] == 0)
{
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
}
What are the errors?
Reply
#10

Quote:
Originally Posted by [FMJ]PowerSurge
Посмотреть сообщение
pawn Код:
#endif
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
pawn Код:
#endif
if(pLogged[playerid] == 0)
{
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
}
It's giving me 26 errors.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)