MySQL saving/updating problem
#1

The script below works almost completely. But the problem after a Player set his house name, the house name saves but the House ID is not saving correctly. It shows -255 in the mysql_logs.

MYSQL_LOG
Quote:

[22:30:28] CMySQLHandler::Query(resultID) - Threaded query with id 18 started. (Extra ID: 0)

[22:30:28] CMySQLHandler::ProcessQueryThread(UPDATE `houses` SET `HName` = 'test' WHERE `HouseID` = '-255') - Data is getting passed to OnQueryFinish() - (Threadsafe: Yes)

[22:30:28] OnQueryFinish(18,"UPDATE `houses` SET `HName` = 'test' WHERE `HouseID` = '-255'") - Called.

HOUSE NAME SCRIPT
PHP код:
            if(strlen(inputtext) > && strlen(inputtext) < 21)
            {
                new 
housenumber GetHouseIDplayerid );
                if ( 
strcmpGetGVarStringEx"h_Owner"housenumber ), PlayerNameplayerid ), false ) )
                return 
SendClientMessageplayerid, -1,""SV_RD"» {c8c8c8}This house isn't yours!" );
                
formatgsQuerysizeof gsQuery"UPDATE `houses` SET `HName` = '%s' WHERE `HouseID` = '%d'"inputtexthousenumber );
                
mysql_querygsQueryTHREAD_NONEplayerid );
                
SetGVarString"h_name""%s"housenumber );
                
formatgsStringsizeofgsString ), ""W"Press "ORANGE_"H "W"key to Enter the House\n"SV_BL"House Name: "W"%s\n"SV_BL"House Owner: "W"%s\n "SV_BL"House Value: "W"%d$\n "SV_BL"House Privacy: "RED_"Closed\n"SV_BL"House ID: "ORANGE_"%d",GetGVarStringEx"h_name"housenumber ), PlayerName(playerid), GetGVarInt"h_Cost"housenumber),housenumber);
                
UpdateDynamic3DTextLabelTextText3D:GetGVarInt"House3DText"housenumber ), 0xFF9900FFgsString );
            }
              else
            {
                 
SendClientMessage(playeridCOLOR_RED"Error: {ffffff}You must enter 2-20 Character.");
                 
ShowPlayerDialog(playeridDIALOG_HOUSE_NAMEDIALOG_STYLE_INPUT"House Name""Write a new name for this house:\n\n{E74C3C}The name you entered is either too short or too long.""Change""Back");
            } 
Reply
#2

Try debugging what GetHouseID( playerid ); is returning.
Reply
#3

btw I got this GetHouseID! as you can see it returns to -255. but i don't know exactly how to fix it.

PHP код:
stock GetHouseIDplayerid )
{
    for ( new 
0MAX_HOUSESi++ )
    if ( 
IsPlayerInRangeOfPointplayerid2.0GetGVarFloat"h_X"), GetGVarFloat"h_Y"), GetGVarFloat"h_Z") ) )
            return 
i;
    return -
255;

Reply
#4

PHP код:
stock GetHouseIDplayerid 
{
    new 
id;
    
id = -255;
    for ( new 
0MAX_HOUSESi++ ) 
    if (
IsPlayerInRangeOfPointplayerid2.0GetGVarFloat"h_X"), GetGVarFloat"h_Y"), GetGVarFloat"h_Z"))) id i;
    print(
id);
    return 
id

Should output number in console. Tell us the number
Reply
#5

@[MG]Dimi thanks, I think this the problem below.

I think I know now what could be the problem. I need to be in a range of IsPlayerInRangeOfPoint( playerid, 2.0..) (which is near the house icon pickup) in order to save the GetHouseID if not then it will return as -255.
Reply
#6

Quote:
Originally Posted by kampuman
Посмотреть сообщение
I think I know now what could be the problem. I need to be in a range of IsPlayerInRangeOfPoint( playerid, 2.0..) (which is near the house icon pickup) in order to save the GetHouseID if not then it will return as -255.
You should check if GetHouseID returns -255 and if so return some kind of message saying that the player is not close enough to a house.
Reply
#7

Good idea phoenix that is really helpful. This is what I did btw.

Dialog 1:
PHP код:
            if(listitem == 0)
            {
                
ShowPlayerDialog(playeridDIALOG_HOUSE_NAMEDIALOG_STYLE_INPUT"House Name""Write a new name for this house:""Change""Back");
            } 
Response to Dialog 1. This will check weather the player is in the range.
Dialog 2:
PHP код:
    if(dialogid == DIALOG_HOUSE_NAME)
    {
        if ( !
response ) return 1;
        if ( 
response )
        {
            if(
strlen(inputtext) > && strlen(inputtext) < 21)
            {
                
SetCameraBehindPlayer(playerid);
                
SetPlayerPosplayeridhousex-0.5 houseyhousez );
                
SetPlayerInteriorplayerid);
                
TogglePlayerControllable(playerid,0);
                
SetTimerEx("WarningUnfreeze",4000,false,"id",playerid,GetPlayerVirtualWorld(playerid));
                
SetTimerEx("housename",3000,false,"id",playerid);
            }
            else
            {
                
SendClientMessage(playeridCOLOR_RED"Error: {ffffff}You must enter 2-20 Character.");
                
ShowPlayerDialog(playeridDIALOG_HOUSE_NAMEDIALOG_STYLE_INPUT"House Name""Write a new name for this house:\n\n{E74C3C}The name you entered is either too short or too long.""Change""Back");
            }
        }
    } 
