help object ig
#1

pawn Код:
CMD:createo(playerid, params[])
{
    new i;
    for(i=0; i < MAX_OBJECTS_PP; i++)
    {
        if(oData[playerid][objID][i] == -1) break;
        if(i == ( MAX_OBJECTS_PP -1 ) ) return SendClientMessage(playerid, red, "You can't create more objects..");
    }
    new objectid;
    if(sscanf(params, "i", objectid)) return SendClientMessage(playerid, -1, "USAGE: /createo [model id]");
    new Float:pos[4];
   
    oData[playerid][objID][i] = objectid;
    oData[playerid][slotobjID] = i;
   
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);
    pos[0] += (3 * floatsin(-pos[3], degrees));
    pos[1] += (3 * floatcos(-pos[3], degrees));
    oObjectID[playerid][i] = CreateObject(objectid, pos[0], pos[1], pos[2], 0.0, 0.0, pos[3]);
    format(ssstring, SOS, "-OBJECT- MODELID: %d, SLOT ID: %d, X:%0.2f,Y:%0.2f,Z:%0.2f", objectid, oData[playerid][slotobjID], pos[0], pos[1], pos[2]);
    SendClientMessage(playerid, YELLOW, ssstring);
    return 1;
}

CMD:deleteo(playerid, params[])
{
    new slot;
    oData[playerid][slotobjID] = slot;
    if(sscanf(params, "i", slot)) return SendClientMessage(playerid, red, "USAGE: /deleteo [slot id]");
    DestroyObject(oObjectID[playerid][slot]);
    return 1;
pawn Код:
enum oInfo
{
    objID[MAX_OBJECTS_PP],
    slotobjID
}
new oData[MAX_PLAYERS][oInfo];
new oObjectID[MAX_PLAYERS][MAX_OBJECTS_PP];
One question .. assuming you want to delete a slot and groove to address this issue, which I can do, for example, delete the slot number 3 and I think another object to create the other object gets the id id 3 and not 4, if I give to understand?


I appreciate an answer!
Reply
#2

Can you try this:
pawn Код:
for(new i = 0; i < MAX_OBJECTS_PP; i++)
{
    if(oObjectID[playerid][i] != 0)
    {
        oObjectID[playerid][i] = CreateObject(objectid, pos[0], pos[1], pos[2], 0.0, 0.0, pos[3]);
        break;
    }
}
It should loop through all the player's object slots and the first slot that is empty gets to be the slot for the object. Haven't tried the code yet though.
Reply
#3

After you destroy your object make sure you reset the slot object id...

oObjectID[playerid][slot] = -1;
Reply
#4

Eyce.

Can you tell me what goes where?

pawn Код:
for(new i = 0; i < MAX_OBJECTS_PP; i++)
{
    if(oObjectID[playerid][i] != 0)
    {
        oObjectID[playerid][i] = CreateObject(objectid, pos[0], pos[1], pos[2], 0.0, 0.0, pos[3]);
        break;
    }
}
Pottus

Can you tell me what goes where?

pawn Код:
oObjectID[playerid][slot] = -1;
Reply
#5

It should be after
pawn Код:
pos[0] += (3 * floatsin(-pos[3], degrees));
pos[1] += (3 * floatcos(-pos[3], degrees));
Please tell me if it works.
Reply
#6

Quote:
Originally Posted by Eyce
Посмотреть сообщение
It should be after
pawn Код:
pos[0] += (3 * floatsin(-pos[3], degrees));
pos[1] += (3 * floatcos(-pos[3], degrees));
Please tell me if it works.
It works, thank you very much.
Eyce.
Reply
#7

After you delete the object of course you will want to reset that object reference to -1 to be reused.
Reply
#8

You're welcome, but
Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
After you delete the object of course you will want to reset that object reference to -1 to be reused.
you should consider this. It should look like
pawn Код:
DestroyObject(oObjectID[playerid][slot]);
oObjectID[playerid][slot] = -1;
then adjust the loop too
pawn Код:
for(new i = 0; i < MAX_OBJECTS_PP; i++)
{
    if(oObjectID[playerid][i] != -1)
    {
        oObjectID[playerid][i] = CreateObject(objectid, pos[0], pos[1], pos[2], 0.0, 0.0, pos[3]);
        break;
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)