Changing maps without restarting server?
#1

Title says it..

How do I change mad without the server restarting? Thanks.
Reply
#2

Remove the objects and create the new ones?
Reply
#3

Use the samp map editor to convert the CreateObject code to just raw data.

Example:
pawn Код:
CMD:loadmap(playerid, params[])
{
    new
        mapname[60], // a new string for the mapname
        string[128] // the string that will be formatted as the path
    ;
    if(sscanf(params, "s[60]", mapname)) // if they didn't type a name
    {
        // then it sends this message
        SendClientMessage(playerid, -1, "USAGE: /loadmap [mapname]");
        return 1;
    }
    // if they did type a name then it formats the name with '.txt'
    format(string, 128, "%s.txt", mapname);
    // if the file does not exist
    if(!fexist(string))
    {
        // then it returns this message
        return SendClientMessage(playerid, -1, "Invalid Map Path");
    }
    new
        File:map = fopen(string, io_read), // open the file for reading
        // we then define new variables for the object info.
        model,
        f:x,
        f:y,
        f:z,
        f:rotX,
        f:rotY,
        f:rotZ,
        f:drawdistance,
        szObject[150], // the string to store the file lines in
        objectcount = 0 // the count for the objects
    ;
    // while there is text in the line, we read the line, and store the line into the szObject string
    while(fread(map, szObject))
    {
        // using sscanf, we split the line into the object paramters and if the line does
        // not follow this format ...
        if(sscanf(szObject, "dfffffff", model, x, y, z, rotX, rotY, rotZ, drawdistance))
        {
            // then we print the formatted print on the console
            printf("Invalid Line Format At File: %s", string);
            // and then skip the loop iteration
            continue;
        }
        // we split the line into the object format
        sscanf(szObject, "dfffffff", model, x, y, z, rotX, rotY, rotZ, drawdistance);
        // then we create the object
        CreateObject(model, x, y, z, rotX, rotY, rotZ, drawdistance);
        // and the object count goes up
        objectcount++;
    }
    printf("%d objects loaded from file: %s", objectcount, string);
    fclose(map); // we then close the file
    return 1;
}
That is a VERY rough example, it was just to give you the idea.
Reply
#4

*sigh* change the map with out the gamemode restarting..

Meaning, instead of changemap *mapname* - Nevermind.
Reply
#5

You can do a Vincent has shoed you above or you can place the Objects Directly into your GM.

Example:
pawn Код:
new Map1[60];
new Map2[60];

OnGameModeInit()
{
       Map1[0] = CreateObject(..);
       Map1[1] = CreateObject(..);// Game Mode starter map.
       return 1;
}

Command header here.
{
        for(new i = 0; i < sizeof(Map2); i++)
        {
                     Map2[i] = CreateObject(..);//creates the Map2 defined objects
          }
return 1;
}

Command Header Here.
{
     for(new i = 0; i < sizeof(Map2); i++)
     {
           DestroyObject(Map2[i]);//Destorys the Map2 defined objects
      }
return 1;
}
If you chose this method I can help you further.
Reply
#6

You mean this?
pawn Код:
CMD:changemapname(playerid, params[])
{
    new
        name[60],
        command[128]
    ;
    if(isnull(params)) return SendClientMessage(playerid, -1, "USAGE: /changemapname [newname]");
    format(command, 128, "mapname %s" name);
    SendRconCommand(command);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)