[BUG]DestroyObject doesn't work
#1

I tested it again and again.. DestroyObject won't work. I just tested it with the new SA:MP objects. Here's an example:

pawn Код:
if (strcmp(cmd, "/neontest", true) == 0)
        {
            new neon1[MAX_PLAYERS], neon2[MAX_PLAYERS];
            if(UserStats[playerid][Fraktion] == 1)
                {
                    if(status1 == 0)
                        {
                            status1 = 1;
                            neon1[playerid] = CreateObject(18647,0,0,0,0,0,0);
                            neon2[playerid] = CreateObject(18647,0,0,0,0,0,0);
                            AttachObjectToVehicle(neon11[playerid], GetPlayerVehicleID(playerid), -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
                            AttachObjectToVehicle(neon1[playerid], GetPlayerVehicleID(playerid), 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
                            return 1;
                        }
                    else
                        {
                            DestroyObject(neon1[playerid]);
                            DestroyObject(neon2[playerid]);
                            status1 = 0;
                            return 1;
                        }
                    }
The neon light won't be deleted..
Reply
#2

It's your code, DestroyObject is working perfectly fine for me.
Reply
#3

Your defining the neon1 and neon2 variables every time someone types neontest so your DestroyObject code will always attempt to destroy object id 0 (default value). You would have the same issue in previous SA-MP versions.
Reply
#4

I know that erveryone can delete the neon lights. Can you post the fixed code? Thanks.
Reply
#5

Not sure, but try this:
pawn Код:
if (strcmp(cmd, "/neontest", true) == 0)
{
new neon1, neon2, status1[MAX_PLAYERS];
    if(UserStats[playerid][Fraktion] == 1)
    {
    if(status1[playerid] == 0)
    {
    status1[playerid] = 1;
    neon1 = CreateObject(18647,0,0,0,0,0,0);
    neon2 = CreateObject(18647,0,0,0,0,0,0);
    AttachObjectToVehicle(neon1, GetPlayerVehicleID(playerid), -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
    AttachObjectToVehicle(neon1, GetPlayerVehicleID(playerid), 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
    return 1;
}
        if(status1[playerid] == 1)
        {  
            DestroyObject(neon1);
            DestroyObject(neon2);
status1[playerid] = 0;
            return 1;
        }
    }
Reply
#6

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
Not sure, but try this:
pawn Код:
if (strcmp(cmd, "/neontest", true) == 0)
{
new neon1, neon2, status1[MAX_PLAYERS];
    if(UserStats[playerid][Fraktion] == 1)
    {
    if(status1[playerid] == 0)
    {
    status1[playerid] = 1;
    neon1 = CreateObject(18647,0,0,0,0,0,0);
    neon2 = CreateObject(18647,0,0,0,0,0,0);
    AttachObjectToVehicle(neon1, GetPlayerVehicleID(playerid), -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
    AttachObjectToVehicle(neon1, GetPlayerVehicleID(playerid), 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
    return 1;
}
        if(status1[playerid] == 1)
        {  
            DestroyObject(neon1);
            DestroyObject(neon2);
status1[playerid] = 0;
            return 1;
        }
    }
Doesn't work..
Reply
#7

pawn Код:
if (strcmp(cmd, "/neontest", true) == 0)
{
    if(UserStats[playerid][Fraktion] == 1)
    {
        if(!GetPVarInt(playerid, "Status"))
        {
            SetPVarInt(playerid, "Status", 1);
            SetPVarInt(playerid, "neo1", CreateObject(18647,0,0,0,0,0,0));
            SetPVarInt(playerid, "neo2", CreateObject(18647,0,0,0,0,0,0));
            AttachObjectToVehicle(GetPVarInt(playerid, "neo1"), GetPlayerVehicleID(playerid), -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
            AttachObjectToVehicle(GetPVarInt(playerid, "neo2"), GetPlayerVehicleID(playerid), 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
        }
        else
        {
            DestroyObject(GetPVarInt(playerid, "neo1"));
            DestroyObject(GetPVarInt(playerid, "neo2"));
            DeletePVar(playerid, "Status");
        }
    }
    return 1;
}
Try this.
Reply
#8

Quote:
Originally Posted by kacper55331
Посмотреть сообщение
pawn Код:
if (strcmp(cmd, "/neontest", true) == 0)
{
    if(UserStats[playerid][Fraktion] == 1)
    {
        if(!GetPVarInt(playerid, "Status"))
        {
            SetPVarInt(playerid, "Status", 1);
            SetPVarInt(playerid, "neo1", CreateObject(18647,0,0,0,0,0,0));
            SetPVarInt(playerid, "neo2", CreateObject(18647,0,0,0,0,0,0));
            AttachObjectToVehicle(GetPVarInt(playerid, "neo1"), GetPlayerVehicleID(playerid), -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
            AttachObjectToVehicle(GetPVarInt(playerid, "neo2"), GetPlayerVehicleID(playerid), 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
        }
        else
        {
            DestroyObject(GetPVarInt(playerid, "neo1"));
            DestroyObject(GetPVarInt(playerid, "neo2"));
            DeletePVar(playerid, "Status");
        }
    }
    return 1;
}
Try this.
Thanks! Thanks very much! Works fine.
Reply
#9

It's logical, you have created vars (new neon1[MAX_PLAYERS], neon2[MAX_PLAYERS] on your command and value doesn't saved.. for fix this problem put your vars on top of your script or use PVars..
Sorry for my english xd
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)