I made a forward for

Код HTML:
SetTimerEx("housename",3000,false,"id",playerid) <--- Dialog 2;
PHP код:
forward housename(playerid);
public 
housename(playerid)
{
    new 
housenumber GetHouseIDplayerid );
    if ( 
strcmpGetGVarStringEx"h_Owner"housenumber ), PlayerNameplayerid ), false ) )
    return 
SendClientMessageplayerid, -1,""SV_RD"» {c8c8c8}This house isn't yours!" );
    
formatgsQuerysizeof gsQuery"UPDATE `houses` SET `HName` = '%s' WHERE `HouseID` = '%d'"inputtexthousenumber );
    
mysql_querygsQueryTHREAD_NONEplayerid );
    
SetGVarString"h_name""%s"housenumber );
    
formatgsStringsizeofgsString ), ""W"Press "ORANGE_"H "W"key to Enter the House\n"SV_BL"House Name: "W"%s\n"SV_BL"House Owner: "W"%s\n "SV_BL"House Value: "W"%d$\n "SV_BL"House Privacy: "RED_"Closed\n"SV_BL"House ID: "ORANGE_"%d",GetGVarStringEx"h_name"housenumber ), PlayerName(playerid), GetGVarInt"h_Cost"housenumber),housenumber);
    
UpdateDynamic3DTextLabelTextText3D:GetGVarInt"House3DText"housenumber ), 0xFF9900FFgsString );
    return 
1;

and error from the line
Quote:

(22602) : error 017: undefined symbol "inputtext"

Reply
#8

Someone please tell me how to convert this to y_timers?
Quote:

SetTimerEx("housename",3000,false,"is",playerid, inputtext);

Reply
#9

You can't and you don't need to.
There is no need for those timers, you can check player's position before setting house name, and also you need to escape house name, otherwise someone will f*ck you up with sql injection.
Reply
#10

Quote:
Originally Posted by Dragony92
Посмотреть сообщение
You can't and you don't need to.
There is no need for those timers, you can check player's position before setting house name, and also you need to escape house name, otherwise someone will f*ck you up with sql injection.

Quote:

[10:30:49] CMySQLHandler::Query(resultID) - Threaded query with id 18 started. (Extra ID: 0)

[10:30:49] CMySQLHandler::ProcessQueryThread(UPDATE `houses` SET `HName` = 'test' WHERE `HouseID` = '-255') - Data is getting passed to OnQueryFinish() - (Threadsafe: Yes)

[10:30:49] OnQueryFinish(18,"UPDATE `houses` SET `HName` = 'test' WHERE `HouseID` = '-255'") - Called.

When ever I combine, it gives me -255 HouseID which is invalid

PHP код:
            if(strlen(inputtext) > && strlen(inputtext) < 21)
            {
                
SetCameraBehindPlayer(playerid);  
                
SetPlayerInteriorplayerid);
                
TogglePlayerControllable(playerid,0);
                
SetPlayerPosplayeridhousex-0.5 houseyhousez );  //check last position before entering the house
                
SetTimerEx("WarningUnfreeze",4000,false,"id",playerid,GetPlayerVirtualWorld(playerid));
                
                 new 
housenumber GetHouseIDplayerid );
                if ( 
strcmpGetGVarStringEx"h_Owner"housenumber ), PlayerNameplayerid ), false ) )
                return 
SendClientMessageplayerid, -1,""SV_RD"» {c8c8c8}This house isn't yours!" );
                
formatgsQuerysizeof gsQuery"UPDATE `houses` SET `HName` = '%s' WHERE `HouseID` = '%d'"inputtexthousenumber );
                
mysql_querygsQueryTHREAD_NONEplayerid );
                  
SetGVarString"h_name""%s"housenumber );
                
formatgsStringsizeofgsString ), ""W"Press "ORANGE_"H "W"key to Enter the House\n"SV_BL"House Name: "W"%s\n"SV_BL"House Owner: "W"%s\n "SV_BL"House Value: "W"%d$\n "SV_BL"House Privacy: "RED_"Closed\n"SV_BL"House ID: "ORANGE_"%d",GetGVarStringEx"h_name"housenumber ), PlayerName(playerid), GetGVarInt"h_Cost"housenumber),housenumber);
                
UpdateDynamic3DTextLabelTextText3D:GetGVarInt"House3DText"housenumber ), 0xFF9900FFgsString );
            } 
can someone please tell me why is %s showing? when I use
Код HTML:
SetTimerEx("housename",3000,false,"is",playerid, inputtext);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)