check for a exact string
#1

Hi everyone,

The title may sound a little strange, so let me explain what the problem is here.
If someone wants to buy a house, they get a dialog where they have to type the exact house adress they want to buy.
I use strcmp to do this, here is my code:
pawn Code:
if(strcmp(inputtext,HInfo[i][Streetname],false) != -1)
So, when I test this, the following happens:

I type the adress in the dialog, but incomplete.
Let's say I want to buy house adress "51.Main Street", if I type, 5.Mainstreet(5.Mainstreet does not exist), it buys one of the houses with "main street" in the adress.

Now, the big question, how can I make the script check the exact string, so that it will only buy if it is the exact adress?


Thanks in advance
Reply
#2

new address[128];
format(address, 128, "%d.%s", housenumber, streetname);

Use that replace housenumber and streetname and use cstrcmp with address and inputtext
Reply
#3

Quote:
Originally Posted by ikkentim
View Post
new address[128];
format(address, 128, "%d.%s", housenumber, streetname);

Use that replace housenumber and streetname and use cstrcmp with address and inputtext
thanks for the reply

I tried this before, but when I type in housenumber, for example , 5 (which doesn't exist) , it buys a random house from the street i chose..
I will try it again though, maybe I find something when i'm scripting it..

Thanks
Reply
#4

to check if strings are the same, you need to check if strcmp returns 0 or not

https://sampwiki.blast.hk/wiki/Strcmp
Reply
#5

pawn Code:
if(!strcmp(inputtext,HInfo[i][Streetname],true))
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)