[SOLVED]Multiple vehicles
#1

Hi all, I've made a Car Rental system, it all works as it is supposed to, but only for ONE vehicle.
It creates the other vehicles, but does not set them as a hire car, even though I have.

I haven't shown full code due to it is going to be a release.

pawn Код:
new HireID = -1, Hire[MAX_RENTABLE_VEHICLES];
pawn Код:
stock CreateHireVehicle(Modelid, Float:x, Float:y, Float:z, Float:a, Color1, Color2, price)
{
    HireID++;
    printf("Hire[HireID] %d", Hire[HireID]);
    hData[HireID][HirePrice] = price;
    hData[HireID][Hiree] = 501;
    hData[HireID][Hired] = 0;
    Hire[HireID] = CreateVehicle(Modelid, x, y, z, a, Color1, Color2, -1);
    printf("Hire[HireID] %d", Hire[HireID]);
    return 1;
}
Reply
#2

Bump (Sorry for less than 12 Hour bump, but Scripting Discussion is fl00ded quickly.)
Reply
#3

In which way does the result for the first car getting created by this code differ from the second car getting created by this code?
Reply
#4

The fact that it is not a hire vehicle when It should be, and that it skips a number ( I think that's due to vehicles in my GM )

pawn Код:
CreateHireVehicle(451, 524.259704, -1290.022094, 16.948589, 310.302642, -1, -1, 3000); //1
CreateHireVehicle(451, 534.313842, -1290.038574, 16.948661, 314.290283, -1, -1, 3000); //2
When I get in the first one, it returns "This is a hire vehicle");
Although when I get in the second one (Or any other vehicles created by CreateHireVehicle, other than the first) I get "This is not a hire vehicle."

pawn Код:
if(new a = 0; a < MAX_HIRE_VEHICLES; a++)
{
if(v != Hire[a])
{
SendClientMessage(playerid, yellow, "This is not a hire vehicle.");
}
else if(v == Hire[a])
{
SendClientMessage(playerid, yellow, "This Is a hire vehicle.");
}
// other stuff
}
return 1;
Reply
#5

That would probably be because the variable 'v's value does not change.
Reply
#6

Quote:
Originally Posted by Grim_
That would probably be because the variable 'v's value does not change.
Mhh..

pawn Код:
new v = GetPlayerVehicleID(playerid);
That is above the MAX_HIRE_VEHICLES loop, I will try and make it more local.

EDIT - Nothing's changed.
Reply
#7

You're code is always going to send the "not" message first, because you always check Hire[0] first. (The first vehicle)
Just do:
pawn Код:
new v = GetPlayerVehicleID(playerid);
if(v == Hire[1])
{
  //valid vehicle
}
And make sure you're in the second vehicle when you do it.
Reply
#8

But then I would need

pawn Код:
if(v == hire[1])
{
stuff
}
else if(v == hire[2])
{
//stuff
}
I thaught the loop would automaticly do the numbers (0-100)
Reply
#9

Yeah but with a for loop ( not sure what the code in your 3rd post is supposed to do )
Код:
for(new i=1;i<MAX_VEHICLES;i++) // or MAX_HIRE_VEHICLES
{
    if(v == Hire[i])
       // some code
}
Reply
#10

pawn Код:
if(v == hire[i])
mh?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)