Command
#7

Quote:
Originally Posted by kingmk
Посмотреть сообщение
Change this

Код:
GetNumberOwner(number)
{
	foreach (new i : Player) if (Player[i][PhoneNumber] == number && Player[i][HasPhone] == 1)
	{
		return i;
	}
	return INVALID_PLAYER_ID;
}
TO

Код:
GetNumberOwner(number)
{
        new ID = -1;
	for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) //You can use foreach here if u want.
	{
              if(Player[i][PhoneNumber] == number && Player[i][HasPhone] == 1)
              {
                     ID = i;
                     break;
              }
	}
	return ID;
}
That's exactly same as he doing now.return does breaks the control flow.
Quote:
Originally Posted by GTLS
Посмотреть сообщение
PHP код:
GetNumberOwner(number)
{
    foreach (new 
Player)
        {
              if (
Player[i][PhoneNumber] == number && Player[i][HasPhone] == 1)
          {
             return 
i;
          }
    return 
INVALID_PLAYER_ID;
      }

Brackets are only excluded when you have only 1 statement.

Edit: sorry for bad formatting. idk how did it happen.
That's wrong it will lead the function to return INVALID_PLAYER_ID if the first iteration fails the if condition,and the loop will only execute once.And "Brackets" can be excluded in this case as the one following it is an another block (if in this case).

@OP

PHP код:
new targetid,.....; 
you are declaring targetid but not giving it any value before using it in the above mentioned if statement.On declaration it's value is zero unless you provided any other value.You should get targetid from the number using GetNumberOwner before using it.

PHP код:
    if(!strcmp(sub_cmd"sms"))
    {
        new 
targetidnumbertext[128];
        
        if (
sscanf(params"ds[128]"numbertext)) return SCM(playeridCOLOR_LIGHTRED"* [USAGE]: /phone sms [phone number] [message]");
        
        
targetid GetNumberOwner(number);
        
        if (
targetid == INVALID_PLAYER_ID) return SCM(playeridCOLOR_LIGHTRED"* The specified phone number is not in service.");
        
        
//if (targetid == playerid) return SCM(playerid, COLOR_LIGHTRED, "* You can't text yourself.");
        
        
if (Player[targetid][PhoneStatus] == 0) return SCM(playeridCOLOR_LIGHTRED"* The recipient has their phone powered OFF.");
        
        
        
GivePlayerMoney(playerid, -1);
        
SetMoneyInfo(playerid1false2000);
        
        
ShowPlayerFooter(playerid"You've been ~r~charged~w~ $1 to send a text.");
        
SendClientMessageEx(targetidCOLOR_YELLOW"[TEXT]: %s - %s (%d)"textReturnName(playerid0), Player[playerid][PhoneNumber]);
        
SendClientMessageEx(playeridCOLOR_YELLOW"[TEXT]: %s - %s (%d)"textReturnName(playerid0), Player[playerid][PhoneNumber]);
        
PlayerPlaySound(targetid10570.00.00.0);
        
        
SendNearbyMessage(playerid30.0COLOR_PURPLE"* %s takes out %s phone and sends a text."ReturnName(playerid0), CheckSex(playerid));
    } 
Reply


Messages In This Thread
Command - by KinderClans - 21.09.2018, 09:40
Re: Command - by Flamehaze7 - 21.09.2018, 09:53
Re: Command - by GTLS - 21.09.2018, 13:03
Re: Command - by KinderClans - 21.09.2018, 13:25
Re: Command - by kingmk - 21.09.2018, 13:59
Re: Command - by GTLS - 22.09.2018, 07:06
Re: Command - by SyS - 22.09.2018, 07:27
Re: Command - by KinderClans - 22.09.2018, 12:55
Re: Command - by UFF - 22.09.2018, 13:14
Re: Command - by KinderClans - 22.09.2018, 13:44

Forum Jump:


Users browsing this thread: 1 Guest(s)