Phone system /sms
#1

Hi, i'm making a phone system, but the /sms cmd dosn't work. When you type /sms <Number> <Text> it says "Invalid Number" So i'm pretty sure it's my stock (NumberUsed) that's the problem.

/sms cmd
Код:
dcmd_sms(playerid,params[])
{
	new number,text[50],name[MAX_PLAYER_NAME],pid,name2[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,sizeof(name));
	GetPlayerName(pid,name2,sizeof(name2));
	if(sscanf(params,"ds",number,text)) return SendClientMessage(playerid,COLOUR_RED,"Usage: /sms <phonenumber> <text chat>!");
	if(number <= 3) return SendClientMessage(playerid,COLOUR_RED,"Usage: /sms [number] [text]!");
	if(GetPlayerMoney(playerid) <= 0) return SendClientMessage(playerid,COLOUR_RED,"You need $5 to send a sms!");
	if(NumberUsed(pid)) return SendClientMessage(playerid,COLOUR_RED,"[Voicemail]: Invalid Number!");
	{
		new str[128];
		format(str,sizeof(str),"[SMS](%s): %s",name,text);
		SendClientMessage(pid,COLOUR_YELLOW,str);
		SendClientMessage(playerid,COLOUR_GREEN,"Text Message Delivered");
		GivePlayerMoney(playerid,-5);
		GameTextForPlayer(playerid,"Cost 5$",5000,1);
	}
	return 1;
}
Stock:
Код:
stock NumberUsedT(playerid)
{
	new name[MAX_PLAYER_NAME],number,pid;
	for(new i = 0; i < MAX_PLAYERS; i ++)
	{
	  number = pi[i][pNumber];
		GetPlayerName(i,name,sizeof(name));
		format(file,sizeof(file),"%s.ini",name);
		if(number == dini_Int(file,"Number")) return 1;
	}
	return 0;
}
Hopefully someone can see the error(s)

- Naxix

P.S This is my first stock :b
Reply
#2

I don't really get the meaning of your function code wise.

You pass a playerid as a parameter which you don't use in your function at all, create a variable "pid" inside that function which you neither use. There are two ways numbers are being stored (at least I guess) -> pi[playerid][pNumber] and dini_Int(file,"Number") allthough during session you only need one of them.

In your sms command, you declare in the beginning a variable called pid which is by default 0.

Using GetPlayerName(pid,name2,sizeof(name2)); stores the playername of id 0 in name2.

I stop here for now and simply ask, is all that on purpose?
Reply
#3

Quote:
Originally Posted by juice.j
I don't really get the meaning of your function code wise.

You pass a playerid as a parameter which you don't use in your function at all, create a variable "pid" inside that function which you neither use. There are two ways numbers are being stored (at least I guess) -> pi[playerid][pNumber] and dini_Int(file,"Number") allthough during session you only need one of them.

In your sms command, you declare in the beginning a variable called pid which is by default 0.

Using GetPlayerName(pid,name2,sizeof(name2)); stores the playername of id 0 in name2.

I stop here for now and simply ask, is all that on purpose?
Hmm.. No, that was not the meaning. :b I normally use pid as target playerid.
Reply
#4

Well you just mixed up some things I guess.

If you store each player number in a variable pi[playerid][pNumber] just use that as reference, you don't need to compare the file data additionally (if I assume correctly and you store the number of each player file in that variable upon OnPlayerConnect).

Just try something like this:

Код:
NumberUsedT(number)
{
	for(new i = 0; i < MAX_PLAYERS; i ++)
		if(number==pi[i][pNumber])
			return 1;
	return 0;
}
(( I can only assume how your datamanagement / variables are set up, hence - adjust as necessary.
Reply
#5

Quote:
Originally Posted by juice.j
Well you just mixed up some things I guess.

If you store each player number in a variable pi[playerid][pNumber] just use that as reference, you don't need to compare the file data additionally (if I assume correctly and you store the number of each player file in that variable upon OnPlayerConnect).

Just try something like this:

Код:
NumberUsedT(number)
{
	for(new i = 0; i < MAX_PLAYERS; i ++)
		if(number==pi[i][pNumber])
			return 1;
	return 0;
}
(( I can only assume how your datamanagement / variables are set up, hence - adjust as necessary.
Lol, thanks! I forgot i only need to check the online players :b
Reply
#6

Right, add an if(IsPlayerConnected(i)) below for(...

Forgot that. Doesn't make that much difference, however if you should forget to reset variables upon OnPlayerDisconnect you do not run into problems, if not connected playerids are being ignored.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)