4 symbols.
#1

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

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
Reply
#3

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

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.");
Reply
#5

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

Thanks a lot. All works.
Reply
#7

no problem enjoy
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)