OnPlayerEditObject / DynamicObject Help
#1

Hi guys,

So I'm working on a furniture system but for the life of me I can't find a way to detect what object is actually being edited currently by the player.

I've attempted to do a loop through all furniture and do an if statement to say if the objectid is equal to that furniture object currently selected in the loop, however that didn't work, I'm just completely out of ideas and I can't exactly show any code because all the code I have doesn't seem to be correct. However, this is what I have.

pawn Код:
if(response == EDIT_RESPONSE_FINAL)
    {
if(IsMovingFurniture[playerid] == true)
                    {
                        for(new FurnLoop = 0; FurnLoop < MAX_FURNITURE; FurnLoop++)
                        {

                            if(FurnitureObj[FurnLoop])
                            {
                                new query[500];
                               
                                SetDynamicObjectPos(FurnitureObj[ FurnLoop ], fX, fY, fZ);
                                SetDynamicObjectRot(FurnitureObj[ FurnLoop ], fRotX, fRotY, fRotZ);

                               
                                HouseFurni[ FurnLoop ] [FurnitureX] = fX;
                                HouseFurni[ FurnLoop ] [FurnitureY] = fY;
                                HouseFurni[ FurnLoop ] [FurnitureZ] = fZ;
                                HouseFurni[ FurnLoop ] [FurnitureRX] = fRotX;                        
                                HouseFurni[ FurnLoop ] [FurnitureRY] = fRotY;
                                HouseFurni[ FurnLoop ] [FurnitureRZ] = fRotZ;
                               
                                format(query, sizeof(query), "UPDATE `furniture` SET FurnitureX='%f', FurnitureY='%f', FurnitureZ='%f', FurnitureRX='%f',\
                                 FurnitureRY='%f', FurnitureRZ='%f' WHERE FurnitureID='%d'"
, fX, fY, fZ, fRotX, fRotY, fRotZ, HouseFurni[FurnLoop][FurnitureID]);

                                mysql_function_query(dbHandle, query, false, "", "");

                                IsMovingFurniture[playerid] = false;
                                MovingFurnitureID[playerid] = -1;

                                SendClientMessageF(playerid, COLOR_OOC, "Furniture ID: %d", HouseFurni[ FurnLoop ][FurnitureID]);
                                break;
                            }
                        }
}
Currently the if(FurnitureObj[FurnLoop]) statement only selects the FIRST object in the loop, I can't find a way to say if that isn't the selected object, then continue the loop; This is literally impossible to explain
Reply
#2

Why not use the PVars ? :/

Use a pvar to set the current selected object which then can be retrieved later.
Reply
#3

At the part where you set the IsMovingFurniture[playerid] to true.
Add this:
PHP код:
SetPVarInt(playerid"SelFurnObj"ID_OF_FURN); //Replace the ID_OF_FURN with the ID where you set the above variable to true. 
And then in the OnPlayerEditObject callback, use this:
PHP код:
new furnID GetPVarInt(playerid"SelFurnObj"); 
Reply
#4

Quote:
Originally Posted by Ahmad45123
Посмотреть сообщение
At the part where you set the IsMovingFurniture[playerid] to true.
Add this:
PHP код:
SetPVarInt(playerid"SelFurnObj"ID_OF_FURN); //Replace the ID_OF_FURN with the ID where you set the above variable to true. 
And then in the OnPlayerEditObject callback, use this:
PHP код:
new furnID GetPVarInt(playerid"SelFurnObj"); 
Hi Ahmad,
I've attempted something similar to this in the past but then I couldn't actually update the enums for that furniture, as I may have the objectid but there is no way to actually get the 'loop number' that matches the data stored for it on the enum, for example.

pawn Код:
HouseFurni[ (INDEX) ] [FurnitureX] = fX;
                                HouseFurni[ (INDEX)] [FurnitureY] = fY;
                                HouseFurni[ (INDEX)] [FurnitureZ] = fZ;
                                HouseFurni[ (INDEX)] [FurnitureRX] = fRotX;                        
                                HouseFurni[ (INDEX)] [FurnitureRY] = fRotY;
                                HouseFurni[ (INDEX)] [FurnitureRZ] = fRotZ;
If I have it linking to the objectid, how can I get the index? It's hard to explain because I think this system I have scripted won't work, as HouseFurni[MAX_FURNITURE] is impossible to get with an objectid.
Reply
#5

Maybe create a FurnObject in the enum.
And when a furniture object is created, Store that ID in the array to be used later on.

And to get the index from the ID, Just use this func:
PHP код:
GetFurnIndex(objectid)
{
    for(new 
FurnLoop 0FurnLoop MAX_FURNITUREFurnLoop++)
    {
         if(
HouseFurni[FurnLoop][FurnObject] == objectid) return FurnLoop;
    }
    return -
1;

And ofcourse use PVars to have the objectid as I already said.
Reply
#6

Just got something in mind, At the part where you actually call the EditObject.. How did you manage to get the index.. You should've had the same problem :/

I am 80% sure you already had the index there so store it as a PVar.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)