SA-MP Forums Archive
Need help with House Search in gps - 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: Need help with House Search in gps (/showthread.php?tid=654625)

Pages: 1 2


Need help with House Search in gps - ImTobi - 01.06.2018

Код:
if(dialogid == NAVIDIALOGHAUS)
	{
		if(response)
		{
			for(new i=0; i<sizeof(hausInfo); i++)
			{
				if(!IsNumeric(inputtext))return SendClientMessage(playerid, COLOR_RED, "Du kannst nur Zahlen eingeben.");
				if(strval(inputtext) == hausInfo[i][hausnummer])
				{
					SetPlayerCheckpoint(playerid, hausInfo[i][hx], hausInfo[i][hy], hausInfo[i][hz], 5);
					SendClientMessage(playerid, COLOR_WHITE, "Das Haus wurde auf der Karte markiert.");	
					return 1;
				}
				else
				{
					SendClientMessage(playerid, COLOR_RED, "Die Hausnummer gibt es nicht.");
					break;
				}
				return 1;
			}
		}
		else
		{
			return 1;
		}
	}
But it says everytime that the house is not existing, or the housnumber


Re: Need help with House Search in gps - DarkSkull - 02.06.2018

Yes. That will happen as what your code does is that if the houseid is not found, It will break the loop. For example, if houseid 0 doesn't exists and 1 exists, It will stop the loop at 0. Try this

PHP код:
if(dialogid == NAVIDIALOGHAUS)
    {
        if(
response)
        {
            for(new 
i=0i<sizeof(hausInfo); i++)
            {
                if(!
IsNumeric(inputtext))return SendClientMessage(playeridCOLOR_RED"Du kannst nur Zahlen eingeben.");
                if(
strval(inputtext) == hausInfo[i][hausnummer])
                {
                    
SetPlayerCheckpoint(playeridhausInfo[i][hx], hausInfo[i][hy], hausInfo[i][hz], 5);
                    
SendClientMessage(playeridCOLOR_WHITE"Das Haus wurde auf der Karte markiert.");    
                    return 
1;
                }
            }

            return 
SendClientMessage(playeridCOLOR_RED"Die Hausnummer gibt es nicht.");
        }
        else
        {
            return 
1;
        }
    } 



Re: Need help with House Search in gps - GTLS - 02.06.2018

Dont run the loop size of HInfo. Run it to MAX_HOUSES.

PHP код:
//Define this if you dont have to number of your max houses.
#define MAX_HOUSES 200

for(new i=0i<sizeof(MAX_HOUSES); i++) 



Re: Need help with House Search in gps - ImTobi - 02.06.2018

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
Yes. That will happen as what your code does is that if the houseid is not found, It will break the loop. For example, if houseid 0 doesn't exists and 1 exists, It will stop the loop at 0. Try this

PHP код:
if(dialogid == NAVIDIALOGHAUS)
    {
        if(
response)
        {
            for(new 
i=0i<sizeof(hausInfo); i++)
            {
                if(!
IsNumeric(inputtext))return SendClientMessage(playeridCOLOR_RED"Du kannst nur Zahlen eingeben.");
                if(
strval(inputtext) == hausInfo[i][hausnummer])
                {
                    
SetPlayerCheckpoint(playeridhausInfo[i][hx], hausInfo[i][hy], hausInfo[i][hz], 5);
                    
SendClientMessage(playeridCOLOR_WHITE"Das Haus wurde auf der Karte markiert.");    
                    return 
1;
                }
            }
            return 
SendClientMessage(playeridCOLOR_RED"Die Hausnummer gibt es nicht.");
        }
        else
        {
            return 
1;
        }
    } 

It works, but on the housenumber 1 every second time it sets the checkpoint to blueberry acres (0.0,0.0,0.0)


Re: Need help with House Search in gps - ImTobi - 02.06.2018

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Dont run the loop size of HInfo. Run it to MAX_HOUSES.

