[Solved]Random spawn points
#1

Hey.
At the moment I got my own local server running, trying to get a few teleports.Recently I edited a map with MTA, adding objects, their position etc to create a sniper DM area.I got the cordinates for 2 or 3 teleport-arrival points, but I can't make the player teleport to them randomly.E.g: Whenever you type /sniperDM, it teleports you to different places in the same area.
I don't know if that's possible though as I just started scripting 3 days ago.
I'd appreciate some help
Reply
#2

pawn Код:
new RandomSpawn = random(3); //3 Random spawns
pawn Код:
if (RandomSpawn == 0)
{
  SetPlayerPos(playerid, ....); //1st Spawn
}
if (RandomSpawn == 1)
{
  SetPlayerPos(playerid, ....); //2nd Spawn
}
if (RandomSpawn == 2)
{
  SetPlayerPos(playerid, ....); // 3rd Spawn
}
Reply
#3

Thanks a lot, I'll try them all later, I'm not home atm.
Reply
#4

Quote:
Originally Posted by [SE
FeaR ]
pawn Код:
new RandomSpawn = random(3); //3 Random spawns
pawn Код:
if (RandomSpawn == 0)
{
  SetPlayerPos(playerid, ....); //1st Spawn
}
if (RandomSpawn == 1)
{
  SetPlayerPos(playerid, ....); //2nd Spawn
}
if (RandomSpawn == 2)
{
  SetPlayerPos(playerid, ....); // 3rd Spawn
}
A switch case is better,
pawn Код:
switch(RandomSpawn)
{
    case 0:
    {
        SetPlayerPos( ... );
    }
    case 1:
    {
        SetPlayerPos( ... );
    }
    case 2:
    {
        SetPlayerPos( ... );
    }
}
Reply
#5

Okay for now I got 7 teleports, and I know I'm not such a great scripter, I just can't find the right place to place the teleport command and such.Could I get some help writing the whole code?
I got this atm:
pawn Код:
new RandomSpawn = random(7);
   
  if (RandomSpawn == 0)
{
  SetPlayerPos(playerid,1314.9265,1274.5889,10.8203);
}
  if (RandomSpawn == 1)
{
  SetPlayerPos(playerid,2593.3086,2825.2039,27.8203);
}
  if (RandomSpawn == 2)
{
  SetPlayerPos(playerid,2689.9150,2790.7878,59.0212);
}

  if (RandomSpawn == 3)
{
  SetPlayerPos(playerid,2725.5459,2682.5300,59.0234);
}

  if (RandomSpawn == 4)
{
  SetPlayerPos(playerid,2605.4829,2714.0332,25.8222);
}

  if (RandomSpawn == 5)
{
  SetPlayerPos(playerid,2693.7769,2696.0540,22.9472);
}

  if (RandomSpawn == 6)
{
  SetPlayerPos(playerid,2505.3228,2687.8430,74.8281);
}

  if (RandomSpawn == 7)
{
  SetPlayerPos(playerid,2631.9949,2835.0886,94.0156);
}
Plus I want the GivePlayerWeapon command on the teleport command, dunno where to place that neither.
Reply
#6

EDIT: double-posted by mistake.
Reply
#7

or:

Код:
new Float:gRandomSpawns[][4] = {
{x,y,z,a},
{x,y,z,a},
{x,y,z,a}
};
and in command/spawn..:

Код:
new r=random(sizeof(gRandomSpawns));
SetPlayerPos(playerid,gRandomSpawns[0],gRandomSpawns[1],gRandomSpawns[2]);
SetPlayerFacingAngle(playerid,gRandomSpawns[3]);
Reply
#8

Quote:
Originally Posted by NaS
or:

Код:
new Float:gRandomSpawns[][4] = {
{x,y,z,a},
{x,y,z,a},
{x,y,z,a},
{x,y,z,a}
};
and in command/spawn..:

