Guest User

Untitled

a guest
Sep 13th, 2010
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. //
  2. // MTA .map loader by mick88
  3. // Release 0.1
  4. // 13th September 2010
  5. //
  6. // MTA .map files supported for MTA verion 1.0.4,
  7. // other versions not tested
  8. //
  9. // Requirements: SSCANF2 plugin by Y_Less
  10. //
  11. //
  12. // FS commands for RCON admin: /LoadMtaMap [file path) - loads .map file
  13. // /DeleteVehicles - deletes all spawned vehicles
  14. // /DeleteObjects - deletes all created objects
  15. //
  16. // Public function: LoadMtaMap(file[]) - loads .map file
  17. //
  18. //
  19. // Supported map items: objects, vehicles
  20. //
  21. // Supported object data: model, posX, posY, posZ, rotX, rotY, rotZ
  22. // Supported vehicle data: model, paintjob, mods (upgrades), colors (2 colors),
  23. // posX, posY, posZ, rotZ, interior, world (dimension)
  24. //
  25. // Currently not supported:
  26. // 3rd nad 4th vehicle colors, vehicle registration, vehicle rotations X and Y
  27. //
  28. //
  29.  
  30. #include <a_samp>
  31. #include <sscanf2>
  32.  
  33. #define ADD_OBJECT(%1) CreateObject(%1) //Change this if you use a streamer i.e. to CreateDynamicObject(%1) for Incognito's streamer etc.
  34. //the function must have format: model x y z rx ry rz
  35. #define DELETE_OBJECT(%1) DestroyObject(%1) //Change this if you use a streamer
  36. #define MAX_CREATED_OBJECTS MAX_OBJECTS //max id of object to be deleted. Change if you use a streamer
  37.  
  38. #define VEHICLE_RESPAWN_DELAY 60*5 //60*5 is 5 minutes
  39.  
  40. #define MAX_MODS 14 //there is 14 vehicle component slots in gta (0-13)
  41.  
  42. forward LoadMtaMap(file[]);
  43. public LoadMtaMap(file[])
  44. {
  45. if (!fexist(file)) return 0;
  46. new File:MapFile=fopen(file);
  47. new n, string[400];
  48. new Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz;
  49. new modelid, paintjob, interior, world;
  50. while(fread(MapFile, string))
  51. {
  52. if (!sscanf(string, "p<\">'object''model='d'interior='d'dimension='d'posX='f'posY='f'posZ='f'rotX='f'rotY='f'rotZ='f", modelid, interior, world, x, y, z, rx, ry, rz))
  53. {
  54. n++;
  55. //modelid x y z rx ry rz interior world
  56. ADD_OBJECT(modelid, x, y, z, rx, ry, rz);
  57. }
  58. else if (!sscanf(string, "p<\">'vehicle''paintjob='d'model='d'interior='d'dimension='d'posX='f'posY='f'posZ='f'rotZ='f", paintjob, modelid, interior, world, x, y, z, rz))
  59. {
  60. n++;
  61.  
  62. new col1, col2, colors[20];
  63. sscanf(string, "p<\">'color='s[20] ", colors);
  64. sscanf(colors, "p<,>dd", col1, col2);
  65. new mods[80], mod[MAX_MODS];
  66. sscanf(string, "p<\">'upgrades='s[80] ", mods);
  67. sscanf(mods, "p<,>A<d>(0)["#MAX_MODS"]", mod);
  68.  
  69. //modelid x y z rz col1 col2 paintjob interior world
  70. new vehicleid = CreateVehicle(modelid, x, y, z, rz, col1, col2, VEHICLE_RESPAWN_DELAY);
  71. for (new i; i < MAX_MODS; i++) if (mod[i]) AddVehicleComponent(vehicleid, mod[i]);
  72. ChangeVehiclePaintjob(vehicleid, paintjob);
  73. LinkVehicleToInterior(vehicleid, interior);
  74. SetVehicleVirtualWorld(vehicleid, world);
  75. }
  76. }
  77. fclose(MapFile);
  78. printf("%d items loaded from '%s'", n, file);
  79. return n;
  80. }
  81.  
  82. public OnFilterScriptInit()
  83. {
  84. return 1;
  85. }
  86.  
  87. public OnPlayerCommandText(playerid, cmdtext[])
  88. {
  89. if (!IsPlayerAdmin(playerid)) return false; //Admin commands
  90. new command[32], param[64];
  91. if (sscanf(cmdtext[1], "s[32]S()[64]", command, param)) return false;
  92. if (!strcmp(command, "loadmtamap"))
  93. {
  94. if (!param[0]) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /LoadMtaMap [file path]");
  95. new msg[128];
  96. new n = LoadMtaMap(param);
  97. format(msg, 128, "%d items loaded from %s", n, param);
  98. SendClientMessage(playerid, 0xFFFFFFFF, msg);
  99. return 1;
  100. }
  101. else if (!strcmp(command, "deletevehicles"))
  102. {
  103. for (new i=1; i < MAX_VEHICLES; i++) DestroyVehicle(i);
  104. SendClientMessage(playerid, 0xFFFFFFFF, "All vehices have been destroyed!");
  105. return 1;
  106. }
  107. else if (!strcmp(command, "deleteobjects"))
  108. {
  109. for (new i=1; i < MAX_CREATED_OBJECTS; i++) DELETE_OBJECT(i);
  110. SendClientMessage(playerid, 0xFFFFFFFF, "All objects have been deleted!");
  111. return 1;
  112. }
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment