SA-MP Forums Archive
Random zones - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Random zones (/showthread.php?tid=590627)



Random zones - Counterafk - 01.10.2015

I'm making a low-quality DM server for myself and a couple of friends and I was hoping someone could help me

Pretty much what I want is to make random dm areas with their separate spawns, that change every 10 minutes, sort of like an always on-going random rotation.

I havent seen this before so I dont know how complex it is to make, nor do I know where to start.

Code/idea of what I want below:
Код:
new gFlintCountyZoneSpawn[][] =
{
	{X,Y,Z},
	{X,Y,Z},
	{X,Y,Z}
};

//And then make one for another spot?

new gIdlewoodZoneSpawn[][] =
{
	{X,Y,Z},
	{X,Y,Z},
	{X,Y,Z}
};


public OnGameModeInit()
{
	gRandomZoneTimer = SetTimer("ChangeRandomZone", 60000, true);
	return 1;
}

forward ChangeRandomZone();
public ChangeRandomZone()
{
?????????????????????????????
	return 1;
}
I want to make it so that the actual rotation doesnt SetPlayerPos unless you are in the "DM rotation",
and another question is how I set the players position on first login? Doesnt need to save or anything just so that when you first login you spawn inside an interior, and when you are ready to join the DM you /start or whatever.

I'm thinking that that would look something like this:
Код:
public OnPlayerConnect(playerid)
{
     gDMRotation[playerid] = 0;
	return 1;

// And then add in like a command to enter rotation?

public OnPlayerCommandText(playerid, cmdtext[])
{
	new idx;
	new cmd[256];

	cmd = strtok(cmdtext, idx);

	if(strcmp(cmd, "/Start", true) == 0) {
     gDMRotation[playerid] = 1;
    	return 1;
	}

	return 0;


I've been doing extremely basic stuff on and off for a year or two but I still cant seem to figure this out.
This might be alot of work just to help some guy on the internet out, so if needed I can pay a dollar or two.

Thanks alot in beforehand!


Re: Random zones - PrO.GameR - 01.10.2015

use 3D arrays for positions,
Zonespawns[10][10][3] for example ( that means 10 DM areas, 10 different spawns each, and XYZ for each spawn), then when you wanna change the zone, do a random(sizeof(Zonespawns)) and load your spawns from the one it randomed.
PS: I'm not sure how to give value to 3D arrays, but you can simply do it all under Ongamodmodeinit and do Zonespawns[0][][]={ {X,Y,Z}, } etc, at least if no one answers how would you do that


as for your second question, you can simply spawn people using SetSpawnInfo and SpawnPlayer to force the player to spawn in the interior as soon as they logged on, and you can simply spawn them on your next map rotation that you do, just like you suggested yourself, nothing complex

although as a suggestion let people join on the current map too if they want, 10 min is too much to wait, or make rotations be 4-5 mins


Re: Random zones - Counterafk - 01.10.2015

I lowered it down so there are only 2 zones for the simplicity of it, ill add in more later when(if) I get it to work.
Код:
new gZoneSpawns[2][10][3] =
{
	{"1244.6598,-2007.9690,59.8583"}, // #1
	{"1263.8115,-2008.7446,59.3110"}, // #2
	{"1274.2030,-2017.0784,59.0140"}, // #3
	{"1275.0482,-2029.7145,59.0075"}, // #4
	{"1267.9203,-2039.6437,59.1826"}, // #5
	{"1257.5148,-2045.0038,59.4839"}, // #6
	{"1248.4553,-2045.1805,59.7547"}, // #7
	{"1241.6305,-2040.7483,60.0307"}, // #8
	{"1237.1600,-2037.8246,60.4849"}, // #9
	{"1231.9650,-2033.4900,62.9660"} // #10

	{"-2634.5728,1352.5977,7.1206"}, // #1
	{"-2628.7397,1356.4369,7.0964"}, // #2
	{"-2626.7644,1364.8420,7.0882"}, // #3
	{"-2635.1113,1367.3550,7.1229"}, // #4
	{"-2638.3760,1359.6676,7.1364"}, // #5
	{"-2633.6199,1351.5447,7.1167"}, // #6
	{"-2624.4773,1349.3302,7.1448"}, // #7
	{"-2616.0916,1347.4570,7.1953"}, // #8
	{"-2613.6470,1355.6351,7.1460"}, // #9
	{"-2605.9299,1360.8137,7.0848"} // #10

};
^ Is pretty much all I got I right now. How does the script know which of the 3d arrays above have to do with each area? Does it do it automaticly or? And thats just a small question I dont know how to continue after that
And where(how) do I create the dm mode? a #define? I dont even know what Im talking about right now.


Re: Random zones - xVIP3Rx - 02.10.2015

Quote:
Originally Posted by Counterafk
Посмотреть сообщение
^ Is pretty much all I got I right now. How does the script know which of the 3d arrays above have to do with each area? Does it do it automaticly or? And thats just a small question I dont know how to continue after that
And where(how) do I create the dm mode? a #define? I dont even know what Im talking about right now.
I didn't understand that bit, but the script does nothing from itself, you've got to tell it which does what and when, try this.

pawn Код:
new order;
new bool:gDMRotation[MAX_PLAYERS];

new gZoneSpawns[][] =
{
//First spawn
    { 1244.6598, -2007.9690, 59.8583 }, // #0
    { 1263.8115, -2008.7446, 59.3110 }, // #1
    { 1274.2030, -2017.0784, 59.0140 }, // #2
    { 1275.0482, -2029.7145, 59.0075 }, // #3
    { 1267.9203, -2039.6437, 59.1826 }, // #4
    { 1257.5148, -2045.0038, 59.4839 }, // #5
    { 1248.4553, -2045.1805, 59.7547 }, // #6
    { 1241.6305, -2040.7483, 60.0307 }, // #7
    { 1237.1600, -2037.8246, 60.4849 }, // #8
    { 1231.9650, -2033.4900, 62.9660 }, // #9
//Second
    {-2634.5728, 1352.5977, 7.1206 }, // #10
    {-2628.7397, 1356.4369, 7.0964 }, // #11
    {-2626.7644, 1364.8420, 7.0882 }, // #12
    {-2635.1113, 1367.3550, 7.1229 }, // #13
    {-2638.3760, 1359.6676, 7.1364 }, // #14
    {-2633.6199, 1351.5447, 7.1167 }, // #15
    {-2624.4773, 1349.3302, 7.1448 }, // #16
    {-2616.0916, 1347.4570, 7.1953 }, // #17
    {-2613.6470, 1355.6351, 7.1460 }, // #18
    {-2605.9299, 1360.8137, 7.0848 }  // #19
};

public OnGameModeInit()
{
    order = 1;
    gRandomZoneTimer = SetTimer("ChangeRandomZone", 60000, true);//a minute timer
    return 1;
}

forward ChangeRandomZone();
public ChangeRandomZone()
{
//Sizeof returns the size of the array plus one for the EOS, so if we say we have 10 spawn each, we'll devide it by 10 (since it start counting from 0, if we have 20 spawn the actual sizeof array will be 20);

    //if(++order > (sizeof(gZoneSpawns)) / 10) order = 1; //if you want to switch between thim in order use this
    order = random(sizeof(gZoneSpawns) / 10);//If you want the order be random, use this, note that it might spawn you at the same DM, cause it's random
    //order will be 0 or 1, since we only got 20 spawn.
    return 1;
}

public OnPlayerConnect(playerid)
{
    gDMRotation[playerid] = false;//Use bool instead of an integer
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    new idx;
    new cmd[256];

    cmd = strtok(cmdtext, idx);

    if(strcmp(cmd, "/Start", true) == 0)
    {
        gDMRotation[playerid] = true;
        return 1;
    }

    return 0;
}

public OnPlayerSpawn(playerid)
{
    if( gDMRotation[playerid] ) //if he enabled it
    {
        JoinRandomRotation(playerid);
    }
    else // if there are other deathmatch modes, put a case for them, if not, just spawn him where you want to.
    {
        //SetPlayerPos(playerid, x, y, z);
    }
    return 1;
}

JoinRandomDeathmatch(playerid)
{
    new rnd = random(10+1); //A random spawn, you can make them spawn in order if you want.
    SetPlayerPos(playerid, gZoneSpawn[order * rnd][0], gZoneSpawn[order * rnd][1], gZoneSpawn[order * rnd][2]);
    //SetPlayerInterior(playerid, interiorid); If it's a diffrent interior, switch his interior.
    return 1;
}
If you had any problems please message me on the website or skype and I'll be glad to help.