PHP код:
//Define this if you dont have to number of your max houses.
#define MAX_HOUSES 200
for(new i=0i<sizeof(MAX_HOUSES); i++) 
Код:
C:\Users\Tobias\Desktop\SAMPServer\pawno\include\sscanf2.inc(149) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\SAMPServer\pawno\include\sscanf2.inc(193) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\SAMPServer\pawno\include\playerzone.inc(422) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\SAMPServer\pawno\include\playerzone.inc(445) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(781) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(968) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1059) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1086) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1148) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1223) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1700) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1704) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1708) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1712) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1718) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1730) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1734) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1740) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1746) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1753) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1757) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1839) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1864) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1924) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(1933) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(2487) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(3051) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(3098) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(3109) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(3132) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(3142) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(3149) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(3865) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(4214) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(4214) : error 020: invalid symbol name ""
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(4214) : error 036: empty statement
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(4214) : error 017: undefined symbol "i"
C:\Users\Tobias\Desktop\Scripting Server\gamemodes\Reallife.pwn(4214) : fatal error 107: too many error messages on one line

Compilation aborted.

Pawn compiler 3.2.3664	 	 	Copyright © 1997-2017, ITB CompuPhase


4 Errors.
[Finished in 0.6s]
Because MAX_HOUSES Doesn't work for some reason


Re: Need help with House Search in gps - ImTobi - 02.06.2018

help? i need it fast


Re: Need help with House Search in gps - GTLS - 03.06.2018

Those errors are not because of MAX_HOUSES. This is because of something else. Probably a misplaced bracket.


Re: Need help with House Search in gps - ImTobi - 03.06.2018

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Those errors are not because of MAX_HOUSES. This is because of something else. Probably a misplaced bracket.
No it must be <MAX_HOUSES not <sizeof(MAX_HOUSES) But it didn't fix my problem, it still sets the checkpoint to blueberry every 2 times i enter the number


Re: Need help with House Search in gps - GTLS - 03.06.2018

Yeah sorry I forgot. It should be <MAX_HOUSES.

PHP код:
if(dialogid == NAVIDIALOGHAUS
    { 
        if(
response
        { 
            new 
i;
            for(
i=0i<MAX_HOUSESi++) 
            { 
                if(!
IsNumeric(inputtext))return SendClientMessage(playeridCOLOR_RED"Du kannst nur Zahlen eingeben."); 
                if(
strval(inputtext) == hausInfo[i][hausnummer]) 
                { 
                    
SetPlayerCheckpoint(playeridhausInfo[i][hx], hausInfo[i][hy], hausInfo[i][hz], 5); 
                    
SendClientMessage(playeridCOLOR_WHITE"Das Haus wurde auf der Karte markiert.");  
                        break;
                }                
            }
            if(
== MAX_HOUSES) return SendClientMessage(playeridCOLOR_RED"Die Hausnummer gibt es nicht."); 
            return 
1;
        } 
        return 
1;
    } 
Try this?


Re: Need help with House Search in gps - ImTobi - 03.06.2018

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Yeah sorry I forgot. It should be <MAX_HOUSES.

PHP код:
if(dialogid == NAVIDIALOGHAUS
    { 
        if(
response
        { 
            new 
i;
            for(
i=0i<MAX_HOUSESi++) 
            { 
                if(!
IsNumeric(inputtext))return SendClientMessage(playeridCOLOR_RED"Du kannst nur Zahlen eingeben."); 
                if(
strval(inputtext) == hausInfo[i][hausnummer]) 
                { 
                    
SetPlayerCheckpoint(playeridhausInfo[i][hx], hausInfo[i][hy], hausInfo[i][hz], 5); 
                    
SendClientMessage(playeridCOLOR_WHITE"Das Haus wurde auf der Karte markiert.");  
                        break;
                }                
            }
            if(
== MAX_HOUSES) return SendClientMessage(playeridCOLOR_RED"Die Hausnummer gibt es nicht."); 
            return 
1;
        } 
        return 
1;
    } 
Try this?
It works now, but if i type "6" in no error is coming that the house isnt existing


Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at index 1000 in array of size 1000
[debug] AMX backtrace:
[debug] #0 0003c658 in public OnDialogResponse (0, 48, 1, -1, 2993040) from Reallife.amx
[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at index 1000 in array of size 1000
[debug] AMX backtrace:
[debug] #0 0003c658 in public OnDialogResponse (0, 48, 1, -1, 2993040) from Reallife.amx
[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at index 1000 in array of size 1000
[debug] AMX backtrace:
[debug] #0 0003c658 in public OnDialogResponse (0, 48, 1, -1, 2993040) from Reallife.amx
And this is in console


Re: Need help with House Search in gps - GTLS - 03.06.2018

Add this:
PHP код:
if(!housInfo[strval(inputtext)][hx]) SendClientMessage(playerid, -1"That house doesnt exist"); 



Re: Need help with House Search in gps - ImTobi - 03.06.2018

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Add this:
PHP код:
if(!housInfo[strval(inputtext)][hx]) SendClientMessage(playerid, -1"That house doesnt exist"); 
It doesn't work :c


Re: Need help with House Search in gps - ImTobi - 03.06.2018

whyyyyyyy


Re: Need help with House Search in gps - ImTobi - 05.06.2018

bump, please help


Re: Need help with House Search in gps - ImTobi - 07.06.2018

? someone


Re: Need help with House Search in gps - Beckett - 07.06.2018

You need to ensure the house exists before even checking for the number. For instance, if a player inputs 0 for example, all houses that aren't created will be considered in the loop.


Re: Need help with House Search in gps - ImTobi - 08.06.2018

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
You need to ensure the house exists before even checking for the number. For instance, if a player inputs 0 for example, all houses that aren't created will be considered in the loop.
I will try it, thanks.
I thought checking the housnumber is the same.
I will check back later, and tell you if it worked


Re: Need help with House Search in gps - jasperschellekens - 08.06.2018

wtf is this:
PHP код:
new i
for(
i=0i<MAX_HOUSESi++) 
Im pretty sure that is not a way to fix a local var shadowing.

PHP код:
for(new d=0HOUSESd++) 



Re: Need help with House Search in gps - ImTobi - 08.06.2018

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
wtf is this:
PHP код:
new i
for(
i=0i<MAX_HOUSESi++) 
Im pretty sure that is not a way to fix a local var shadowing.

PHP код:
for(new d=0HOUSESd++) 
No the shadowing was because i defined MAX_HOUSES Wrong, but it still doesnt work correctly, u think i should remove it?


Re: Need help with House Search in gps - Logic_ - 09.06.2018

Sometimes, mistakes in some codes can also lead to lots of warnings, so you check the compiler log and fix the errors that you've got, and then attempt to fix other errors that may pop up.

Your script will not compile if you've errors, but it'll still compile if you're warnings. So more priority should be given to the errors, this doesn't mean that you completely ignore them, but yet, as I said before in my first paragraph.

--

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Dont run the loop size of HInfo. Run it to MAX_HOUSES.

PHP код:
//Define this if you dont have to number of your max houses.
#define MAX_HOUSES 200
for(new i=0i<sizeof(MAX_HOUSES); i++) 
This code is, in fact, wrong. sizeof can only be used for variables, not pre-processor defines. However, both are valid, i < sizeof HausInfo or i < MAX_HOUSES.

Please think for a minute before you post.

--

The code of yours @OP, is slow.

You're running the loop the times of the MAX_HOUSES/ size of the House array, then you're converting the string (inputtext) to an integer and then comparing it, just convert the stuff beforehand you run the loop.

PHP код:
if(dialogid == NAVIDIALOGHAUS)
{
    if (!
response) return 1;
    if(!
IsNumeric(inputtext)) return SendClientMessage(playeridCOLOR_RED"Du kannst nur Zahlen eingeben.");
    new 
value strval(inputtext);
    for(new 
i=0i<sizeof(hausInfo); i++)
    {
        if(
value == hausInfo[i][hausnummer])
        {
            
SetPlayerCheckpoint(playeridhausInfo[i][hx], hausInfo[i][hy], hausInfo[i][hz], 5);
            
SendClientMessage(playeridCOLOR_WHITE"Das Haus wurde auf der Karte markiert.");    
            return 
1;
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"Die Hausnummer gibt es nicht.");
            break;
        }
        return 
1;
    }

A good tip for you'll be that you decrease the usage of brackets, and make your statements straight forward, like in my code!

However, there may be other errors in the code since I've just assumed some stuff on my own since I don't know what the original 'HausInfo' variable is.