SA-MP Forums Archive
When spawn, teleport on random place. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: When spawn, teleport on random place. (/showthread.php?tid=126084)



When spawn, teleport on random place. - MummyKillerSLO - 07.02.2010

Hi all!

How can I make that when the player is spawned, he is teleported on '/lsair' or '/sfair' place? I know how to do this with coordinates, but it is any other way? Please help.


Re: When spawn, teleport on random place. - Miguel - 07.02.2010

Make an array and get a random row from it:
pawn Код:
new Float:rPos[][3] =
{
  {1255.4554, 4556.1147, 4545.1154}, // pos 1
  {4587.4455, 4789.8977, 1214.6544}, // pos 2
  {1.021, 45.0114, 6444.0000} // pos 3
};
pawn Код:
public OnPlayerSpawn(playerid)
{
  new rand = random(sizeof(rPos))
  SetPlayerPos(playerid, rPos[rand][0], rPos[rand][1], rPos[rand][2]);
  return 1;
}



Re: When spawn, teleport on random place. - mansonh - 07.02.2010

Thats a nice one if you have specific areas
There is however another way which is completely random, using the samp-gta map system zreset SetPlayerPosFindZ.

pawn Код:
public OnPlayerSpawn(playerid)
{
  new Float:randx = float(random(4000)-2000);
  new Float:randy = float(random(4000)-2000);
  SetPlayerPosFindZ(playerid, randx, randy, 0.0);
  return 1;
}



Re: When spawn, teleport on random place. - HydraX - 07.02.2010

Quote:
Originally Posted by mansonh
Thats a nice one if you have specific areas
There is however another way which is completely random, using the samp-gta map system zreset SetPlayerPosFindZ.

pawn Код:
public OnPlayerSpawn(playerid)
{
  new Float:randx = float(random(4000)-2000);
  new Float:randy = float(random(4000)-2000);
  SetPlayerPosFindZ(playerid, randx, randy, 0.0);
  return 1;
}
This is more for pros or experts

the one Miguel posted seems more n00b-freindly.


Re: When spawn, teleport on random place. - Onyx09 - 07.02.2010

Quote:
Originally Posted by HydraX
Quote:
Originally Posted by mansonh
Thats a nice one if you have specific areas
There is however another way which is completely random, using the samp-gta map system zreset SetPlayerPosFindZ.

pawn Код:
public OnPlayerSpawn(playerid)
{
  new Float:randx = float(random(4000)-2000);
  new Float:randy = float(random(4000)-2000);
  SetPlayerPosFindZ(playerid, randx, randy, 0.0);
  return 1;
}
This is more for pros or experts

the one Miguel posted seems more n00b-freindly.
i use this and its a pretty good way :P


Re: When spawn, teleport on random place. - mansonh - 07.02.2010

Quote:
Originally Posted by HydraX
Quote:
Originally Posted by mansonh
Thats a nice one if you have specific areas
There is however another way which is completely random, using the samp-gta map system zreset SetPlayerPosFindZ.

pawn Код:
public OnPlayerSpawn(playerid)
{
  new Float:randx = float(random(4000)-2000);
  new Float:randy = float(random(4000)-2000);
  SetPlayerPosFindZ(playerid, randx, randy, 0.0);
  return 1;
}
This is more for pros or experts
I'll take that as a compliment.

But it is still easy to use for new scripters, they don't need to know exactly how it works.

Quote:
Originally Posted by Reality King
i use this and its a pretty good way :P



Re: When spawn, teleport on random place. - [Bm]rap45 - 07.02.2010

Well i learned this from LVDM script

This goes on top of the script, below the #include <a_samp>

If you want to add more positions, just change "new Float:gRandomPlayerSpawns[17][3] = {" the [17] to the number of positions you want, and just add the position with a " }, " and the last one should only be a " } " at the end.

Код:
//new's 
new iSpawnSet[MAX_PLAYERS];
// forwards
forward SetPlayerRandomSpawn(playerid);
//
new Float:gRandomPlayerSpawns[17][3] = {
{1958.3783,1343.1572,15.3746},
{2199.6531,1393.3678,10.8203},
{2483.5977,1222.0825,10.8203},
{2637.2712,1129.2743,11.1797},
{2000.0106,1521.1111,17.0625},
{2024.8190,1917.9425,12.3386},
{2261.9048,2035.9547,10.8203},
{2262.0986,2398.6572,10.8203},
{1598.8419,2221.5676,11.0625},
{1318.7759,1251.3580,10.8203},
{1558.0731,1007.8292,10.8125},
{1705.2347,1025.6808,10.8203},
{1380.7273,-1740.7815,13.5469},
{2280.4670,-1724.4014,13.5469},
{2073.4302,-1762.4957,13.5594},
{1827.6128,-1857.6096,13.5781},
{1210.4469,-2037.1666,69.0078}
};

new Float:gCopPlayerSpawns[2][3] = {
{2297.1064,2452.0115,10.8203},
{2297.0452,2468.6743,10.8203}
};
This would be a new "public" thingy so you don't put it in "Public OnPlayerRequestClass" or other public one.
Код:
//-------------------------------------------------------------------------------------------------
public OnPlayerSpawn(playerid)
{
  	SetPlayerRandomSpawn(playerid);
  return 1;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
public SetPlayerRandomSpawn(playerid)
{
	if (iSpawnSet[playerid] == 1)
	{
		new rand = random(sizeof(gCopPlayerSpawns));
		SetPlayerPos(playerid, gCopPlayerSpawns[rand][0], gCopPlayerSpawns[rand][1], gCopPlayerSpawns[rand][2]);
		SetPlayerFacingAngle(playerid, 270.0);
  }
  else if (iSpawnSet[playerid] == 0)
  {
		new rand = random(sizeof(gRandomPlayerSpawns));
		SetPlayerPos(playerid, gRandomPlayerSpawns[rand][0], gRandomPlayerSpawns[rand][1], gRandomPlayerSpawns[rand][2]); 
	}
	return 1;
}



Re: When spawn, teleport on random place. - mansonh - 07.02.2010

Quote:
Originally Posted by [Bm
rap45 ]

If you want to add more positions, just change "new Float:gRandomPlayerSpawns[17][3] = {" the [17] to the number of positions you want, and just add the position with a " }, " and the last one should only be a " } " at the end.
Actually you can just leave the 17 out, and it will auto determine how many it needs.

As you can see in Miguel™ version.


Re: When spawn, teleport on random place. - [Bm]rap45 - 07.02.2010

Quote:
Originally Posted by mansonh
Actually you can just leave the 17 out, and it will auto determine how many it needs.

As you can see in Miguel™ version.
Or like he said ^