Command
#1

Can someone tell me why this doesn't work?

pawn Код:
if(!strcmp(sub_cmd, "sms"))
    {
        new targetid, number, text[128];
       
        if (sscanf(params, "ds[128]", number, text)) return SCM(playerid, COLOR_LIGHTRED, "* [USAGE]: /phone sms [phone number] [message]");

        if (!number) return SCM(playerid, COLOR_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(playerid, COLOR_LIGHTRED, "* The recipient has their phone powered OFF.");
       
        if ((targetid = GetNumberOwner(number)))
    {
        GivePlayerMoney(playerid, -1);
        SetMoneyInfo(playerid, 1, false, 2000);
       
        ShowPlayerFooter(playerid, "You've been ~r~charged~w~ $1 to send a text.");

        SendClientMessageEx(targetid, COLOR_YELLOW, "[TEXT]: %s - %s (%d)", text, ReturnName(playerid, 0), Player[playerid][PhoneNumber]);
        SendClientMessageEx(playerid, COLOR_YELLOW, "[TEXT]: %s - %s (%d)", text, ReturnName(playerid, 0), Player[playerid][PhoneNumber]);

        PlayerPlaySound(targetid, 1057, 0.0, 0.0, 0.0);
       
        SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "* %s takes out %s phone and sends a text.", ReturnName(playerid, 0), CheckSex(playerid));
    }
I do /phone sms 61333 (my ig phone number) test and doesn't work. No messages or anything.
Reply
#2

Код:
if ((targetid = GetNumberOwner(number)))
to

Код:
if (targetid == GetNumberOwner(number))
By the way you should show us the entire code of "GetNumberOwner" and stuff like this since the code is a mess.
Reply
#3

Post the code GetNumberOwner.
Reply
#4

Nope, same problem. GetNumberOwner:

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

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;
}
Reply
#6

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.
Reply
#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
#8

Nothing, same problem. No messages at all
Reply
#9

Try this

Код:
	if(!strcmp(sub_cmd, "sms"))
    {
		new targetid, number, text[128];

		if (sscanf(params, "ds[128]", number, text)) return SCM(playerid, COLOR_LIGHTRED, "* [USAGE]: /phone sms [phone number] [message]");

		if (targetid == INVALID_PLAYER_ID) return SCM(playerid, COLOR_LIGHTRED, "* The specified phone number is not in service.");

		if (Player[targetid][PhoneStatus] == 0) return SCM(playerid, COLOR_LIGHTRED, "* The recipient has their phone powered OFF.");

        if (Player[targetid][PhoneNumber] == number && Player[targetid][HasPhone] == 1)
		{
	        GivePlayerMoney(playerid, -1);
	        SetMoneyInfo(playerid, 1, false, 2000);

			ShowPlayerFooter(playerid, "You've been ~r~charged~w~ $1 to send a text.");

			SendClientMessageEx(targetid, COLOR_YELLOW, "[TEXT]: %s - %s (%d)", text, ReturnName(playerid, 0), Player[playerid][PhoneNumber]);
			SendClientMessageEx(playerid, COLOR_YELLOW, "[TEXT]: %s - %s (%d)", text, ReturnName(playerid, 0), Player[playerid][PhoneNumber]);

	        PlayerPlaySound(targetid, 1057, 0.0, 0.0, 0.0);

			SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "* %s takes out %s phone and sends a text.", ReturnName(playerid, 0), CheckSex(playerid));
		}
	 }
Reply
#10

I was missing sub_params. It works now. Thanks everyone.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)