[HELP] Case scripting
#1

Dear all,

I just started to learn scripting in pawno but got a small problem with the following script,

Код:
        switch(Maps)
        {
        	case 0: // map1
            {
            	SetPlayerInterior(i,0);
                SendRconCommand("loadfs map1");
				Minutes =0;  // 0:40 min
				Seconds =40;  // 0:40 min
			}
            case 1: // map2
            {
            	SetPlayerInterior(i,0);
                SendRconCommand("unloadfs map1");
                SendRconCommand("loadfs map2");
				Minutes =0;  // 0:40 min
				Seconds =40;  // 0:40 min
			}
            case 2:
            {
                SendRconCommand("unloadfs map2");
                GameTextForAll("~r~Restarting server maps",6000,4);
                SendRconCommand("gmx");
                Maps = 0;
			}
		}
	}
    return 1;
Im making a basic dm server and i want that it goes from case 1 to 0 without server restarting, but till now i cant fix this.

i did now with rcon gmx so the whole server will restart and i dont like that, can one of you help me out please?

Kind regards,
FeniX,
Reply
#2

Well, you need to destroy the created map when you unload the previous filterscript. Otherwise you just end up with multiple objects on the same place, eventually crashing your server (without GMX).

So basically, you can do:
pawn Код:
new Objects[MAX_OBJECTS]; //At the top of your script
Where 'MAX_OBJECTS' is the highest number of objects that you have in your map.

Then under OnFilterScriptInit():
pawn Код:
Objects[0] = CreateObject(...
Objects[1] = CreateObject(...
Objects[2] = CreateObject(...
//etc.
Objects[MAX_OBJECTS - 1] = CreateObject(...
Note that you cannot reach 'MAX_OBJECTS', you are limited to one less than that, as elements start at 0 not 1.

Then under OnFilterScriptExit, you simply delete the objects:
pawn Код:
for(new i = 0; i < MAX_OBJECTS; i++)
{
    if(!IsValidObject(Objects[i])) continue; //Object does not exist, skip. You can break here too, if you want.
    DestroyObject(Objects[i]);
}
Reply
#3

Hi and thanks for your answer, but my objects are in filterscript so when i do unloadfs the objects will dissapear isnt it?

Also my question was not about the objects but about the loop of server maps so when map 2 is reached that it will go back to map 1 without an server restart i search on ****** for long time and even on forums but cant find anything,

maybe you can help me out?
Reply
#4

You mean this?:
pawn Код:
switch(Maps)
        {
            case 0: // map1
            {
                SetPlayerInterior(i, 0);
                SendRconCommand("unloadfs map2");
                SendRconCommand("loadfs map1");
                Minutes = 0;  // 0:40 min
                Seconds = 40;  // 0:40 min
                Maps = 1;
            }
            case 1: // map2
            {
                SetPlayerInterior(i,0);
                SendRconCommand("unloadfs map1");
                SendRconCommand("loadfs map2");
                Minutes =0;  // 0:40 min
                Seconds =40;  // 0:40 min
                Maps = 0;
            }
        }
And yes, the method above will delete objects when the filterscript is unloaded.
Reply
#5

Thanks, i will try it now out, but getting the following warning, on the
SendRconCommand("loadfs map1");
Line

C:\Users\FeniX\Desktop\SAMP Server\gamemodes\test.pwn(111) : warning 217: loose indentation
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Warning.


PS, i added you on skype can you teach me from there?



Edit: i tried ur script but it didnt work it stays on map 2, after that i tried another code like this




Код:
        switch(Maps)
        {
        	case 0: // map1
            {
            	SetPlayerInterior(i,0);
                SendRconCommand("loadfs map1");
				Minutes =0;  // 0:40 min
				Seconds =40;  // 0:40 min
    			Maps = 1;
			}
            case 1: // map2
            {
            	SetPlayerInterior(i,0);
                SendRconCommand("unloadfs map1");
                SendRconCommand("loadfs map2");
				Minutes =0;  // 0:40 min
				Seconds =40;  // 0:40 min
                Maps = 2;
			}
            case 2:
            {
                SendRconCommand("unloadfs map2");
                Maps = 0;
			}
		}
	}
Still no effect, stays on map2

any idea?
Reply
#6

Depends. Where is this code being called?
Reply
#7

public MapsChange(playerid)
{
foreach(Player,i)
{
SpawnPlayer(i);
SetPlayerHealth(i,99.0);
SetPlayerArmour(i,0.0);
ResetPlayerWeapons(i);
RemovePlayerFromVehicle(i);

switch(Maps)
{
case 0: // map1
{
SetPlayerInterior(i,0);
SendRconCommand("loadfs map1");
Minutes =0; // 0:40 min
Seconds =40; // 0:40 min
Maps = 1;
}
case 1: // map2
{
SetPlayerInterior(i,0);
SendRconCommand("unloadfs map1");
SendRconCommand("loadfs map2");
Minutes =0; // 0:40 min
Seconds =40; // 0:40 min
Maps = 2;
}
case 2:
{
SetPlayerInterior(i,0);
SendRconCommand("unloadfs map2");
Minutes =0; // 0:40 min
Seconds =1; // 0:40 min
Maps = 0;
}
}
}
return 1;
}

i tried something difference now but still nothing happends
Reply
#8

pawn Код:
forward MapsChange();
public MapsChange()
{
    foreach(new i : Player)
    {
        SpawnPlayer(i);
        SetPlayerHealth(i,99.0);
        SetPlayerArmour(i,0.0);
        ResetPlayerWeapons(i);
        RemovePlayerFromVehicle(i);
        SetPlayerInterior(i, 0);
    }
    switch(Maps)
    {
        case 0: // map1
        {
            SendRconCommand("unloadfs map2");
            SendRconCommand("loadfs map1");
            Minutes = 0; // 0:40 min
            Seconds = 40; // 0:40 min
            Maps = 1;
        }
        case 1: // map2
        {
            SendRconCommand("unloadfs map1");
            SendRconCommand("loadfs map2");
            Minutes =0; // 0:40 min
            Seconds = 40; // 0:40 min
            Maps = 0;
        }
        default:
        {
            Maps = 0;
            MapsChange();
        }
    }
    return 1;
}
I guess this is on a timer? If so, this should work.
Reply
#9

Yes this is an timer with textdraw each map, i try it for easy way to add maps with fs and for more lagfree server!

but i get now the following

C:\Users\FeniX\Desktop\SAMP Server\gamemodes\test.pwn(136) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Warning.


on the following line: MapsChange();

i can see an problem in samp-server.exe map1 unload failed and map2 load failed all the time
Reply
#10

I would probably go with an approach like this since it's easier to add maps than your other system. I'm not sure what you're using the minutes & seconds for, so it's not very expansive on that aspect.

pawn Код:
new OldMap;

//How many entries we have and then the string size, I put 10 just in case you wanted a different name scheme or had a certain map that was longer etc
new map_Names[2][10] = {
    "map1",
    "map2"
};

stock LoadMap(map)
{
    if(map > sizeof(map_Names)-1 || map < 0) return false;
    new tmp[30];
    Minutes=0;
    Seconds=40;
   
    format(tmp, sizeof(tmp), "unloadfs %s", map_Names[OldMap]);
    SendRconCommand(tmp);
    format(tmp, sizeof(tmp), "loadfs %s", map_Names[map]);
    SendRconCommand(tmp);
    OldMap=map;
   
    return true;
 }
All this is really doing is unloading the previous map and loading the new one in.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)