Код:
new r=random(sizeof(gRandomSpawns));
SetPlayerPos(playerid,gRandomSpawns[0],gRandomSpawns[1],gRandomSpawns[2]);
SetPlayerFacingAngle(playerid,gRandomSpawns[3]);
That didn't help me, really :P
Reply
#9

Here's an example:
pawn Код:
if(strcmp(cmdtext, "/sniperdm", true) == 0)
{
new RandomSpawn = random(7);
   
  if (RandomSpawn == 0)
{
  SetPlayerPos(playerid,1314.9265,1274.5889,10.8203);
}
  if (RandomSpawn == 1)
{
  SetPlayerPos(playerid,2593.3086,2825.2039,27.8203);
}
  if (RandomSpawn == 2)
{
  SetPlayerPos(playerid,2689.9150,2790.7878,59.0212);
}

  if (RandomSpawn == 3)
{
  SetPlayerPos(playerid,2725.5459,2682.5300,59.0234);
}

  if (RandomSpawn == 4)
{
  SetPlayerPos(playerid,2605.4829,2714.0332,25.8222);
}

  if (RandomSpawn == 5)
{
  SetPlayerPos(playerid,2693.7769,2696.0540,22.9472);
}

  if (RandomSpawn == 6)
{
  SetPlayerPos(playerid,2505.3228,2687.8430,74.8281);
}

  if (RandomSpawn == 7)
{
  SetPlayerPos(playerid,2631.9949,2835.0886,94.0156);
}
GivePlayerWeapon(playerid, 38, 99999999); //
GivePlayerWeapon(playerid, 38, 99999999); ///// Place Weapons here<<
GivePlayerWeapon(playerid, 38, 99999999);//
SendClientMessage(playerid,0x00AFFFAA, "Welcome to the Sniper Deathmatch!");
return 1;
}

Reply
#10

Quote:
Originally Posted by [SE
FeaR ]
Here's an example:
pawn Код:
if(strcmp(cmdtext, "/sniperdm", true) == 0)
{
new RandomSpawn = random(7);
   
  if (RandomSpawn == 0)
{
  SetPlayerPos(playerid,1314.9265,1274.5889,10.8203);
}
  if (RandomSpawn == 1)
{
  SetPlayerPos(playerid,2593.3086,2825.2039,27.8203);
}
  if (RandomSpawn == 2)
{
  SetPlayerPos(playerid,2689.9150,2790.7878,59.0212);
}

  if (RandomSpawn == 3)
{
  SetPlayerPos(playerid,2725.5459,2682.5300,59.0234);
}

  if (RandomSpawn == 4)
{
  SetPlayerPos(playerid,2605.4829,2714.0332,25.8222);
}

  if (RandomSpawn == 5)
{
  SetPlayerPos(playerid,2693.7769,2696.0540,22.9472);
}

  if (RandomSpawn == 6)
{
  SetPlayerPos(playerid,2505.3228,2687.8430,74.8281);
}

  if (RandomSpawn == 7)
{
  SetPlayerPos(playerid,2631.9949,2835.0886,94.0156);
}
GivePlayerWeapon(playerid, 38, 99999999); //
GivePlayerWeapon(playerid, 38, 99999999); ///// Place Weapons here<<
GivePlayerWeapon(playerid, 38, 99999999);//
SendClientMessage(playerid,0x00AFFFAA, "Welcome to the Sniper Deathmatch!");
return 1;
}

Thanks again, the only problem comes up when I try to compile it.

Код:
C:\Documents and Settings\Dezi\Desktop\Mil Freeroam\gamemodes\MilFreeroam.pwn(2856) : warning 219: local variable "RandomSpawn" shadows a variable at a preceding level
C:\Documents and Settings\Dezi\Desktop\Mil Freeroam\gamemodes\MilFreeroam.pwn(2852) : warning 204: symbol is assigned a value that is never used: "RandomSpawn"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Warnings.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)