Advertisement
Guest User

Dynamic Map System - SA-MP by kitten

a guest
Sep 11th, 2012
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.43 KB | None | 0 0
  1. #include <a_samp>
  2. #include <foreach>
  3. #include <YSI\y_ini>
  4.  
  5. // Defines
  6. #define function%0(%1) forward%0(%1);public%0(%1)
  7. #define MAX_MAPTIME 60 // Seconds before the map ends (60seconds = 1 minute)
  8. #define MAX_RESTART_TIME 10000 // Seconds before to load the next map (10000ms = 10 seconds)
  9. #define MAX_MAPUPDATE_TIME 1000 // Seconds to count down until the map ends this is only for the function! (to decrease the map time) (1000ms = 1 seconds)
  10. #define MAX_END_TIME 2000 // Seconds before it ends the map with the callback OnMapUpdate (2000ms = 2 seconds)
  11. #define MAX_MAP_FILES 2 // Change this to amount of map files you have or else the map system will be bugged
  12.  
  13. #define DIALOG_SELECT_TEAM 0
  14.  
  15. #define TEAM_1 1
  16. #define TEAM_2 2
  17.  
  18. // Variables
  19. new time; // Goes towards MAX_MAPTIME
  20. new mapvar; // Variable assigning to the map timer
  21. new mapid; // Pretty obvious
  22. new team[MAX_PLAYERS]; // basic team system to test. (spawns etc)
  23. new LastMapStarted = -1; // Pretty obvious
  24.  
  25. enum mapinfo
  26. {
  27. MapName[128],
  28. FSMapName[128],
  29. Float:Team1X,
  30. Float:Team1Y,
  31. Float:Team1Z,
  32. Float:Team2X,
  33. Float:Team2Y,
  34. Float:Team2Z,
  35. Interior,
  36. Weather,
  37. Time
  38. };
  39. new Map[mapinfo];
  40.  
  41. forward load_Map_basic(Mapid, name[], value[]);
  42.  
  43. main () {}
  44.  
  45. function StartMap()
  46. {
  47. foreach(Player,i)
  48. {
  49. SpawnPlayer(i); // Spawns the player to the new map
  50. // Just a note you can add variables here also such as Resetting First kill or any variable just based on the map.
  51. }
  52.  
  53. time = MAX_MAPTIME; // Setting the variable define to MAX_MAPTIME!
  54.  
  55. SetWeather(Map[Weather]); // The integer you've entered on the map file (weather)
  56. SetWorldTime(Map[Time]); // The integer you've entered on the map file (time)
  57.  
  58. mapvar = SetTimer("OnMapUpdate",MAX_MAPUPDATE_TIME,true); // Self explained
  59. return 1;
  60. }
  61.  
  62. function EndMap()
  63. {
  64. ClearObjects(); // If your map file has objects and it's loaded in a filterscript or not, it'll delete all the objects for that specific map.
  65. UnloadFilterScript(Map[FSMapName]); // Unloading the filterscript for the map. (you can include commands for that map, objects etc)
  66. LoadMap(LoadNewMap()); // Loading the new map information.
  67. LoadFilterScript(Map[FSMapName]); // Loading the new map filterscript.
  68.  
  69. SetTimer("StartMap",MAX_RESTART_TIME,false);
  70. return 1;
  71. }
  72.  
  73. function OnMapUpdate()
  74. {
  75. time -= 1; // Decreasing the map time by 60ms
  76. if(time <= 0) KillTimer(mapvar),SetTimer("EndMap",MAX_END_TIME,false); // If the map time has reached to zero gets the next map ID in that callback then loads it
  77. /* You can also add other variables such as if(time <= 50) SendClientMessageToAll(-1,"50 Seconds left till next map"); */
  78.  
  79. new str[64];
  80. format(str,sizeof(str),"Time: %i",time);
  81. SendClientMessageToAll(-1,str); // This sends how much time is left for debug purposes.
  82. return 1;
  83. }
  84.  
  85. public OnGameModeInit()
  86. {
  87. SetGameModeText("DYT - By Kitten");
  88. SendRconCommand("hostname Dynamic Map System Test");
  89.  
  90. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  91.  
  92. mapid = 0; // Resetting the map ID to zero so it loads the map from zero you can also make commands to set map id's
  93. LoadMap(LoadNewMap()); // Loading the first map in the folder list.
  94. StartMap(); // Loading the map info
  95. return 1;
  96. }
  97.  
  98. public OnGameModeExit()
  99. {
  100. return 1;
  101. }
  102.  
  103. public OnPlayerRequestClass(playerid, classid)
  104. {
  105. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  106. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  107. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  108. return 1;
  109. }
  110.  
  111. public OnPlayerConnect(playerid)
  112. {
  113. team[playerid] = 0;
  114. ShowPlayerDialog(playerid,DIALOG_SELECT_TEAM,DIALOG_STYLE_MSGBOX,"Team Selection","Select an team","Team 1","Team 2");
  115. return 1;
  116. }
  117.  
  118. public OnPlayerDisconnect(playerid, reason) return team[playerid] = 0;
  119.  
  120. public OnPlayerSpawn(playerid)
  121. {
  122. SetPlayerInterior(playerid,Map[Interior]); // Setting the map interior
  123. if(team[playerid] == TEAM_1) SetPlayerPos(playerid,Map[Team1X],Map[Team1Y],Map[Team1Z]); // Setting team 1 position from the file.
  124. if(team[playerid] == TEAM_2) SetPlayerPos(playerid,Map[Team2X],Map[Team2Y],Map[Team2Z]); // ^
  125. return 1;
  126. }
  127.  
  128. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  129. {
  130. switch(dialogid)
  131. {
  132. case DIALOG_SELECT_TEAM:
  133. {
  134. if(response) team[playerid] = TEAM_1,SpawnPlayer(playerid);
  135. if(!response) team[playerid] = TEAM_2,SpawnPlayer(playerid);
  136. }
  137. }
  138. return 1;
  139. }
  140.  
  141. stock GetMapCount()
  142. {
  143. new mcount = 0, file[128];
  144. for(new i = 0; i < MAX_MAP_FILES; i++)
  145. {
  146. format(file, sizeof(file), "/Maps/%d.ini", i);
  147. if(fexist(file))
  148. {
  149. mcount ++;
  150. }
  151. }
  152. return mcount;
  153. }
  154.  
  155. stock GetFreeMapID()
  156. {
  157. new file[32], id = 0;
  158. for(new i = 0; i < MAX_MAP_FILES; i++)
  159. {
  160. format(file, sizeof(file), "/Maps/%d.ini", i);
  161. if(fexists(file)) continue;
  162. id = i;
  163. break;
  164. }
  165. return id;
  166. }
  167.  
  168. stock NoMapCheck()
  169. {
  170. new tcount = 0, file[128];
  171. for(new i = 0; i < MAX_MAP_FILES; i++)
  172. {
  173. format(file, sizeof(file), "/Maps/%d.ini", i);
  174. if(fexist(file))
  175. {
  176. tcount ++;
  177. }
  178. }
  179. if(tcount == 0)
  180. {
  181. print("_____________________________________________________________");
  182. print("WARNING: The server has detected there are no map files!");
  183. print("currently installed. The server has been set to");
  184. print("automatically shut down in 25000/ MS. (25 Seconds)");
  185. print("_____________________________________________________________");
  186. SetTimer("No_Maps", 25000, false);
  187. return 1;
  188. }
  189. return 1;
  190. }
  191.  
  192. function No_Maps() return SendRconCommand("exit");
  193.  
  194. public load_Map_basic(Mapid, name[], value[])
  195. {
  196. if(strcmp(name, "FSMapName", true) == 0)
  197. {
  198. strmid(Map[FSMapName], value, false, strlen(value), 128);
  199. LoadFilterScript(Map[FSMapName]);
  200.  
  201. }
  202.  
  203. /*printf("[Debug] Name: %s - Value: %s", name, value); For Debug Purposes*/
  204.  
  205. if(strcmp(name, "MapName", true) == 0)
  206. {
  207. new mpname[50];
  208. strmid(Map[MapName], value, false, strlen(value), 128);
  209. format(mpname, sizeof(mpname), "mapname %s", Map[MapName]);
  210. SendRconCommand(mpname);
  211. }
  212. if(strcmp(name, "Team1X", true) == 0) Map[Team1X] = floatstr(value);
  213. if(strcmp(name, "Team1Y", true) == 0) Map[Team1Y] = floatstr(value);
  214. if(strcmp(name, "Team1Z", true) == 0) Map[Team1Z] = floatstr(value);
  215. if(strcmp(name, "Team2X", true) == 0) Map[Team2X] = floatstr(value);
  216. if(strcmp(name, "Team2Y", true) == 0) Map[Team2Y] = floatstr(value);
  217. if(strcmp(name, "Team2Z", true) == 0) Map[Team2Z] = floatstr(value);
  218. if(strcmp(name, "Interior", true) == 0) Map[Interior] = strval(value);
  219. if(strcmp(name, "Weather", true) == 0)
  220. {
  221. Map[Weather] = strval(value);
  222. SetWeather(Map[Weather]);
  223. }
  224.  
  225. if(strcmp(name, "Time", true) == 0)
  226. {
  227. Map[Time] = strval(value);
  228. SetWorldTime(Map[Time]);
  229. printf("Map ID %d's Information Has Been Loaded.", Mapid);
  230. }
  231. return 1;
  232. }
  233.  
  234. stock LoadMap(Mapid)
  235. {
  236. new Map_file[64];
  237. format(Map_file, sizeof(Map_file), "/Maps/%d.ini", Mapid);
  238. if(fexist(Map_file))
  239. {
  240. printf("loading Map %s", Map_file);
  241. INI_ParseFile(Map_file, "load_Map_%s", .bExtra = true, .extra = Mapid);
  242. return 1;
  243. }
  244. return 0;
  245. }
  246.  
  247. stock LoadNewMap()
  248. {
  249. new file[64];
  250. mapid %= MAX_MAP_FILES;
  251. format(file, sizeof(file), "/Maps/%d.ini", mapid);
  252. if(!fexist(file)) return printf("[NOTICE] File Bugged.");
  253. LastMapStarted = mapid;
  254. mapid++;
  255. return mapid-1;
  256. }
  257.  
  258. stock ClearObjects()
  259. {
  260. for(new i; i<MAX_OBJECTS; i++)
  261. {
  262. if(IsValidObject(i)) DestroyObject(i);
  263. }
  264. }
  265.  
  266. stock GetRandomMap()
  267. {
  268. new file[64];
  269. new i = 0, count = 0, Maps[MAX_MAP_FILES], Mapid;
  270. for( ; i != MAX_MAP_FILES; ++i)
  271. {
  272. if(LastMapStarted == i) continue;
  273. format(file, sizeof(file), "/Maps/%d.ini", i);
  274. if(fexist(file))
  275. {
  276. Maps[count] = i;
  277. count++;
  278. }
  279. }
  280. if(count == 0)
  281. {
  282. return NoMapCheck();
  283. }
  284. Mapid = Maps[random(count)];
  285.  
  286. format(file, sizeof(file), "/Maps/%d.ini", Mapid);
  287. if(fexist(file))
  288. {
  289. LastMapStarted = Mapid;
  290. return Mapid;
  291. }
  292. else return printf("[NOTICE] File Bugged.");
  293. }
  294.  
  295. stock LoadFilterScript(filename[])
  296. {
  297. new string[128];
  298. format(string, sizeof(string), "loadfs %s", filename);
  299. SendRconCommand(string);
  300. return 1;
  301. }
  302.  
  303. stock UnloadFilterScript(filename[])
  304. {
  305. new string[128];
  306. format(string, sizeof(string), "unloadfs %s", filename);
  307. SendRconCommand(string);
  308. return 1;
  309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement