Help with: /myhouses command.
#1

Hello there guys and Happy New Year !
I have a problem with command: /myhouses.
I doesn't have this command at my houses system, so
how i created the system i created /myhouses command also now.
So the problem is that. I don't know why when i select from /myhouses dialog
the house that i want to teleport, it's teleporting me to the next house from the dialog.

Command:
Код:
CMD:myhouses( playerid, params[ ] )
{
 	new query[ 200 ];
    mysql_format( DB_Connect, query, sizeof( query ), "SELECT ID, HouseName, HousePassword FROM houses WHERE HouseOwner = '%s'", PlayerName( playerid ) );
	mysql_query( DB_Connect, query );
	
	eBigString[ 0 ] = EOS;
	new rows = cache_num_rows( );
	
	if( rows )
	{
 		new id, hn[ MAX_HOUSE_NAME ], hp[ MAX_HOUSE_PASSWORD ];
   		format( eBigString, sizeof( eBigString ), "{FFFFFF}#\t{FFFFFF}House Name\t{FFFFFF}ID\t{FFFFFF}Password\n");
	    for( new i; i < rows; ++i )
	    {
	        id = cache_get_field_content_int( i, "ID" );
	        cache_get_field_content( i, "HouseName", hn );
	        cache_get_field_content( i, "HousePassword", hp );
	        PlayerInfo[ playerid ][ Momentan_House_ID ] = i;
	        
	        format( eBigString, sizeof( eBigString ), "%s{FFFFFF}#\t%s\t%d\t%s\n", eBigString, hn, id, hp );
	    }
		ShowPlayerDialog( playerid, DIALOG_HOUSES_TELEPORT, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}My Houses:", eBigString, "Select", "Exit" );
	}
	else
	{
		SendError( playerid, "You don't have any Houses" );
	}
	return 1;
}
Dialogs:
Код:
ase DIALOG_HOUSES_TELEPORT:
		{
			if( response )
			{
    			new message[ 7000 ];
				new count = 0;

				for( new i = 0; i < MAX_HOUSES; i++ )
				{
     				if( !strcmp( HouseData[ i ][ Owner ], PlayerName( playerid ) ) )
					{
	     				if( count == listitem )
						{
							PlayerInfo[ playerid ][ Momentan_House_ID ] = i;
       						format( message, sizeof( message ), "{FFFFFF}%s (ID: {C0C0C0}%d {FFFFFF}):", HouseData[ i ][ Name ], i );
							ShowPlayerDialog( playerid, DIALOG_HOUSES_TELEPORT_2, DIALOG_STYLE_LIST, message, "{FFFFFF}Teleport to House", "Select", "Back" );
       						break;
						}
      					else
						{
							count ++;
						}
					}
				}
   			}
		}
		case DIALOG_HOUSES_TELEPORT_2:
		{
			if( response )
			{
				new i = PlayerInfo[ playerid ][ Momentan_House_ID ];
				switch( listitem )
				{
					case 0:
					{
          				SetPVarInt( playerid, "HousePickupCooldown", gettime( ) + HOUSE_COOLDOWN );
						SetPlayerPos( playerid, HouseData[ i ][ houseX ], HouseData[ i ][ houseY ], HouseData[ i ][ houseZ ] );
						SetPlayerInterior( playerid, 0 );
						SetPlayerVirtualWorld( playerid, 0 );
						
						FormatMSG( playerid, 0xC0C0C0FF, "[INFO]: {FFFFFF}You've been teleported to: {FFFFFF}'%s (ID: {C0C0C0}%d{FFFFFF})'.", HouseData[ i ][ Name ], i );
					}
				}
			}
			else
			{
				cmd_myhouses( playerid, "" );
			}
		}
OnPlayerConnect:
The Momentan_House_ID variable is setted like:
Код:
PlayerInfo[ playerid ][ Momentan_House_ID  ] = -1;
Can you help me to fix this command ?
If you know other mode how to make a command like this
to teleport to one of my houses from the dialog please tell here the solution.

More explicit:
1. When i select the First House ID: 173.
Then appear the dialog with: Teleport to House, but the Title says: [ID: 0] WHAT ?!


2. When i select Second House ID: 174.
Is teleporting me to the First House ID: 173 .. WTF?!

3. When i select Third House ID: 175
Is teleporting me to the Second House ID: 174.. :\

Dialog Picture:
Reply
#2

An option is to use house ID as first column in the dialog tab list so you can extract it from inputtext and in the loop compare integers instead of strings.
Reply
#3

I don't understand.. how to extract.. ?
Can you show me an example or.. something ..
Reply
#4

Is there a person that can help me with this ?
Please ?
Reply
#5

While formatting the houses to show the dialog, instead of using # as first column pass the house ID. In dialog response, just:
pawn Код:
new house_ID = strval(inputtext);
and loop to compare which house index has that house ID. You are supposed to save this anyway so you can update the houses.

By the way, something important: delete the cache from memory, see example: https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_query
Reply
#6

I really don't understand why you say to use inputtext.. there doesn't exist an DIALOG_STYLE_INPUT ...
For what to use that inputtext ?
Reply
#7

https://sampwiki.blast.hk/wiki/OnDialogResponse

inputtext[]The text entered into the input box by the player or the selected list item text.
In a list, it returns the whole text but with the tab (headers), it returns the text of the first column (before \t).
Reply
#8

Код:
case DIALOG_HOUSES_TELEPORT:
		{
			if( response )
			{
          		new message[ 7000 ], count = 0;
				for( new i = 0; i < MAX_HOUSES; i++ )
				{
     				if( !strcmp( HouseData[ i ][ Owner ], PlayerName( playerid ) ) )
					{
	     				if( count == listitem )
						{
       						PlayerInfo[ playerid ][ Momentan_House_ID ] = strval( inputtext );
            				format( message, sizeof( message ), "{FFFFFF}%s (ID: {C0C0C0}%d {FFFFFF}):", HouseData[ strval( inputtext ) ][ Name ], strval( inputtext ) );
							ShowPlayerDialog( playerid, DIALOG_HOUSES_TELEPORT_2, DIALOG_STYLE_LIST, message, "{FFFFFF}Teleport to House", "Select", "Back" );
   			 				break;
						}
      					else
						{
							count ++;
						}
					}
				}
   			}
		}
Код:
case DIALOG_HOUSES_TELEPORT:
		{
			if( response )
			{
          		new message[ 7000 ], count = 0;
				for( new i = 0; i < MAX_HOUSES; i++ )
				{
     				if( !strcmp( HouseData[ i ][ Owner ], PlayerName( playerid ) ) )
					{
	     				if( count == listitem )
						{
       						PlayerInfo[ playerid ][ Momentan_House_ID ] = strval( inputtext );
            				format( message, sizeof( message ), "{FFFFFF}%s (ID: {C0C0C0}%d {FFFFFF}):", HouseData[ strval( inputtext ) ][ Name ], strval( inputtext ) );
							ShowPlayerDialog( playerid, DIALOG_HOUSES_TELEPORT_2, DIALOG_STYLE_LIST, message, "{FFFFFF}Teleport to House", "Select", "Back" );
   			 				break;
						}
      					else
						{
							count ++;
						}
					}
				}
   			}
		}
Command:
Код:
CMD:myhouses( playerid, params[ ] )
{
 	new query[ 200 ];
    mysql_format( DB_Connect, query, sizeof( query ), "SELECT ID, HouseName, HousePassword FROM houses WHERE HouseOwner = '%s'", PlayerName( playerid ) );
	mysql_query( DB_Connect, query );
	
	eBigString[ 0 ] = EOS;
	new rows = cache_num_rows( );
	
	if( rows )
	{
 		new id, hn[ MAX_HOUSE_NAME ], hp[ MAX_HOUSE_PASSWORD ];
   		format( eBigString, sizeof( eBigString ), "{FFFFFF}ID\t{FFFFFF}House Name\t{FFFFFF}Password\n");
	    for( new i; i < rows; ++i )
	    {
	        id = cache_get_field_content_int( i, "ID" );
	        cache_get_field_content( i, "HouseName", hn );
	        cache_get_field_content( i, "HousePassword", hp );
	        PlayerInfo[ playerid ][ Momentan_House_ID ] = i;
	        
	        format( eBigString, sizeof( eBigString ), "%s{FFFFFF}%d\t%s\t%s\n", eBigString,id, hn, hp );
	    }
		ShowPlayerDialog( playerid, DIALOG_HOUSES_TELEPORT, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}My Houses:", eBigString, "Select", "Exit" );
	}
	else
	{
		SendError( playerid, "You don't have any Houses" );
	}
	return 1;
}
It is ok ?
I tested and it's working.
Reply
#9

Looking at your code, I believe the "ID" in database is used as index for HouseData array. This isn't the best thing if you use auto increment as it could go out of bounds.

Anyway, the loop in that case is not needed at all:
pawn Код:
case DIALOG_HOUSES_TELEPORT:
{
    if (response)
    {
        new message[40 + MAX_HOUSE_NAME], house_ID;

        house_ID = PlayerInfo[playerid][Momentan_House_ID] = strval(inputtext);

        format(message, sizeof(message), "{FFFFFF}%s (ID: {C0C0C0}%d {FFFFFF}):", HouseData[house_ID][Name], house_ID);
        ShowPlayerDialog(playerid, DIALOG_HOUSES_TELEPORT_2, DIALOG_STYLE_LIST, message, "{FFFFFF}Teleport to House", "Select", "Back");

    }
}
and don't create local strings with 7000 size as run time 3 is in the door.
Reply
#10

Thank you very much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)