Jump to content
  • 0

Furniture - problema (dinou)


HypCosmin

Question

Ok, aici s-a rezolvat problema, dar acuma a intervenit o noua problema, nu se salveaza in baza de date nici atunci cand modific un obiect si nici atunci cand doresc sa il sterg!

//===================================================================================================================
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
	new Float:oldX, Float:oldY, Float:oldZ, Float:oldRotX, Float:oldRotY, Float:oldRotZ;
	GetDynamicObjectPos(objectid, oldX, oldY, oldZ);
	GetDynamicObjectRot(objectid, oldRotX, oldRotY, oldRotZ);

	if(response == EDIT_RESPONSE_FINAL)
	{
		if(EditHouse[playerid] == 1) {
		    new szQuery[256];
			mysql_format(handle, szQuery, 256, "INSERT INTO `fobjects` (`House`) VALUES ('0')");
			new Cache: result = mysql_query(handle, szQuery);
			new i = cache_insert_id();
			cache_delete(result);
			FurnitureInfo[i][fiModel] = EditModel[playerid];
			FurnitureInfo[i][fiX] = fX;
			FurnitureInfo[i][fiY] = fY;
			FurnitureInfo[i][fiZ] = fZ;
			FurnitureInfo[i][fiRotX] = fRotX;
			FurnitureInfo[i][fiRotY] = fRotY;
			FurnitureInfo[i][fiRotZ] = fRotZ;
			FurnitureInfo[i][fiVirtual] = GetPlayerVirtualWorld(playerid);
			FurnitureInfo[i][fiHouse] = PlayerInfo[playerid][pHouse];
			SaveObject(i);
			DestroyDynamicObject(ObjectEdited[playerid]);
			FurnitureInfo[i][fiObject] = CreateDynamicObject(FurnitureInfo[i][fiModel], FurnitureInfo[i][fiX], FurnitureInfo[i][fiY], FurnitureInfo[i][fiZ], FurnitureInfo[i][fiRotX], FurnitureInfo[i][fiRotY], FurnitureInfo[i][fiRotZ], FurnitureInfo[i][fiVirtual], -1, -1, 200.0);
            format(szQuery, 256, "Obiect adaugat! Total obiecte: %d/50.",  GetHouseObjects(PlayerInfo[playerid][pHouse]));
            SCM(playerid, COLOR_YELLOW, szQuery);
			GivePlayerCash(playerid, -500);
		}
		else if(EditHouse[playerid] == 2) {
		    new i = EditedObjectID[playerid];
			FurnitureInfo[i][fiX] = fX;
			FurnitureInfo[i][fiY] = fY;
			FurnitureInfo[i][fiZ] = fZ;
			FurnitureInfo[i][fiRotX] = fRotX;
			FurnitureInfo[i][fiRotY] = fRotY;
			FurnitureInfo[i][fiRotZ] = fRotZ;
			FurnitureInfo[i][fiVirtual] = GetPlayerVirtualWorld(playerid);
			FurnitureInfo[i][fiHouse] = PlayerInfo[playerid][pHouse];
			DestroyDynamicObject(FurnitureInfo[i][fiObject]);//
			FurnitureInfo[i][fiObject] = CreateDynamicObject(FurnitureInfo[i][fiModel], FurnitureInfo[i][fiX], FurnitureInfo[i][fiY], FurnitureInfo[i][fiZ], FurnitureInfo[i][fiRotX], FurnitureInfo[i][fiRotY], FurnitureInfo[i][fiRotZ], FurnitureInfo[i][fiVirtual], -1, -1, 200.0);
	        SaveObject(i);
	        SCM(playerid, COLOR_YELLOW, "Mobiler editat cu succes!");
		}
	}

	if(response == EDIT_RESPONSE_CANCEL)
	{
	    if(EditHouse[playerid] == 1) DestroyDynamicObject(ObjectEdited[playerid]), SCM(playerid, -1, "Ai anulat!");
	    if(EditHouse[playerid] == 2) SCM(playerid, -1, "Ai anulat!");
	}
	return 1;
}

si

		case DIALOG_EDITMOBILA: {
			if(!response) return 1;
			SlotSel[playerid] = listitem;
			ShowPlayerDialog(playerid, DIALOG_EDITMOBILA2, DIALOG_STYLE_MSGBOX, "Optiune:", "Ce vrei sa faci cu acest obiect?\nEditezi/Stergi?", "Editeaza", "Sterge");
		}
		case DIALOG_EDITMOBILA2: {
		    new id = SelMobila[playerid][SlotSel[playerid]];
		    printf("id = %d", id);
		    EditedObjectID[playerid] = id;
		    EditHouse[playerid] = 2;
		    new obj2 = FurnitureInfo[id][fiObject];
			if(!response) {
				mysql_format(handle,query,128,"DELETE FROM `fobjects` WHERE `ID`='%d'",id);
				mysql_query(handle, query);
				SCM(playerid, COLOR_YELLOW, "Obiect sters!");
				DestroyDynamicObject(FurnitureInfo[id][fiObject]);
				FurnitureInfo[id][fiHouse] = 0;
			}
			else {
		        EditHouse[playerid] = 2;
		        SendClientMessage(playerid, COLOR_YELLOW, "Mobilerul ales de tine a fost spawnat. Tot ce trebuie sa faci, este sa-i alegi o pozitie!");
		        SendClientMessage(playerid, COLOR_YELLOW, "Pentru a misca camera, apasa tasta SPACE iar pentru a misca obiectul, apasa click pe acele axe (X,Y,Z)");
		        EditDynamicObject(playerid, obj2);
			}
		}

Precizez: Cand adaug obiectul pe server merge sa ii modific/sterg/adaug, cand dau restart la server pot doar sa adaug alte obiecte, nu sa le modific/sterg din db.

