[Rookie Question] Getting the objectid per-say into a delete KeyStateChange?
#3

You need to store the type of edition (to know whether to use DestroyObject or DestroyPlayerObject) and the ID of the object.

I'd personally use a pVar (player-variable) because you won't need this to be stored often and it's not frequently set/read so it won't be a problem:

pawn Код:
new bool:g_pEditObj[MAX_PLAYERS char]; // Char-array to save memory (uses a quarter)

public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
{
    if(type == SELECT_OBJECT_GLOBAL_OBJECT)
    {
        EditObject(playerid, objectid);
        SetPVarInt(playerid, "edit_object_type", 0);
    }
    else
    {
        EditPlayerObject(playerid, objectid);
        SetPVarInt(playerid, "edit_object_type", 1);
    }
    g_pEditObj{playerid} = true;
    SetPVarInt(playerid, "edit_object_id", objectid);
    SendClientMessage(playerid, 0xFFFFFFFF, "You now are able to edit your object!");
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(g_pEditObj{playerid} == true && PRESSED( KEY_SUBMISSION | KEY_LOOK_BEHIND ))
    {
            SendClientMessage(playerid, 0xFFFFFFFF, "You deleted the object.");

            if(GetPVarInt(playerid, "edit_object_type") == 0) DestroyObject(GetPVarInt(playerid, "edit_object_id"));
            else DestroyPlayerObject(playerid, GetPVarInt(playerid, "edit_object_id"));

            // Delete the pVars now
            DeletePVar(playerid, "edit_object_id");
            DeletePVar(playerid, "edit_object_type");
           
            // Reset g_pEditObj
            g_pEditObj{playerid} = false;

    }
}
I used pVars and char-arrays - hope you understand it. If not, let me know.

I used a char-array (bool (true/false)) as it only uses a quarter of the memory a normal array would.
Reply


Messages In This Thread
[Rookie Question] Getting the objectid per-say into a delete KeyStateChange? - by Deal-or-die - 08.04.2013, 06:35
Re: [Rookie Question] Getting the objectid per-say into a delete KeyStateChange? - by Deal-or-die - 08.04.2013, 07:37
Re: [Rookie Question] Getting the objectid per-say into a delete KeyStateChange? - by MP2 - 08.04.2013, 23:20

Forum Jump:


Users browsing this thread: 1 Guest(s)