[Help] OnPlayerConnect public.
#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


Messages In This Thread
[Help] OnPlayerConnect public. - by Firo - 19.05.2012, 17:47
Re: [Help] OnPlayerConnect public. - by Firo - 19.05.2012, 18:00
AW: Re: [Help] OnPlayerConnect public. - by Nero_3D - 19.05.2012, 18:19
Re: AW: Re: [Help] OnPlayerConnect public. - by Firo - 19.05.2012, 20:41
Re: [Help] OnPlayerConnect public. - by [FMJ]PowerSurge - 19.05.2012, 21:09
Re: [Help] OnPlayerConnect public. - by Firo - 20.05.2012, 09:54
Re: [Help] OnPlayerConnect public. - by [FMJ]PowerSurge - 20.05.2012, 11:54
Re: [Help] OnPlayerConnect public. - by Firo - 20.05.2012, 12:32
Re: [Help] OnPlayerConnect public. - by [FMJ]PowerSurge - 20.05.2012, 12:49
Re: [Help] OnPlayerConnect public. - by Firo - 20.05.2012, 12:50

Forum Jump:


Users browsing this thread: 3 Guest(s)