SA-MP Forums Archive
Problem with MySQL - 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: Problem with MySQL (/showthread.php?tid=575452)



Problem with MySQL - Joseito - 27.05.2015

їWhat system try to develop?

Objects IG system with MySQL database.

їWhat problem I have?

My problem is this, the command /createobject [Object ID] everything works perfectly into the data but when using /editobject [ID], and when finished giving to customize the database object does not update the new coordinates.

Note: In the "" if (response == EDIT_RESPONSE_FINAL) "" place a SendClientMessage within it and when should give out the message of SendClientMessage, moves the object, not save the new coordinates, and shows the SendClientMessage.

їWhat is the problem?

PHP код:
COMMAND:editobject(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return 0;
    new 
id,count;
    if(
sscanf(params"i"id)) return SendClientMessage(playeridCOLOR_LIGHTBLUE"Usage: /editobject [object id]");
    for(new 
isizeof(object); i++){
        if(
object[i][oScriptID] == id){
            
EditDynamicObject(playeridobject[i][oObjectID]);
            
count++;
            break;
        }
    }
    if(
count == 0)
    {
        
SendClientMessage(playeridCOLOR_LIGHTRED"Error: That object ID do not exist.");
        return 
1;
    }    
    return 
1;
}
public 
OnPlayerEditObject(playeridplayerobjectobjectidresponseFloat:fXFloat:fYFloat:fZFloat:fRotXFloat:fRotYFloat:fRotZ)
{
    if(
response == EDIT_RESPONSE_FINAL)
    {
            new 
query[258];
        new 
Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz;
        
GetDynamicObjectPos(objectid,x,y,z);
        
GetDynamicObjectRot(objectid,rx,ry,rz);
        for(new 
isizeof(object); i++){
            if(
object[i][oObjectID] == objectid){
                        
object[i][oX] = fX;
                
object[i][oY] = fY;
                
object[i][oZ] = fZ;
                
object[i][roX] = fRotX;
                
object[i][roY] = fRotY;
                
object[i][roZ] = fRotZ;
                
format(dquerysizeof(dquery), "UPDATE objects SET oX = %f, oY = %f, oZ = %f, roX = %f, roY = %f, roZ = %f WHERE ScriptID = %d",object[i][oX],object[i][oY],object[i][roX],object[i][roY],object[i][roZ],object[i][oZ],object[i][oScriptID]);
                
mysql_query(1query);
                
DestroyDynamicObject(objectid);
                
object[i][oObjectID] = CreateDynamicObject(object[i][oModelID], object[i][oX], object[i][oY], object[i][oZ], object[i][roX], object[i][roY], object[i][roZ]);
                break;
            }    
        }
                
    }
    if(
response == EDIT_RESPONSE_CANCEL)
    {
        for(new 
isizeof(object); i++){
            if(
object[i][oObjectID] == objectid){
                
DestroyDynamicObject(objectid);
                
object[i][oObjectID] = CreateDynamicObject(object[i][oModelID], object[i][oX], object[i][oY], object[i][oZ], object[i][roX], object[i][roY], object[i][roZ]);
                break;
            }
        }            
    }
    return 
1;




Re: Problem with MySQL - X337 - 27.05.2015

Change:
Код:
format(dquery, sizeof(dquery), "UPDATE objects SET oX = %f, oY = %f, oZ = %f, roX = %f, roY = %f, roZ = %f WHERE ScriptID = %d",object[i][oX],object[i][oY],object[i][roX],object[i][roY],object[i][roZ],object[i][oZ],object[i][oScriptID]);
To:
Код:
format(dquery, sizeof(dquery), "UPDATE objects SET `oX` = '%f', `oY` = '%f', `oZ` = '%f', `roX` = '%f', `roY` = '%f', `roZ` = '%f' WHERE `ScriptID` = %d",object[i][oX],object[i][oY],object[i][roX],object[i][roY],object[i][roZ],object[i][oZ],object[i][oScriptID]);
Add single quote on float.


Re: Problem with MySQL - ball - 27.05.2015

Quote:
Originally Posted by bondowocopz
Посмотреть сообщение
Change:
Код:
format(dquery, sizeof(dquery), "UPDATE objects SET oX = %f, oY = %f, oZ = %f, roX = %f, roY = %f, roZ = %f WHERE ScriptID = %d",object[i][oX],object[i][oY],object[i][roX],object[i][roY],object[i][roZ],object[i][oZ],object[i][oScriptID]);
To:
Код:
format(dquery, sizeof(dquery), "UPDATE objects SET `oX` = '%f', `oY` = '%f', `oZ` = '%f', `roX` = '%f', `roY` = '%f', `roZ` = '%f' WHERE `ScriptID` = %d",object[i][oX],object[i][oY],object[i][roX],object[i][roY],object[i][roZ],object[i][oZ],object[i][oScriptID]);
Add single quote on float.
It's not necessary when saving integer or float. Problem is here

Код:
format(dquery, sizeof(dquery), "UPDATE objects SET oX = %f, oY = %f, oZ = %f, roX = %f, roY = %f, roZ = %f WHERE ScriptID = %d",object[i][oX],object[i][oY],object[i][roX],object[i][roY],object[i][roZ],object[i][oZ],object[i][oScriptID]); 
                mysql_query(1, query);
You format dquery string, but query string is in mysql_query function. Use one string.


Respuesta: Problem with MySQL - Joseito - 28.05.2015

Thanks for trying to help me solve the problem, the OnPlayerEditObject not respond, but I managed to fix it