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

Hey there!

Yes yes I know... I feel stupid asking this question as I know it's simple i'm just having a mental blank right now.

pawn Код:
public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
{
    if(type == SELECT_OBJECT_GLOBAL_OBJECT)
    {
        EditObject(playerid, objectid);
    }
    else
    {
        EditPlayerObject(playerid, objectid);
    }
    SendClientMessage(playerid, 0xFFFFFFFF, "You now are able to edit your object!");
    return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED( KEY_SUBMISSION|KEY_LOOK_BEHIND ))
    {
            SendClientMessage(playerid, 0xFFFFFFFF, "You deleted the object.");
        DestroyObject(objectid);
            CancelEdit(playerid);
       
    }
}
The error on 'DestroyObject(objectid);'
pawn Код:
undefined symbol "objectid"
Basically I want that when you select the object I am then able to delete it by pressing the key. However I can't remmeber how to get the objectid into either another string or get that string into the KeyStateChange.


Cheers.
Reply
#2

Yeah, apologies ******.
I am just trying to get back into things, been away from a Computer for a while.
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)