why is this little command not working? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: why is this little command not working? (
/showthread.php?tid=609698)
why is this little command not working? -
MayaEU - 15.06.2016
hello, i hope that anyone of you can help me
this command does not work correctly
pawn Code:
if (strcmp(cmd, "/phnumber", true) == 0)
{
new string[40];
new phnumber[20];
switch(PlayerInfo[targetid][pPnumber])
{
default: phnumber = "None";
}
format(string, sizeof(string), "Your phone number is %d",phnumber);
SendClientMessage(playerid, COLOR_GREY,string);
return 1;
}
Re: why is this little command not working? -
oMa37 - 15.06.2016
nvm.
Re: why is this little command not working? -
biker122 - 15.06.2016
#EDIT:
Believing that the phone number is a numeric value, and is NON-ZERO - this code should work.
pawn Code:
if (strcmp(cmd, "/phnumber", true) == 0)
{
new string[40];
new phnumber[20];
if(PlayerInfo[targetid][pPnumber] == 0) format(phnumber, 20, None);
else if(PlayerInfo[targetid][pPnumber] != 0) format(phnumber, "%i", PlayerInfo[targetid][pPnumber]);
format(string, sizeof(string), "Your phone number is %s",phnumber);
SendClientMessage(playerid, COLOR_GREY,string);
return 1;
}
The code is untested, yet it should work fine.
I have changed '%d' to '%s' while formatting the 'string' because, phnumber is a string and not a integer/numeric value.
Re: why is this little command not working? -
Stinged - 15.06.2016
Quote:
Originally Posted by biker122
#EDIT:
Believing that the phone number is a numeric value, and is NON-ZERO - this code should work.
pawn Code:
if (strcmp(cmd, "/phnumber", true) == 0) { new string[40]; new phnumber[20]; if(PlayerInfo[targetid][pPnumber] == 0) format(phnumber, 20, None); else if(PlayerInfo[targetid][pPnumber] != 0) format(phnumber, "%i", PlayerInfo[targetid][pPnumber]); format(string, sizeof(string), "Your phone number is %s",phnumber); SendClientMessage(playerid, COLOR_GREY,string); return 1; }
The code is untested, yet it should work fine.
I have changed '%d' to '%s' while formatting the 'string' because, phnumber is a string and not a integer/numeric value.
|
Why would you even need phnumber?
Code:
new string[40];
if(PlayerInfo[targetid][pPnumber] == 0) strcat(string, "You don't have a phone number.");
else format(string, sizeof(string), "Your phone number is %i", PlayerInfo[targetid][pPnumber]);
SendClientMessage(playerid, COLOR_GREY,string);
But I don't get why you're using targetid MayaEU, I mean you're telling the player that his (the player's) number is [number], but you're getting the number of someone else (targetid).