Max Vehicles 200? -
Alvord - 02.01.2015
I'm putting in random vehicles in my script using
AddStaticVehicleEx() there are also some vehicles that were created using
CreateVehicle() mainly for dealership vehicles. I scripted it in that if the player is an admin and spawns a "temporary vehicle", it would automatically turn the engine on. It's weird that when the vehicle ID reached 200, it stopped working. Any fixes on this?
I already tried this:
pawn Код:
printf("MAX VEHICLES: %d", MAX_VEHICLES);
and it shows 2000, which is correct.
Here is the code:
pawn Код:
new TempVehicles[MAX_VEHICLES] = {INVALID_VEHICLE_ID, ...};
command(randomveh, playerid, params[])
{
#pragma unused params
if(IsPlayerConnected(playerid) && Player[playerid][AdminLevel] >= 3)
{
new Float:X, Float:Y, Float:Z, Float:R;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, R);
new vid = random(sizeof(RandomVehicles));
new v = RandomVehicles[vid];
new color1 = random(128);
new color2 = random(128);
new vehicle = CreateVehicle(v, X, Y, Z, R, 0, 0, 60000);
ChangeVehicleColor(vehicle, color1, color2);
PutPlayerInVehicle(playerid, vehicle, 0);
for(new i = 0; i < sizeof(TempVehicles); i++)
{
if(TempVehicles[i] == INVALID_VEHICLE_ID)
{
TempVehicles[i] = vehicle;
break;
}
}
}
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(IsPlayerConnected(playerid))
{
if(newstate == PLAYER_STATE_DRIVER)
{
if(Player[playerid][AdminLevel] >= 3)
{
new vehicle = GetPlayerVehicleID(playerid);
new engine, lights, alarm, doors, hood, trunk, objective;
if(TempVehicles[vehicle])
{
GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, hood, trunk, objective);
SetVehicleParamsEx(vehicle, VEHICLE_PARAMS_ON, lights, alarm, doors, hood, trunk, objective);
}
}
}
}
return 1;
}
Re: Max Vehicles 200? -
HazardouS - 02.01.2015
pawn Код:
for(new i = 0; i < sizeof(TempVehicles); i++)
{
if(TempVehicles[i] == INVALID_VEHICLE_ID)
{
TempVehicles[i] = vehicle;
break;
}
}
What are you doing here? You should do something like this instead of that for()
pawn Код:
TempVehicles[vehicle-1] = 1; //or some other value that's not INVALID_VEHICLE_ID (65535); vehicle-1 because array index starts from 0 and vehicle ids start from 1
//and
if(TempVehicles[vehicle-1] != INVALID_VEHICLE_ID)
{
GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, hood, trunk, objective);
SetVehicleParamsEx(vehicle, VEHICLE_PARAMS_ON, lights, alarm, doors, hood, trunk, objective);
}
and you should consider resetting TempVehicles[vehicle-1] to INVALID after deleting it or something...
Re: Max Vehicles 200? -
Alvord - 02.01.2015
Edit: Nevermind, it still stops at ID 200.
Re: Max Vehicles 200? -
Alvord - 02.01.2015
Isn't it weird that it stops at ID 200? I mean, I could still spawn a temporary vehicle but then ID 200 couldn't be manipulated anymore. I tried to do this:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(IsPlayerConnected(playerid))
{
if(newstate == PLAYER_STATE_DRIVER)
{
if(Player[playerid][AdminLevel] >= 3)
{
new vehicle = GetPlayerVehicleID(playerid);
new engine, lights, alarm, doors, hood, trunk, objective;
if(TempVehicles[vehicle] != INVALID_VEHICLE_ID)
{
GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, hood, trunk, objective);
SetVehicleParamsEx(vehicle, VEHICLE_PARAMS_ON, lights, alarm, doors, hood, trunk, objective);
new string[64];
format(string, sizeof(string), "Game ID: %d | Temp ID: %d", vehicle, TempVehicles[vehicle]);
SendClientMessage(playerid, 0xFFFFFFFF, string);
}
}
}
}
return 1;
}
If it's under ID 200 it shows:
Game ID: 198 | Temp ID: 198
Game ID: 199 | Temp ID: 199
but if I spawn the 200th vehicle, the message fails to show.