Little Help
#1

Hi,

I have attach police siren to infernus car, now how i can attach all this sirens for other 5 infernus cars ? Instead of repeating code! +REP
Reply
#2

I'm not sure what you mean by "repeating" code, show what you currently have or be more specific with what you're trying to do.
Reply
#3

If you are using AddStaticVehicleEx then you can't do it for more other 5 infernus cars without repeating..
Reply
#4

I have variable InfernusCars[5], and i want to attach sirens to all these infernus cars without repeating code like this.

Code:
new Siren= CreateObject(1541, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
AttachObjectToVehicle(InfernusCar[0], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
Code:
new Siren= CreateObject(1541, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
AttachObjectToVehicle(InfernusCar[1], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
Code:
new Siren= CreateObject(1541, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
AttachObjectToVehicle(InfernusCar[2], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
I creating vehicles like this: InfernusCars[0] = CreateVehicle(411, bla bla bla, bla bla bla);
.............
.............
Reply
#5

You could loop through them, which also allows you to dynamically make more later on. Is there also a purpose to storing the object ID? (i.e: destroying them later on).
Reply
#6

I have no idea how to loop trought these :/ . No there is no purpose of storing object
Reply
#7

You could do something such as this:
pawn Code:
for(new i; i < sizeof InfernusCar; i++)
{
       if(!GetVehicleModel(InfernusCar[i])) continue;
       AttachObjectToVehicle(CreateObject(1541, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), InfernusCar[0], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
}
Reply
#8

Now, the siren is only attached to InfernusCar[0] What to do ?
Reply
#9

Quote:
Originally Posted by Hunud
View Post
Now, the siren is only attached to InfernusCar[0] What to do ?
Code:
for(new i; i < sizeof InfernusCars; i++)
{
    if(!GetVehicleModel(InfernusCars[i])) continue;
    AttachObjectToVehicle(CreateObject(1541, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), InfernusCars[i], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
}
Reply
#10

thanks that work :d
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)