Edited by HypCosmin
Precizare
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0
1 oră în urmă, Dennis12. a spus:

Arata query-ul cu care salvezi in database obiectul.

Cred ca e in functia

SaveObject

 

Uite aici

	pc SaveObject(const id)
 {
    format(query,sizeof(query),"UPDATE `fobjects` SET `Model`='%d', `X`='%f', `Y`='%f', `Z`='%f', `RotX`='%f', `RotY`='%f', `RotZ`='%f', `Virtual`='%d', `House`='%d' WHERE `ID`='%d'",
    FurnitureInfo[id][fiModel], FurnitureInfo[id][fiX], FurnitureInfo[id][fiY], FurnitureInfo[id][fiZ], FurnitureInfo[id][fiRotX], FurnitureInfo[id][fiRotY], FurnitureInfo[id][fiRotZ], FurnitureInfo[id][fiVirtual], FurnitureInfo[id][fiHouse], id);
    mysql_tquery(handle, query);
    return 1;
}
	

 

 

Dar pot spune ca nici nu se sterg din baza

	         switch(dialogid) // DE EDITAT
       {
        case DIALOG_EDITMOBILA: {
            if(!response) return 1;
            SlotSel[playerid] = listitem;
            ShowPlayerDialog(playerid, DIALOG_EDITMOBILA2, DIALOG_STYLE_MSGBOX, "Optiune:", "Ce vrei sa faci cu acest obiect?\nEditezi/Stergi?", "Editeaza", "Sterge");
        }
        case DIALOG_EDITMOBILA2: {
            new id = SelMobila[playerid][SlotSel[playerid]];
            printf("id = %d", id);
            EditedObjectID[playerid] = id;
            EditHouse[playerid] = 2;
            new obj2 = FurnitureInfo[id][fiObject];
            if(!response) {
                mysql_format(handle,query,128,"DELETE FROM `fobjects` WHERE `ID`='%d'",id);
                mysql_query(handle, query);
                //mysql_format(handle, query,  sizeof(query), "DELETE FROM `fobjects` WHERE `ID` = %d",FurnitureInfo[id][fiObject]);
                //mysql_tquery(handle, query);
                SCM(playerid, COLOR_YELLOW, "Obiect sters!");
                DestroyDynamicObject(FurnitureInfo[id][fiObject]);
                FurnitureInfo[id][fiHouse] = 0;
            }
            else {
                EditHouse[playerid] = 2;
                SendClientMessage(playerid, COLOR_YELLOW, "Mobilerul ales de tine a fost spawnat. Tot ce trebuie sa faci, este sa-i alegi o pozitie!");
                SendClientMessage(playerid, COLOR_YELLOW, "Pentru a misca camera, apasa tasta SPACE iar pentru a misca obiectul, apasa click pe acele axe (X,Y,Z)");
                EditDynamicObject(playerid, obj2);
            }
        }
	

Edited by HypCosmin
Link to comment
Share on other sites

  • 0

	pc LoadFurnitures() {
    new Cache: db = mysql_query(handle, "SELECT * FROM `fobjects` ORDER BY `fobjects`.`ID` ASC");
    new objects = 0, result[180];
     for(new i, j = cache_num_rows (); i != j; ++i) {
           objects ++;
           cache_get_value_name_int(i, "ID",            FurnitureInfo[i][fiID]);
           cache_get_value_name_int(i, "Model",         FurnitureInfo[i][fiModel]);
           cache_get_value_name_float(i, "X",           FurnitureInfo[i][fiX]);
           cache_get_value_name_float(i, "Y",           FurnitureInfo[i][fiY]);
           cache_get_value_name_float(i, "Z",           FurnitureInfo[i][fiZ]);
           cache_get_value_name_float(i, "RotX",        FurnitureInfo[i][fiRotX]);
           cache_get_value_name_float(i, "RotY",        FurnitureInfo[i][fiRotY]);
           cache_get_value_name_float(i, "RotZ",        FurnitureInfo[i][fiRotZ]);
           cache_get_value_name_int(i, "Virtual",       FurnitureInfo[i][fiVirtual]);
           cache_get_value_name_int(i, "House",         FurnitureInfo[i][fiHouse]);
           FurnitureInfo[i][fiObject] = CreateDynamicObject(FurnitureInfo[i][fiModel], FurnitureInfo[i][fiX], FurnitureInfo[i][fiY], FurnitureInfo[i][fiZ], FurnitureInfo[i][fiRotX], FurnitureInfo[i][fiRotY], FurnitureInfo[i][fiRotZ], FurnitureInfo[i][fiVirtual], -1, -1, 200.0);
    }
    printf("Furnitures: %d", objects);
    cache_delete(db);
    return 1;
}
	

 

	mysql_tquery(handle, "SELECT * FROM `fobjects`", "LoadFurnitures");
	

- Asta e in ongamemodeinit

Link to comment
Share on other sites

  • 0

Stati mai baieti asa.. 

Baiatu uite tie iti lipseste asta din codul dau:

//mysql_format(handle, query,  sizeof(query), "DELETE FROM `fobjects` WHERE `ID` = '%d'",FurnitureInfo[id][fiObject]);
//mysql_tquery(handle, query);

Nu sterge codul asta, anuleaza.l pe ala de mai sus si pe asta activeaza iar vezi ca ai uitat niste ghilimele la '%d'"tu asa il ai.. e trebuie sa il ai '%d'". Asa se va salva in baza de date.

Ti.am scris eu codul corect doar tu sa stergi // din fata.

Iar la editat nu ai mysql_format care sa.ti salveze obiectele modificate.

Edited by Cordyandrey
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.