24.05.2017, 08:03
Is it possible to loop through all vehicles, engine activated or not? See, I'm making this system and somewhere in it, it requires all created vehicles to be teleported somewhere.
Yes, of course it is...All vehicles have an ID, and there is MAX_VEHICLES, or GetVehiclePoolSize.
Engine being activated has nothing to do with it. |
for(new i; i < GetVehiclePoolSize()+1; i++)
{
if( GetVehicleMass( i ) >= 2400.0 )
{
SetVehicleAngularVelocity( i, 0.05, 0.3, 0.08 );
}
else
{
SetVehicleAngularVelocity( i, 0.015, 0.15, 0.15 );
}
}
[16:14:01] [debug] Run time error 4: "Array index out of bounds" [16:14:01] [debug] Accessing element at negative index -400 [16:14:01] [debug] AMX backtrace: [16:14:01] [debug] #0 0002bf38 in ?? (0) from gm.amx [16:14:01] [debug] #1 0018801c in public TestEffect () from gm.amx
public TestEffect(playerid)
{
switch(random(3))
{
case 0:
{
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) SetPlayerVelocity(playerid, 0.03, 0.0, 0.05);
}
case 1:
{
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) SetPlayerVelocity(playerid, 0.05, 0.0, 0.02);
}
case 2:
{
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) SetPlayerVelocity(playerid, 0.01, 0.05, 0.03);
}
}
for(new vid; vid < GetVehiclePoolSize()+1; vid++)
{
if( GetVehicleMass( vid ) >= 2400.0 ){
SetVehicleAngularVelocity( vid, qmag * 0.03, qmag * 0.03, qmag * 0.03 );
} else SetVehicleAngularVelocity( vid, qmag * 0.05, qmag * 0.05, qmag * 0.05 );
}
new qint = floatround(qmag , floatround_round);
SetPlayerDrunkLevel(playerid, qint* 10000);
return 1;
}
for(new vid; vid < GetVehiclePoolSize()+1; vid++)
for(new i = 1, j = GetVehiclePoolSize(); i <= j; i++)
Ah well, if you give up that easily, then obviously you're not interested in learning how to go further.
You've got playerstates, and other checks in that function... It wouldn't be that hard to remove those, and isolate the issue. If the error came back exactly the same when you used the example code, then chances are the error could be in another section of that function. Hence why I said why do you have all that crud in there... |
new i = GetPlayerVehicleID(playerid);
if( GetVehicleMass( i ) >= 2400.0 )
{
SetVehicleAngularVelocity( i, 0.05, 0.3, 0.08 );
}
else
{
SetVehicleAngularVelocity( i, 0.015, 0.15, 0.15 );
}
new vid = GetPlayerVehicleID(playerid);
if( GetVehicleMass( vid ) >= 2400.0 ){
SetVehicleAngularVelocity( vid, 0.03, 0.03, 0.03 );
} else SetVehicleAngularVelocity( vid, 0.015, 0.015, 0.015 );