4 symbols. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: 4 symbols. (
/showthread.php?tid=156559)
4 symbols. -
DyDy - 23.06.2010
Hello. I'm trying to do house system. I need house key with 4 numbers. I'm doing it with GUI. But I don't know how to do that player could only type 4 numbers. If there would be any letters, server would send message with explain, and if there would be too little or too much numbers message would be sent too. I hope you understand me.
Re: 4 symbols. -
(SF)Noobanatior - 23.06.2010
do you want to know if a player types a string are they all numbers?
Код:
stock isNumeric(const string[]) {
new length=strlen(string);
if (length==0) return false;
for (new i = 0; i < length; i++) {
if (
(string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
|| (string[i]=='-' && i!=0) // A '-' but not at first.
|| (string[i]=='+' && i!=0) // A '+' but not at first.
) return false;
}
if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
return true;
}
NOTE: thanks Dracoblue
Re: 4 symbols. -
DyDy - 23.06.2010
Quote:
Originally Posted by (SF)Noobanatior
do you want to know if a player types a string are they all numbers?
|
Yes, I'll try it.
Re: 4 symbols. -
DyDy - 23.06.2010
Thanks, you're really helped me. But I still have one problem. How to do something like that?
Код:
if(numbers < 4 || numbers > 4) return SendClientMessage(playerid, white,"Code must be of 4 numbers.");
Re: 4 symbols. -
(SF)Noobanatior - 23.06.2010
Quote:
Originally Posted by DyDy
Thanks, you're really helped me. But I still have one problem. How to do something like that?
Код:
if(numbers < 4 || numbers > 4) return SendClientMessage(playerid, white,"Code must be of 4 numbers.");
|
Код:
if(strlen(cmdtext) == 4 && isNumeric(cmdtext)) {
// input is 4 char long and numbers
}
Re: 4 symbols. -
DyDy - 23.06.2010
Thanks a lot. All works.
Re: 4 symbols. -
(SF)Noobanatior - 23.06.2010
no problem

enjoy