Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void spawn_lots_of_cars()
- {
- //This can definitely crash the game, be careful
- const int NUM_ROWS = 4;
- const int NUM_COLS = 35;
- const float xSpacing = 3.0;
- const float ySpacing = 4.0;
- const float initialX = -(xSpacing * NUM_ROWS) / 2;
- const float initialY = 5.0;
- //Cache everything so we can set them as unneeded once we are done.
- Vehicle vehicles[NUM_COLS][NUM_ROWS];
- Any pedestrians[NUM_COLS][NUM_ROWS];
- LPCSTR modelName = "NINEF";
- DWORD singleModel = GAMEPLAY::GET_HASH_KEY((char *)modelName);
- STREAMING::REQUEST_MODEL(singleModel);
- while (!STREAMING::HAS_MODEL_LOADED(singleModel)) WAIT(0);
- for (int col = 0; col < NUM_COLS; ++col)
- {
- for (int row = 0; row < NUM_ROWS; ++row)
- {
- Vector3 coords = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(PLAYER::PLAYER_PED_ID(), initialX + xSpacing * row, initialY + ySpacing * col, 0.0);
- float heading = ENTITY::GET_ENTITY_HEADING(PLAYER::PLAYER_PED_ID());
- Vehicle currentVehicle = vehicles[col][row] = VEHICLE::CREATE_VEHICLE(singleModel, coords.x, coords.y, coords.z, heading + 180, 1, 1);
- //This doesn't seem to work on slopes
- VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(currentVehicle);
- pedestrians[col][row] = PED::CREATE_RANDOM_PED_AS_DRIVER(currentVehicle, 1);
- }
- }
- WAIT(0);
- //Cleanup
- STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(singleModel);
- for (int col = 0; col < NUM_COLS; ++col)
- {
- for (int row = 0; row < NUM_ROWS; ++row)
- {
- ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&vehicles[col][row]);
- ENTITY::SET_PED_AS_NO_LONGER_NEEDED(&pedestrians[col][row]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement