Advertisement
djhonga2001

Untitled

Dec 28th, 2016
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. void spawn_lots_of_cars()
  2. {
  3. //This can definitely crash the game, be careful
  4. const int NUM_ROWS = 4;
  5. const int NUM_COLS = 35;
  6.  
  7. const float xSpacing = 3.0;
  8. const float ySpacing = 4.0;
  9.  
  10. const float initialX = -(xSpacing * NUM_ROWS) / 2;
  11. const float initialY = 5.0;
  12.  
  13. //Cache everything so we can set them as unneeded once we are done.
  14. Vehicle vehicles[NUM_COLS][NUM_ROWS];
  15. Any pedestrians[NUM_COLS][NUM_ROWS];
  16.  
  17. LPCSTR modelName = "NINEF";
  18. DWORD singleModel = GAMEPLAY::GET_HASH_KEY((char *)modelName);
  19. STREAMING::REQUEST_MODEL(singleModel);
  20. while (!STREAMING::HAS_MODEL_LOADED(singleModel)) WAIT(0);
  21.  
  22. for (int col = 0; col < NUM_COLS; ++col)
  23. {
  24. for (int row = 0; row < NUM_ROWS; ++row)
  25. {
  26. Vector3 coords = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(PLAYER::PLAYER_PED_ID(), initialX + xSpacing * row, initialY + ySpacing * col, 0.0);
  27. float heading = ENTITY::GET_ENTITY_HEADING(PLAYER::PLAYER_PED_ID());
  28. Vehicle currentVehicle = vehicles[col][row] = VEHICLE::CREATE_VEHICLE(singleModel, coords.x, coords.y, coords.z, heading + 180, 1, 1);
  29.  
  30. //This doesn't seem to work on slopes
  31. VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(currentVehicle);
  32.  
  33. pedestrians[col][row] = PED::CREATE_RANDOM_PED_AS_DRIVER(currentVehicle, 1);
  34. }
  35. }
  36.  
  37. WAIT(0);
  38.  
  39. //Cleanup
  40. STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(singleModel);
  41. for (int col = 0; col < NUM_COLS; ++col)
  42. {
  43. for (int row = 0; row < NUM_ROWS; ++row)
  44. {
  45. ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&vehicles[col][row]);
  46. ENTITY::SET_PED_AS_NO_LONGER_NEEDED(&pedestrians[col][row]);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement