Issues having custom colors applied to gamemode vehicles after applying a paintjob
#1

Hi all,

I have been trying for a while now to have customized vehicles automatically get added to the game world once the script starts. I've gotten quite far with this - the vehicles spawn fine (after a little coaxing - read on), complete with any paintjob I set them to spawn with. However, some of these vehicles use a little trick to spice up the looks of those paintjobs - applying custom car colors after the paintjob is on to make the paintjobs look a lot different.

The problem I'm having is that these colors don't apply at all when added normally, and randomly decide to apply or fail applying when called with a timer. Furthermore, not all cars spawn at first - only a few do. I basically have to keep using /respawncars (simple loop which checks all vehicles and sets them to respawn) everytime I restart the server, just to get all vehicles to respawn.

Here's my code:
pawn Code:
//top of script
new PretunedCar[24];
pawn Code:
//OnFilterScriptInit - maps and vehicles are loaded through a separate FS. I have had similar issues when running from within the GM however.
    PretunedCar[1] = AddStaticVehicleEx(560, -2228.2, 2179.2, 11.5, 90, -1, -1, 1);
    PretunedCar[2] = AddStaticVehicleEx(560, -2228.2, 2168.5, 11.5, 90, -1, -1, 1);
    PretunedCar[3] = AddStaticVehicleEx(560, -2228.2, 2157.4, 11.5, 90, -1, -1, 1);
    PretunedCar[4] = AddStaticVehicleEx(559, -2228.2, 2147, 11.5, 90, -1, -1, 1);
    PretunedCar[5] = AddStaticVehicleEx(565, -2228.2, 2136.6, 11.5, 90, -1, -1, 1);
    PretunedCar[6] = AddStaticVehicleEx(558, -2228.2, 2127.2, 11.5, 90, -1, -1, 1);
    PretunedCar[7] = AddStaticVehicleEx(561, -2228.2, 2116.5, 11.5, 90, -1, -1, 1);
    PretunedCar[8] = AddStaticVehicleEx(562, -2228.2, 2106.3, 11.5, 90, -1, -1, 1);
    PretunedCar[9] = AddStaticVehicleEx(567, -2228.2, 2094.8, 11.5, 90, -1, -1, 1);
    PretunedCar[10] = AddStaticVehicleEx(558, -2228.2, 2084, 11.5, 90, -1, -1, 1);
    PretunedCar[11] = AddStaticVehicleEx(557, -2228.2, 2072.8, 11.5, 90, -1, -1, 1);
    PretunedCar[12] = AddStaticVehicleEx(535, -2295.2, 2184.8, 11.5, 270, -1, -1, 1);
    PretunedCar[13] = AddStaticVehicleEx(562, -2295.2, 2174.65, 11.5, 270, -1, -1, 1);
    PretunedCar[14] = AddStaticVehicleEx(562, -2295.2, 2163.8, 11.5, 270, -1, -1, 1);
    PretunedCar[15] = AddStaticVehicleEx(559, -2295.2, 2154, 11.5, 270, -1, -1, 1);
    PretunedCar[16] = AddStaticVehicleEx(483, -2295.2, 2143.65, 11.5, 270, -1, -1, 1);
    PretunedCar[17] = AddStaticVehicleEx(558, -2295.2, 2133.7, 11.5, 270, -1, -1, 1);
    PretunedCar[18] = AddStaticVehicleEx(534, -2295.2, 2123.8, 11.5, 270, -1, -1, 1);
    PretunedCar[19] = AddStaticVehicleEx(565, -2295.2, 2114, 11.5, 270, -1, -1, 1);
    PretunedCar[20] = AddStaticVehicleEx(558, -2295.2, 2103.9, 11.5, 270, -1, -1, 1);
    PretunedCar[21] = AddStaticVehicleEx(558, -2295.2, 2094, 11.5, 270, -1, -1, 1);
    PretunedCar[22] = AddStaticVehicleEx(560, -2295.2, 2083.7, 11.5, 270, -1, -1, 1);
    PretunedCar[23] = AddStaticVehicleEx(535, -2295.2, 2073.3, 11.5, 270, -1, -1, 1);
   
    OnVehicleSpawn(PretunedCar[1]); // works great apart from those colors...
    OnVehicleSpawn(PretunedCar[2]);
    OnVehicleSpawn(PretunedCar[3]);
    OnVehicleSpawn(PretunedCar[4]);
    OnVehicleSpawn(PretunedCar[5]);
    OnVehicleSpawn(PretunedCar[6]);
    OnVehicleSpawn(PretunedCar[7]);
    OnVehicleSpawn(PretunedCar[8]);
    OnVehicleSpawn(PretunedCar[9]);
    OnVehicleSpawn(PretunedCar[10]);
    OnVehicleSpawn(PretunedCar[11]);
    OnVehicleSpawn(PretunedCar[12]);
    OnVehicleSpawn(PretunedCar[13]);
    OnVehicleSpawn(PretunedCar[14]);
    OnVehicleSpawn(PretunedCar[15]);
    OnVehicleSpawn(PretunedCar[16]);
    OnVehicleSpawn(PretunedCar[17]);
    OnVehicleSpawn(PretunedCar[18]);
    OnVehicleSpawn(PretunedCar[19]);
    OnVehicleSpawn(PretunedCar[20]);
    OnVehicleSpawn(PretunedCar[21]);
    OnVehicleSpawn(PretunedCar[22]);
    OnVehicleSpawn(PretunedCar[23]);
pawn Code:
//OnVehicleSpawn(vehicleid) < below is an example of the tuning code I use for the vehicles which require colors - not gonna add all vehicles as these are private, but they all work the same way.
    if(vehicleid == PretunedCar[22])
    {
        ChangeVehiclePaintjob(PretunedCar[22], 0);
        AddVehicleComponent(PretunedCar[22], 1029);
        AddVehicleComponent(PretunedCar[22], 1140);
        AddVehicleComponent(PretunedCar[22], 1138);
        AddVehicleComponent(PretunedCar[22], 1030);
        AddVehicleComponent(PretunedCar[22], 1031);
        AddVehicleComponent(PretunedCar[22], 1080);
        SetTimerEx("ChangeColor", randomEx(2000, 5000), 0, "iii", PretunedCar[22], 6, 6);
    }
pawn Code:
//ChangeColor and randomEx functions
forward ChangeColor(vehicleid, color1, color2);
public ChangeColor(vehicleid, color1, color2)
{
    ChangeVehicleColor(vehicleid, color1, color2);
    return 0;
}

stock randomEx(min, max) //eventually switched to these random randoms to try and get all vehicles to spawn at different intervals - didn't do much, sadly.
{
    new rand = random(max-min)+min;
    return rand;
}
Any ideas why some cars decide to spawn and some don't, and why some cars get colors applied and some don't, all completely at random? Would love to get this issue sorted - thanks in advance for any help!
Reply
#2

Managed to sort-of fix it! The solution I used isn't the most elegant (having a timer re-apply colors and respawn the vehicles every 5 seconds), but it does work extremely well. If anybody knows a sexier solution I'm all ears, but until then I got this little timer keeping everything working well.
Reply
#3

I have the same issue, anybody have any ideas?

Adding too many timers isn't the best idea, I have too many timers as is.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)