Dynamic ATMs not working correctly[MySQL].
#1

Hello, I am kinda new to MySQL and I was wondering if you guys could help me out.

CMD:

PHP код:
CMD:createatm(playeridparams[])
{
    if (
IsPlayerAdminLevel(playerid4))
    {
        new 
string[64];
        
        new 
objectid = -1;
        for (new 
0MAX_DYNAMIC_ATMS++)
        {
            if (!
ATMEnum[i][objectExists])
            {
                
objectid i;
                break;
            }
        }
        if (
objectid != -1)
        {
            
format(stringsizeof(string), "INSERT INTO `ATMs` (`objectID`) VALUES('%d')"objectid);
            
mysql_query(string);
            new 
Float:xFloat:yFloat:zFloat:angle;
            
GetPlayerPos(playeridxyz);
            
GetPlayerFacingAngle(playeridangle);
            
ATMEnum[objectid][objectExists] = true;
            
ATMEnum[objectid][objectModel] = 2618;
            
ATMEnum[objectid][objectX] = + (1.4 floatsin(-angledegrees));
            
ATMEnum[objectid][objectY] = + (1.4 floatcos(angledegrees));
            
ATMEnum[objectid][objectZ] = z;
            
ATMEnum[objectid][objectRotX] = 0.0;
            
ATMEnum[objectid][objectRotY] = 0.0;
            
ATMEnum[objectid][objectRotZ] = angle;
            
ATMEnum[objectid][objectInterior] = GetPlayerInterior(playerid);
            
ATMEnum[objectid][objectVirtual] = GetPlayerVirtualWorld(playerid);
            
ATMEnum[objectid][objectID] = CreateDynamicObject(ATMEnum[objectid][objectModel], ATMEnum[objectid][objectX], ATMEnum[objectid][objectY], ATMEnum[objectid][objectZ], 0.00.0ATMEnum[objectid][objectRotZ], ATMEnum[objectid][objectVirtual], ATMEnum[objectid][objectInterior]);
            
format(stringsizeof(string), "Type {FFFFFF}/atm{F5DEB3} to use this atm.");
            
ATMEnum[objectid][objectLabel] = CreateStreamed3DTextLabel(stringYELLOW2ATMEnum[objectid][objectX], ATMEnum[objectid][objectY], ATMEnum[objectid][objectZ]+1.515.0ATMEnum[objectid][objectVirtual]);
            
            
ATMEnum[objectid][atmICON] = CreateDynamicMapIcon(ATMEnum[objectid][objectY], ATMEnum[objectid][objectY], ATMEnum[objectid][objectY], 520);
            
DestroyDynamicMapIcon(ATMEnum[objectid][atmICON]);
            
            
SaveATM(objectid);
            
format(stringsizeof(string), "You have created an ATM (%d)."objectid);
            
SendClientMessage(playeridWHITEstring);
            return 
1;
        }
        else return 
ErrorMessage(playerid"You cannot create anymore objects.");
    }
    else 
ErrorMessage(playerid"You are not authorized to use this command.");
    return 
1;

Saving:

PHP код:
stock SaveATM(objectid)
{
    if (
objectid >= && objectid MAX_DYNAMIC_ATMS)
    {
        if (
ATMEnum[objectid][objectExists])
        {
            new 
query[768];
            
format(querysizeof(query), "UPDATE `ATMs` SET `objectModel` = '%d', `objectX` = '%.4f', `objectY` = '%.4f', `objectZ` = '%.4f', `objectRotX` = '%.4f', `objectRotY` = '%.4f', `objectRotZ` = '%.4f', `objectInterior` = '%d', `objectVirtual` = '%d' WHERE `objectID` = '%d'",
                
ATMEnum[objectid][objectModel],
                
ATMEnum[objectid][objectX],
                
ATMEnum[objectid][objectY],
                
ATMEnum[objectid][objectZ],
                
ATMEnum[objectid][objectRotX],
                
ATMEnum[objectid][objectRotY],
                
ATMEnum[objectid][objectRotZ],
                
ATMEnum[objectid][objectInterior],
                
ATMEnum[objectid][objectVirtual],
                
objectid
            
);
            
mysql_query(query);
        }
    }
    return 
1;

How it's displaying on phpmyadmin:




And I got another question, I am making a /factions command where you can see both the offline and online members of a faction but when I select online I just see my name and when I invite another player you will only be able to see his name and for offline it isn't displaying the dialog.

Dialog on /factions:

PHP код:
case DIALOG_FACTIONS:
        {
            if (
response)
            {
                if (!
FactionEnum[listitem 1][factionExists])
                {
                    
ErrorMessage(playerid"That faction isn't taken yet.");
                    return 
1;
                }
                else
                {
                       if (
FactionEnum[listitem 1][factionType] == FACTION_HITMAN && PlayerEnum[playerid][pAdmin] < 3)
                        {
                        
ErrorMessage(playerid"This faction is classified.");
                        return 
1;
                    }
                    
SetPVarInt(playerid"SelectFaction"listitem 1);
                    
ShowPlayerDialog(playeridDIALOG_FACTIONS_INDEXDIALOG_STYLE_LIST"Factions""Online Members\nOffline Members""Select""Close");
        
                }
            }
            return 
1;
        } 

PHP код:
case DIALOG_FACTIONS_INDEX:
        {
            if (
response)
            {
                switch (
listitem)
                {
                    case 
0:
                    {
                        foreach (
Playeri)
                        {
                            if (
IsPlayerConnected(i))
                            {
                                new 
title[32], string2[520];
                                if(
PlayerEnum[i][pFaction] == GetPVarInt(playerid"SelectFaction"))
                                {
                                    
format(string2sizeof(string2), "%s%s (Rank: %d)\n"string2PlayerName(ifalse), PlayerEnum[i][pFactionRank]);
                                }
                                
format(titlesizeof(title), "%s"FactionEnum[listitem 1][factionName]);
                                
ShowPlayerDialog(playerid0DIALOG_STYLE_LISTtitlestring2"Close""");
                            }
                        }
                    }
                    case 
1:
                    {
                        new
                        
result[2][32],
                        
string2[500], title[32];
                        
mysql_query("SELECT `Username`, `FactionRank` FROM `Accounts` Where `Faction` = '%d' ORDER BY `FactionRank` DESC"GetPVarInt(playerid"SelectFaction"));
                        
mysql_store_result();
                        if (
mysql_num_rows() < 1) return 0;
                        while (
mysql_retrieve_row())
                        {
                            
mysql_fetch_field_row(result[0], "Username");
                            
mysql_fetch_field_row(result[1], "FactionRank");
                            
format(string2sizeof(string2), "%s%s (Rank: %d)\n",string2result[0], strval(result[1]));
                        }
                        
format(titlesizeof(title), "%s"FactionEnum[listitem 1][factionName]);
                        
ShowPlayerDialog(playerid0DIALOG_STYLE_LISTtitlestring2"Close""");
                    }
                }
            }
        } 
Reply
#2

bump
Reply
#3

Print queries. Check logs. The usual stuff. You're not going to get very far unless you learn how to debug.
Reply
#4

show mysql_log.txt
There might be a clue.
And add this script to your script

Код:
public OnQueryError(errorid, error[], callback[], query[], connectionHandle)
{
    switch(errorid)
	{
		case ER_SYNTAX_ERROR:
		{
			printf("[MY-SQL]Error[%d]:Syntax Error>>Query:%s",errorid,query);
		}
		default:
		{
		    printf("[MY-SQL]Error[%d]:%s",errorid,query);
		}
	}
	return 1;
}
Reply
#5

I added this debug in the SAveATM:

PHP код:
printf("[Query] Saving ATM %d, %s "objectidquery);
            
printf("Saving ATM %d, %d, %.4f, %.4f, %.4f, %.4f "objectidATMEnum[objectid][objectModel], ATMEnum[objectid][objectX], ATMEnum[objectid][objectY], ATMEnum[objectid][objectZ], ATMEnum[objectid][objectRotX]); 
PHP код:
[07:46:15] [08:16:12] [QuerySaving ATM 1UPDATE `ATMsSET `objectModel` = '2618', `objectX` = '1532.9465', `objectY` = '-1674.2839', `objectZ` = '13.3828', `objectRotX` = '0.0000', `objectRotY` = '0.0000', `objectRotZ` = '63.4980', `objectInterior` = '0', `objectVirtual` = '0' WHERE `objectID` = '1' 
[08:16:12Saving ATM 126181532.9465, -1674.283913.38280.0000 
[08:16:14] [cmd] []: /createatm
[08:16:14] [QuerySaving ATM 2UPDATE `ATMsSET `objectModel` = '2618', `objectX` = '1525.5904', `objectY` = '-1681.2431', `objectZ` = '13.3828', `objectRotX` = '0.0000', `objectRotY` = '0.0000', `objectRotZ` = '118.8861', `objectInterior` = '0', `objectVirtual` = '0' WHERE `objectID` = '2' 
[08:16:14Saving ATM 226181525.5904, -1681.243113.38280.0000 
[08:16:16] [cmd] []: /createatm
[08:16:16] [QuerySaving ATM 3UPDATE `ATMsSET `objectModel` = '2618', `objectX` = '1526.2705', `objectY` = '-1672.4276', `objectZ` = '13.3828', `objectRotX` = '0.0000', `objectRotY` = '0.0000', `objectRotZ` = '6.7610', `objectInterior` = '0', `objectVirtual` = '0' WHERE `objectID` = '3' 
[08:16:16Saving ATM 326181526.2705, -1672.427613.38280.0000 
[08:16:18] [cmd] []: /createatm
[08:16:18] [QuerySaving ATM 4UPDATE `ATMsSET `objectModel` = '2618', `objectX` = '1532.0362', `objectY` = '-1668.2733', `objectZ` = '13.3828', `objectRotX` = '0.0000', `objectRotY` = '0.0000', `objectRotZ` = '263.8649', `objectInterior` = '0', `objectVirtual` = '0' WHERE `objectID` = '4' 
[08:16:18Saving ATM 426181532.0362, -1668.273313.38280.0000 
Mhm, it looks like the query is not being excecuted.
Reply
#6

mysql_log plz
That will tell why it is not being executed.

Quote:

public OnQueryError(errorid, error[], callback[], query[], connectionHandle)
{
switch(errorid)
{
case ER_SYNTAX_ERROR:
{
printf("[MY-SQL]Error[%d]:Syntax Error>>Query:%s",errorid,query);
}
default:
{
printf("[MY-SQL]Error[%d]:%s",errorid,query);
}
}
return 1;
}

Even the code above will print the errorid.

You mostly have a syntax error or a column does't exist or some other error.
Reply
#7

Somehow it saved it, but when they're loaded and I want to /atm it isn't working and when I make a new ATM it starts at ID 0.

PHP код:
stock LoadATMS()
{
    new 
field[30], string[65];
    
mysql_query("SELECT * FROM `ATMs`");
    
mysql_store_result();
    if (
mysql_num_rows() != 0)
    {
        new 
id 0;
        while (
mysql_retrieve_row())
        {
            
mysql_get_field("objectID"field);
            
id strval(field);
            if (
id >= && id MAX_DYNAMIC_ATMS)
            {
                
ObjectEnum[id][objectExists] = true;
                
mysql_get_field("objectModel"field); ATMEnum[id][objectModel] = strval(field);
                
mysql_get_field("objectX"field); ATMEnum[id][objectX] = floatstr(field);
                
mysql_get_field("objectY"field); ATMEnum[id][objectY] = floatstr(field);
                
mysql_get_field("objectZ"field); ATMEnum[id][objectZ] = floatstr(field);
                
mysql_get_field("objectRotX"field); ATMEnum[id][objectRotX] = floatstr(field);
                
mysql_get_field("objectRotY"field); ATMEnum[id][objectRotY] = floatstr(field);
                
mysql_get_field("objectRotZ"field); ATMEnum[id][objectRotZ] = floatstr(field);
                
mysql_get_field("objectInterior"field); ATMEnum[id][objectInterior] = strval(field);
                
mysql_get_field("objectVirtual"field); ATMEnum[id][objectVirtual] = strval(field);
                
                
ObjectEnum[id][objectID] = CreateDynamicObject(ATMEnum[id][objectModel], ATMEnum[id][objectX], ATMEnum[id][objectY], ATMEnum[id][objectZ], ATMEnum[id][objectRotX], ATMEnum[id][objectRotY], ATMEnum[id][objectRotZ], ATMEnum[id][objectVirtual], ATMEnum[id][objectInterior]);
                
                
format(stringsizeof(string), "Type {FFFFFF}/atm{F5DEB3} to use this atm.");
                
ATMEnum[id][objectLabel] = CreateStreamed3DTextLabel(stringYELLOW2ATMEnum[id][objectX], ATMEnum[id][objectY], ATMEnum[id][objectZ]+1.515.0ATMEnum[id][objectVirtual]);
                
                   
ATMEnum[id][atmICON] = CreateDynamicMapIcon(ATMEnum[id][objectY], ATMEnum[id][objectY], ATMEnum[id][objectY], 520);
            }
        }
    }
    
mysql_free_result();
    return 
1;

PHP код:
stock GetNearestATM(playerid)
{
    new
        
atmid = -1,
        
Float:radius = (IsPlayerInAnyVehicle(playerid)) ? (5.5) : (2.0);
    for (new 
0MAX_DYNAMIC_ATMS++)
    {
        if (
ATMEnum[i][objectExists] && IsPlayerInRangeOfPoint(playeridradiusATMEnum[i][objectX], ATMEnum[i][objectY], ATMEnum[i][objectZ]) && GetPlayerVirtualWorld(playerid) == ATMEnum[i][objectVirtual])
        {
            
atmid i;
            break;
        }
    }
    return 
atmid;

PHP код:
CMD:atm(playeridparams[])
{
    new 
atm GetNearestATM(playerid);
    if (
atm == -1)
    {
        
ErrorMessage(playerid"You are not near an ATM.");
        return 
1;
    }
     
DisplayDialogForPlayer(playeridDIALOG_BANK_WITHDRAW);
    return 
1;

EDIT:

It showed some errors:

PHP код:
[08:34:49] [MY-SQL]Error[2014]:INSERT INTO `ATMs` (`objectID`) VALUES('2')
[
08:34:49] [MY-SQL]Error[2014]:UPDATE `ATMsSET `objectModel` = '2618', `objectX` = '1538.9224', `objectY` = '-1678.2655', `objectZ` = '13.3828', `objectRotX` = '0.0000', `objectRotY` = '0.0000', `objectRotZ` = '268.7601', `objectInterior` = '0', `objectVirtual` = '0' WHERE `objectID` = '2'
[08:35:25] [MY-SQL]Error[2014]:SELECT `Level`, `UsernameFROM `AccountsWhere `Level` > '1' ORDER BY `LevelDESC LIMIT 10
[08:42:29] [cmd] []: /createatm
[08:42:29] [QuerySaving ATM 3UPDATE `ATMsSET `objectModel` = '2618', `objectX` = '1536.8680', `objectY` = '-1681.8552', `objectZ` = '13.3828', `objectRotX` = '0.0000', `objectRotY` = '0.0000', `objectRotZ` = '222.5794', `objectInterior` = '0', `objectVirtual` = '0' WHERE `objectID` = '3' 
[08:42:29Saving ATM 326181536.8680, -1681.855213.38280.0000 
[08:42:29] [MY-SQL]Error[1062]:INSERT INTO `ATMs` (`objectID`) VALUES('3'
Reply
#8

Error 2014 means
The MySQL client protocol doesn't allow more than one query to be "in progress." That is, you've executed a query and you've fetched some of the results, but not all -- then you try to execute a second query. If the first query still has rows to return, the second query gets an error

Error 1062 is common:
means duplicate entry

****** the error codes that you get.
Reply
#9

I ******d for error 1062 and they say you can fix it by using AUTO_INCREMEN but I got that on ObjectID?
Reply
#10

For the first problem use timer.
For the second problem:it means that there already exists that atm.The ATM is already saved in the database and you have a UNIQUE or PRIMARY KEY that doesn't allow atms to repeat.
So you can't insert one more.
Just remove that primary key or unique key.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)