19.12.2017, 10:38
Try to use sql lite.
This is an example of saving the object(not my work):
And loading.
I hope this helped you
This is an example of saving the object(not my work):
Код:
EDITOR_OBJECT[id][OBJ_MODEL] = strval(inputtext); EDITOR_OBJECT[id][OBJ_X] = editor[0]+1; EDITOR_OBJECT[id][OBJ_Y] = editor[1]+1; EDITOR_OBJECT[id][OBJ_Z] = editor[2]; EDITOR_OBJECT[id][OBJ_RX] = 0.0; EDITOR_OBJECT[id][OBJ_RY] = 0.0; EDITOR_OBJECT[id][OBJ_RZ] = 0.0; EDITOR_OBJECT[id][OBJ_VW] = -1; EDITOR_OBJECT[id][OBJ_INTERIOR] = -1; EDITOR_OBJECT[id][OBJ_STREAM_DISTANCE] = 100.0; EDIT_OBJECT_ID[playerid] = id; EditDynamicObject(playerid, id); new EDITOR_QUERY[256]; format(EDITOR_QUERY, sizeof(EDITOR_QUERY), "INSERT INTO `OBJECTS` (`MODEL`, `X`, `Y`, `Z`, `INT`) VALUES (%d,'%f','%f','%f',%d)", EDITOR_OBJECT[id][OBJ_MODEL], EDITOR_OBJECT[id][OBJ_X], EDITOR_OBJECT[id][OBJ_Y], EDITOR_OBJECT[id][OBJ_Z], id+1000); db_free_result(db_query(EDITOR_DATABASE, EDITOR_QUERY)); new DBResult:EDITOR_RESULT; format(EDITOR_QUERY,sizeof(EDITOR_QUERY),"SELECT `ID` FROM `OBJECTS` WHERE `INT`=%d",id+1000); EDITOR_RESULT = db_query(EDITOR_DATABASE,EDITOR_QUERY); if(db_num_rows(EDITOR_RESULT) == 1) { new temp[16]; db_get_field(EDITOR_RESULT,0,temp,16); EDITOR_OBJECT[id][OBJ_DB_ID] = strval(temp); SendClientMessage(playerid,DEF_COL_WHITE,"Object ID received."); } db_free_result(EDITOR_RESULT); format(EDITOR_QUERY, sizeof(EDITOR_QUERY), "UPDATE `OBJECTS` SET `INT`=-1 WHERE `ID`=%d",EDITOR_OBJECT[id][OBJ_DB_ID]); db_free_result(db_query(EDITOR_DATABASE, EDITOR_QUERY));
Код:
new DBResult:EDITOR_RESULT,IDX; EDITOR_RESULT = db_query(EDITOR_DATABASE, "SELECT * FROM `OBJECTS`"); if(db_num_rows(EDITOR_RESULT) > 0) // Logged In { new EDITOR_VALEU[26][11],id; for (new x=0; x<db_num_rows(EDITOR_RESULT); x++) { IDX = 0; db_get_field_assoc(EDITOR_RESULT, "ID", EDITOR_VALEU[IDX], 26),IDX++; db_get_field_assoc(EDITOR_RESULT, "MODEL", EDITOR_VALEU[IDX], 26),IDX++; db_get_field_assoc(EDITOR_RESULT, "X", EDITOR_VALEU[IDX],26),IDX++; db_get_field_assoc(EDITOR_RESULT, "Y", EDITOR_VALEU[IDX],26),IDX++; db_get_field_assoc(EDITOR_RESULT, "Z", EDITOR_VALEU[IDX],26),IDX++; db_get_field_assoc(EDITOR_RESULT, "RX", EDITOR_VALEU[IDX],26),IDX++; db_get_field_assoc(EDITOR_RESULT, "RY", EDITOR_VALEU[IDX],26),IDX++; db_get_field_assoc(EDITOR_RESULT, "RZ", EDITOR_VALEU[IDX],26),IDX++; db_get_field_assoc(EDITOR_RESULT, "VW", EDITOR_VALEU[IDX],26),IDX++; db_get_field_assoc(EDITOR_RESULT, "INT", EDITOR_VALEU[IDX],26),IDX++; db_get_field_assoc(EDITOR_RESULT, "DISTANCE", EDITOR_VALEU[IDX],26); id = CreateDynamicObject(strval(EDITOR_VALEU[1]), floatstr( EDITOR_VALEU[2]),floatstr(EDITOR_VALEU[3]),floatstr(EDITOR_VALEU[4]), floatstr( EDITOR_VALEU[5]),floatstr(EDITOR_VALEU[6]),floatstr(EDITOR_VALEU[7]), strval(EDITOR_VALEU[8]), strval(EDITOR_VALEU[9]),-1, floatstr(EDITOR_VALEU[10])); EDITOR_OBJECT[id][OBJ_DB_ID] = strval(EDITOR_VALEU[0]); EDITOR_OBJECT[id][OBJ_MODEL] = strval(EDITOR_VALEU[1]); EDITOR_OBJECT[id][OBJ_X] = floatstr(EDITOR_VALEU[2]); EDITOR_OBJECT[id][OBJ_Y] = floatstr(EDITOR_VALEU[3]); EDITOR_OBJECT[id][OBJ_Z] = floatstr(EDITOR_VALEU[4]); EDITOR_OBJECT[id][OBJ_RX] = floatstr(EDITOR_VALEU[5]); EDITOR_OBJECT[id][OBJ_RY] = floatstr(EDITOR_VALEU[6]); EDITOR_OBJECT[id][OBJ_RZ] = floatstr(EDITOR_VALEU[7]); EDITOR_OBJECT[id][OBJ_VW] = strval(EDITOR_VALEU[8]); EDITOR_OBJECT[id][OBJ_INTERIOR] = strval(EDITOR_VALEU[9]); EDITOR_OBJECT[id][OBJ_STREAM_DISTANCE] = floatstr(EDITOR_VALEU[10]); db_next_row(EDITOR_RESULT); } } new string[128]; format(string,sizeof(string),"%d objects have been loaded.",db_num_rows(EDITOR_RESULT)); SendClientMessageToAll(DEF_COL_WHITE,string); db_free_result(EDITOR_RESULT); return 1; }