Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <foreach>
- #include <YSI\y_ini>
- // Defines
- #define function%0(%1) forward%0(%1);public%0(%1)
- #define MAX_MAPTIME 60 // Seconds before the map ends (60seconds = 1 minute)
- #define MAX_RESTART_TIME 10000 // Seconds before to load the next map (10000ms = 10 seconds)
- #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)
- #define MAX_END_TIME 2000 // Seconds before it ends the map with the callback OnMapUpdate (2000ms = 2 seconds)
- #define MAX_MAP_FILES 2 // Change this to amount of map files you have or else the map system will be bugged
- #define DIALOG_SELECT_TEAM 0
- #define TEAM_1 1
- #define TEAM_2 2
- // Variables
- new time; // Goes towards MAX_MAPTIME
- new mapvar; // Variable assigning to the map timer
- new mapid; // Pretty obvious
- new team[MAX_PLAYERS]; // basic team system to test. (spawns etc)
- new LastMapStarted = -1; // Pretty obvious
- enum mapinfo
- {
- MapName[128],
- FSMapName[128],
- Float:Team1X,
- Float:Team1Y,
- Float:Team1Z,
- Float:Team2X,
- Float:Team2Y,
- Float:Team2Z,
- Interior,
- Weather,
- Time
- };
- new Map[mapinfo];
- forward load_Map_basic(Mapid, name[], value[]);
- main () {}
- function StartMap()
- {
- foreach(Player,i)
- {
- SpawnPlayer(i); // Spawns the player to the new map
- // Just a note you can add variables here also such as Resetting First kill or any variable just based on the map.
- }
- time = MAX_MAPTIME; // Setting the variable define to MAX_MAPTIME!
- SetWeather(Map[Weather]); // The integer you've entered on the map file (weather)
- SetWorldTime(Map[Time]); // The integer you've entered on the map file (time)
- mapvar = SetTimer("OnMapUpdate",MAX_MAPUPDATE_TIME,true); // Self explained
- return 1;
- }
- function EndMap()
- {
- 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.
- UnloadFilterScript(Map[FSMapName]); // Unloading the filterscript for the map. (you can include commands for that map, objects etc)
- LoadMap(LoadNewMap()); // Loading the new map information.
- LoadFilterScript(Map[FSMapName]); // Loading the new map filterscript.
- SetTimer("StartMap",MAX_RESTART_TIME,false);
- return 1;
- }
- function OnMapUpdate()
- {
- time -= 1; // Decreasing the map time by 60ms
- 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
- /* You can also add other variables such as if(time <= 50) SendClientMessageToAll(-1,"50 Seconds left till next map"); */
- new str[64];
- format(str,sizeof(str),"Time: %i",time);
- SendClientMessageToAll(-1,str); // This sends how much time is left for debug purposes.
- return 1;
- }
- public OnGameModeInit()
- {
- SetGameModeText("DYT - By Kitten");
- SendRconCommand("hostname Dynamic Map System Test");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- 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
- LoadMap(LoadNewMap()); // Loading the first map in the folder list.
- StartMap(); // Loading the map info
- return 1;
- }
- public OnGameModeExit()
- {
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- team[playerid] = 0;
- ShowPlayerDialog(playerid,DIALOG_SELECT_TEAM,DIALOG_STYLE_MSGBOX,"Team Selection","Select an team","Team 1","Team 2");
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason) return team[playerid] = 0;
- public OnPlayerSpawn(playerid)
- {
- SetPlayerInterior(playerid,Map[Interior]); // Setting the map interior
- if(team[playerid] == TEAM_1) SetPlayerPos(playerid,Map[Team1X],Map[Team1Y],Map[Team1Z]); // Setting team 1 position from the file.
- if(team[playerid] == TEAM_2) SetPlayerPos(playerid,Map[Team2X],Map[Team2Y],Map[Team2Z]); // ^
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case DIALOG_SELECT_TEAM:
- {
- if(response) team[playerid] = TEAM_1,SpawnPlayer(playerid);
- if(!response) team[playerid] = TEAM_2,SpawnPlayer(playerid);
- }
- }
- return 1;
- }
- stock GetMapCount()
- {
- new mcount = 0, file[128];
- for(new i = 0; i < MAX_MAP_FILES; i++)
- {
- format(file, sizeof(file), "/Maps/%d.ini", i);
- if(fexist(file))
- {
- mcount ++;
- }
- }
- return mcount;
- }
- stock GetFreeMapID()
- {
- new file[32], id = 0;
- for(new i = 0; i < MAX_MAP_FILES; i++)
- {
- format(file, sizeof(file), "/Maps/%d.ini", i);
- if(fexists(file)) continue;
- id = i;
- break;
- }
- return id;
- }
- stock NoMapCheck()
- {
- new tcount = 0, file[128];
- for(new i = 0; i < MAX_MAP_FILES; i++)
- {
- format(file, sizeof(file), "/Maps/%d.ini", i);
- if(fexist(file))
- {
- tcount ++;
- }
- }
- if(tcount == 0)
- {
- print("_____________________________________________________________");
- print("WARNING: The server has detected there are no map files!");
- print("currently installed. The server has been set to");
- print("automatically shut down in 25000/ MS. (25 Seconds)");
- print("_____________________________________________________________");
- SetTimer("No_Maps", 25000, false);
- return 1;
- }
- return 1;
- }
- function No_Maps() return SendRconCommand("exit");
- public load_Map_basic(Mapid, name[], value[])
- {
- if(strcmp(name, "FSMapName", true) == 0)
- {
- strmid(Map[FSMapName], value, false, strlen(value), 128);
- LoadFilterScript(Map[FSMapName]);
- }
- /*printf("[Debug] Name: %s - Value: %s", name, value); For Debug Purposes*/
- if(strcmp(name, "MapName", true) == 0)
- {
- new mpname[50];
- strmid(Map[MapName], value, false, strlen(value), 128);
- format(mpname, sizeof(mpname), "mapname %s", Map[MapName]);
- SendRconCommand(mpname);
- }
- if(strcmp(name, "Team1X", true) == 0) Map[Team1X] = floatstr(value);
- if(strcmp(name, "Team1Y", true) == 0) Map[Team1Y] = floatstr(value);
- if(strcmp(name, "Team1Z", true) == 0) Map[Team1Z] = floatstr(value);
- if(strcmp(name, "Team2X", true) == 0) Map[Team2X] = floatstr(value);
- if(strcmp(name, "Team2Y", true) == 0) Map[Team2Y] = floatstr(value);
- if(strcmp(name, "Team2Z", true) == 0) Map[Team2Z] = floatstr(value);
- if(strcmp(name, "Interior", true) == 0) Map[Interior] = strval(value);
- if(strcmp(name, "Weather", true) == 0)
- {
- Map[Weather] = strval(value);
- SetWeather(Map[Weather]);
- }
- if(strcmp(name, "Time", true) == 0)
- {
- Map[Time] = strval(value);
- SetWorldTime(Map[Time]);
- printf("Map ID %d's Information Has Been Loaded.", Mapid);
- }
- return 1;
- }
- stock LoadMap(Mapid)
- {
- new Map_file[64];
- format(Map_file, sizeof(Map_file), "/Maps/%d.ini", Mapid);
- if(fexist(Map_file))
- {
- printf("loading Map %s", Map_file);
- INI_ParseFile(Map_file, "load_Map_%s", .bExtra = true, .extra = Mapid);
- return 1;
- }
- return 0;
- }
- stock LoadNewMap()
- {
- new file[64];
- mapid %= MAX_MAP_FILES;
- format(file, sizeof(file), "/Maps/%d.ini", mapid);
- if(!fexist(file)) return printf("[NOTICE] File Bugged.");
- LastMapStarted = mapid;
- mapid++;
- return mapid-1;
- }
- stock ClearObjects()
- {
- for(new i; i<MAX_OBJECTS; i++)
- {
- if(IsValidObject(i)) DestroyObject(i);
- }
- }
- stock GetRandomMap()
- {
- new file[64];
- new i = 0, count = 0, Maps[MAX_MAP_FILES], Mapid;
- for( ; i != MAX_MAP_FILES; ++i)
- {
- if(LastMapStarted == i) continue;
- format(file, sizeof(file), "/Maps/%d.ini", i);
- if(fexist(file))
- {
- Maps[count] = i;
- count++;
- }
- }
- if(count == 0)
- {
- return NoMapCheck();
- }
- Mapid = Maps[random(count)];
- format(file, sizeof(file), "/Maps/%d.ini", Mapid);
- if(fexist(file))
- {
- LastMapStarted = Mapid;
- return Mapid;
- }
- else return printf("[NOTICE] File Bugged.");
- }
- stock LoadFilterScript(filename[])
- {
- new string[128];
- format(string, sizeof(string), "loadfs %s", filename);
- SendRconCommand(string);
- return 1;
- }
- stock UnloadFilterScript(filename[])
- {
- new string[128];
- format(string, sizeof(string), "unloadfs %s", filename);
- SendRconCommand(string);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement