Create/DestroyObject messing up
#3

I don't want to be rude against pds2k12, you may use his code too if you prefer it. But I'd do it this way:

There are two ways of doing this, if the green, purple and red lights are on different positions you should use the next:
pawn Код:
new light[12];

new Float:green_light_pos[12][6] = { // Positions of the green lights
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}}
};
   
new Float:red_light_pos[12][6] = { // Positions of the red lights
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}}
};
   
new Float:purple_light_pos[12][6] = { // Positions of the purple lights
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}}
};
   
CMD:green(playerid, params[])
{
    ClearObjectsFirst();
    for(new i = 0; i < 12; i++)
        {
        light[i] = CreateObject(*green light modelid*, green_light_pos[i][0], green_light_pos[i][1], green_light_pos[i][2], green_light_pos[i][3], green_light_pos[i][4], green_light_pos[i][5]);
        }
    return 1;
}
   
CMD:red(playerid, params[])
{
    ClearObjectsFirst();
    for(new i = 0; i < 12; i++)
        {
        light[i] = CreateObject(*red light modelid*, red_light_pos[i][0], red_light_pos[i][1], red_light_pos[i][2], red_light_pos[i][3], red_light_pos[i][4], red_light_pos[i][5]);
        }
    return 1;
}
   
CMD:purple(playerid, params[])
{
    ClearObjectsFirst();
    for(new i = 0; i < 12; i++)
        {
        light[i] = CreateObject(*purple light modelid*, purple_light_pos[i][0], purple_light_pos[i][1], purple_light_pos[i][2], purple_light_pos[i][3], purple_light_pos[i][4], purple_light_pos[i][5]);
        }
    return 1;
}

stock ClearObjectsFirst()
{
    for(new i = 0; i < 12; i++)
        {
        if(IsValidObject(light[i]) && light[i] != 24688642)
            {
            DestroyObject(light[i]);
            light[i] = 24688642; // 24688642 is a random number, the check for the number is just a extra one.
            }
        }
    return 1;
}
If they're on the same location but just different object models you can do it like this:
pawn Код:
new light[12];

new Float:light_pos[12][6] = { // Positions of the lights
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}},
{{X},{Y},{Z},{rX},{rY},{rZ}}
};
   
CMD:green(playerid, params[])
{
    ClearObjectsFirst();
    for(new i = 0; i < 12; i++)
        {
        light[i] = CreateObject(*green light modelid*, light_pos[i][0], light_pos[i][1], light_pos[i][2], light_pos[i][3], light_pos[i][4], light_pos[i][5]);
        }
    return 1;
}
   
CMD:red(playerid, params[])
{
    ClearObjectsFirst();
    for(new i = 0; i < 12; i++)
        {
        light[i] = CreateObject(*red light modelid*, light_pos[i][0], light_pos[i][1], light_pos[i][2], light_pos[i][3], light_pos[i][4], light_pos[i][5]);
        }
    return 1;
}
   
CMD:purple(playerid, params[])
{
    ClearObjectsFirst();
    for(new i = 0; i < 12; i++)
        {
        light[i] = CreateObject(*purple light modelid*, light_pos[i][0], light_pos[i][1], light_pos[i][2], light_pos[i][3], light_pos[i][4], light_pos[i][5]);
        }
    return 1;
}

stock ClearObjectsFirst()
{
    for(new i = 0; i < 12; i++)
        {
        if(IsValidObject(light[i]) && light[i] != 24688642)
            {
            DestroyObject(light[i]);
            light[i] = 24688642; // 24688642 is a random number, the check for the number is just a extra one.
            }
        }
    return 1;
}
I just kept 3 commands because you used 3, you can indeed also go with a param to select which color you want within 1 command.

Best regards,
Jesse
Reply


Messages In This Thread
Create/DestroyObject messing up - by Finn707 - 01.01.2014, 15:55
Re: Create/DestroyObject messing up - by Patrick - 01.01.2014, 16:03
Re: Create/DestroyObject messing up - by jessejanssen - 01.01.2014, 16:35
Re: Create/DestroyObject messing up - by Patrick - 01.01.2014, 16:50
Re: Create/DestroyObject messing up - by Konstantinos - 01.01.2014, 16:54
Re: Create/DestroyObject messing up - by Patrick - 01.01.2014, 17:26
Re: Create/DestroyObject messing up - by Konstantinos - 01.01.2014, 17:33
Re: Create/DestroyObject messing up - by Finn707 - 01.01.2014, 19:43

Forum Jump:


Users browsing this thread: 1 Guest(s)