14.03.2017, 10:28
Here is my code for loading and saving Dynamic Tree System. it is based on Mysql r41-2. i dont see anything wrong, but just nothing gets created in my database.
The Problems i am facing is i think MYSQL is not able to connect to Database idk why. there is no mysql_debug() in this version so idk. i tried mysql_log(DEBUG), and mysql_log(all) but mysql_log.txt is empty.
Problems due to that:
-trees table not getting created into database.
-When Server Restarts, Trees created will not be loaded back.
-After i Press Save after Editing a tree and use /edit on other tree, it says i am editing a tree already. idk why?
please help me..
Код:
//Creating and calling format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS trees (ID INT AUTO_INCREMENT, ObjID INT, PosX FLOAT, PosY FLOAT, PosZ FLOAT, RotX FLOAT, RotY FLOAT, RotZ FLOAT)"); mysql_tquery(mysql_connection, query, "OnTableCreate"); format(loadtrees, sizeof(loadtrees), "SELECT * FROM TREES"); mysql_tquery(mysql_connection, loadtrees, "LoadTrees", "i",sizeof(TreeData));
Код:
//LoadTrees public LoadTrees(limit) { new count, rows, fields, data[50]; cache_get_row_count(rows); cache_get_field_count(fields); for(new i; i < rows; i++) { if(count > limit) { printf("Number of Trees exceeded limit!"); break; } for(new h; h < sizeof(TreeData); h++) { if(TreeData[h][ObjID] == 0) { cache_get_value_name(i, "ObjID", data); TreeData[h][ObjID] = strval(data); cache_get_value_name(i, "PosX", data); TreeData[h][treeX] = floatstr(data); cache_get_value_name(i, "PosY", data); TreeData[h][treeY] = floatstr(data); cache_get_value_name(i, "PosZ", data); TreeData[h][treeZ] = floatstr(data); cache_get_value_name(i, "RotX", data); TreeData[h][treeRX] = floatstr(data); cache_get_value_name(i, "RotY", data); TreeData[h][treeRY] = floatstr(data); cache_get_value_name(i, "RotZ", data); TreeData[h][treeRZ] = floatstr(data); CreateDynamicObject(TreeData[h][ObjID], TreeData[h][treeX], TreeData[h][treeY], TreeData[h][treeZ], TreeData[h][treeRX], TreeData[h][treeRY], TreeData[h][treeRZ]); count++; break; } } } printf("No. of Trees Loaded : %d",rows); return 1; }
Код:
//While Creating it: format(query, sizeof(query), "INSERT INTO TREES(ObjID, PosX,PosY,PosZ,RotX,RotY,RotZ) VALUES(%d,%f,%f,%f,0.0,0.0,0.0)",obj, x,y,z); mysql_tquery(mysql_connection, query,"OnTreeCreated", "i", playerid);
Код:
//OnPlayerEditDynamicObject public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz) { if(EditingTreeID[playerid] != -1 && Iter_Contains(Trees, EditingTreeID[playerid])) { if(response == EDIT_RESPONSE_FINAL) { new id = EditingTreeID[playerid]; TreeData[id][treeX] = x; TreeData[id][treeY] = y; TreeData[id][treeZ] = z; TreeData[id][treeRX] = rx; TreeData[id][treeRY] = ry; TreeData[id][treeRZ] = rz; SetDynamicObjectPos(objectid, TreeData[id][treeX], TreeData[id][treeY], TreeData[id][treeZ]); SetDynamicObjectRot(objectid, TreeData[id][treeRX], TreeData[id][treeRY], TreeData[id][treeRZ]); Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TreeData[id][treeLabel], E_STREAMER_X, TreeData[id][treeX]); Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TreeData[id][treeLabel], E_STREAMER_Y, TreeData[id][treeY]); Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TreeData[id][treeLabel], E_STREAMER_Z, TreeData[id][treeZ] + 1.5); new q[256]; format(q,sizeof(q), "INSERT INTO 'trees'(ObjID,PosX,PosY,PosZ,RotX,RotY,RotZ) values(%d,%f,%f,%f,%f,%f,%f)",objectid, TreeData[id][treeX],TreeData[id][treeY],TreeData[id][treeZ],TreeData[id][treeRX],TreeData[id][treeRY],TreeData[id][treeRZ]); mysql_query(mysql_connection, q); EditingTreeID[playerid] = -1; } if(response == EDIT_RESPONSE_CANCEL) { new id = EditingTreeID[playerid]; SetDynamicObjectPos(objectid, TreeData[id][treeX], TreeData[id][treeY], TreeData[id][treeZ]); SetDynamicObjectRot(objectid, TreeData[id][treeRX], TreeData[id][treeRY], TreeData[id][treeRZ]); EditingTreeID[playerid] = -1; } } return 1; }
Problems due to that:
-trees table not getting created into database.
-When Server Restarts, Trees created will not be loaded back.
-After i Press Save after Editing a tree and use /edit on other tree, it says i am editing a tree already. idk why?
please help me..