My phone script crashes my server :(
#1

Hello everybody, I made this phone script but /sms somehow crashes the server when someone uses /sms. anyone know the reason for this?

Code:
CMD:sms(playerid, params[])
{
	if(PlayerInfo[playerid][Phone] == phone_yes)
	{
	    if(phoneon[playerid] == true)
	    {
			new text;
			new pnumber;
	        if(!sscanf(params, "is", pnumber, text))
	        {
				foreach(Player, i)
				{
					if(PlayerInfo[i][Phone] == phone_yes)
					{
						if(PlayerInfo[i][PhoneNumber] == pnumber)
			    		{
			    			if(phoneon[i] == true)
   							{
			    		    	new string[265], string2[265];
			    		    	new pnumber2;
			    		    	pnumber2 = PlayerInfo[playerid][PhoneNumber];
			    		    	format(string, sizeof(string), "[SMS]%i: %s.", pnumber2, text);
			    		    	SendClientMessage(i, TEAM_RADIO_COLOR, string);
			    		    	format(string2, sizeof(string2), "You just sended a text message to %i", pnumber);
			    		    	SendClientMessage(playerid, TEAM_RADIO_COLOR, string2);
	    	        			PlayerPlaySound(i,1085,0.0,0.0,0.0);
	    	        			return 1;
	    	        		}
	    	        		else return SendClientMessage(playerid, COLOR_GREY, "This player has his/her phone turned off!");
	    	        	}
	    	        	return 1;
					}
				}
				return 1;
			}
			else return SendClientMessage(playerid, COLOR_GREY, "USAGE: /sms [Phone Number] [SMS text]");
		}
		else return SendClientMessage(playerid, COLOR_GREY, "You have your phone turned off!");
	}
	else return SendClientMessage(playerid, COLOR_GREY, "You don't have a phone!");
}
Reply
#2

Updated it: Still wont work

PHP Code:
CMD:sms(playeridparams[])
{
    if(
PlayerInfo[playerid][Phone] == phone_yes)
    {
        if(
phoneon[playerid] == true)
        {
            new 
text;
            new 
pnumber;
            if(!
sscanf(params"is"pnumbertext))
            {
                foreach(
Playeri)
                {
                    if(
PlayerInfo[i][Phone] == phone_yes)
                    {
                        if(
PlayerInfo[i][PhoneNumber] == pnumber)
                        {
                            if(
phoneon[i] == true)
                               {
                                new 
string[265], string2[265];
                                new 
pnumber2;
                                
pnumber2 PlayerInfo[playerid][PhoneNumber];
                                
format(stringsizeof(string), "[SMS]%i: %s."pnumber2text);
                                
SendClientMessage(iTEAM_RADIO_COLORstring);
                                
format(string2sizeof(string2), "You just sended a text message to %i"pnumber);
                                
SendClientMessage(playeridTEAM_RADIO_COLORstring2);
                                
PlayerPlaySound(i,1085,0.0,0.0,0.0);
                                return 
1;
                            }
                            else return 
SendClientMessage(playeridCOLOR_GREY"This player has his/her phone turned off!");
                        }
                        return 
1;
                    }
                }
                return 
1;
            }
            else return 
SendClientMessage(playeridCOLOR_GREY"USAGE: /sms [Phone Number] [SMS text]");
        }
        else return 
SendClientMessage(playeridCOLOR_GREY"You have your phone turned off!");
    }
    else return 
SendClientMessage(playeridCOLOR_GREY"You don't have a phone!");

Reply
#3

You are trying to store the message in an INTEGER variable, declare a string instead

pawn Code:
CMD:sms(playerid, params[])
{
    if(PlayerInfo[playerid][Phone] == phone_yes)
    {
        if(phoneon[playerid] == true)
        {
            new text[128]; //<-----
            new pnumber;
            if(!sscanf(params, "is[128]", pnumber, text)) //You need to put the string size!
            {
                foreach(Player, i)
                {
                    if(PlayerInfo[i][Phone] == phone_yes)
                    {
                        if(PlayerInfo[i][PhoneNumber] == pnumber)
                        {
                            if(phoneon[i] == true)
                               {
                                new string[128];
                                format(string, sizeof(string), "[SMS]%i: %s.", PlayerInfo[playerid][PhoneNumber], text);
                                SendClientMessage(i, TEAM_RADIO_COLOR, string);
                                //You can reuse the string here, as you already sent the other message
                                format(string, sizeof(string), "You just sended a text message to %i", pnumber);
                                SendClientMessage(playerid, TEAM_RADIO_COLOR, string);
                                PlayerPlaySound(i,1085,0.0,0.0,0.0);
                                return 1;
                            }
                            else return SendClientMessage(playerid, COLOR_GREY, "This player has his/her phone turned off!");
                        }
                        return 1;
                    }
                }
                return 1;
            }
            else return SendClientMessage(playerid, COLOR_GREY, "USAGE: /sms [Phone Number] [SMS text]");
        }
        else return SendClientMessage(playerid, COLOR_GREY, "You have your phone turned off!");
    }
    else return SendClientMessage(playerid, COLOR_GREY, "You don't have a phone!");
}
EDIT: There is no need of having 2 strings with size 265.... See this: https://sampforum.blast.hk/showthread.php?tid=55261
Reply
#4

Thanks Still some things to learn for me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)