Random team spawns not working
#1

https://pastebin.com/cBkAnXuQ

The team spawn thing is at the very bottom.

For some reason it only randomly spawns at this one:
Код:
new Float:IndiaSpawns[3][4] =
{ 
		{2841.2942,1285.7273,11.3906,88.5804},
		{2794.3298,1256.1736,11.0299,4.2696},
		{2837.1394,1337.4557,11.0877,82.9403}
};
and none of the other ones, no matter which team you select.

Included the entire thing in case it's something outside that.
Reply
#2

I think the problem is that you didn't use any brackets in the code and just wrote it all in one line. That's not how checks are done.
After an IF statement, the code will execute lines up to the first semicolon and that will be considered your block of code for the statement. You can avoid this by using commas or brackets, to indicate blocks of code to execute.

You currently have:

PHP код:
if(PlayerInfo[playerid][pTeam] == TEAM_USArnd random(sizeof(USASpawns)); SetPlayerPos(playerid,USASpawns[rnd][0],USASpawns[rnd][1],USASpawns[rnd][2]); SetPlayerFacingAngle(playeridUSASpawns[rnd][3]); 
Which is executed as:
PHP код:
if(PlayerInfo[playerid][pTeam] == TEAM_USA
{
    
rnd random(sizeof(USASpawns)); 
}
SetPlayerPos(playerid,USASpawns[rnd][0],USASpawns[rnd][1],USASpawns[rnd][2]); 
SetPlayerFacingAngle(playeridUSASpawns[rnd][3]); 
What happens is that your code checks the team, if the team is correct, generates the random number and then uses it for all the SetPlayerPos and FacingAngle lines. Eventually it reaches the last spawn point (India) and leaves the player there.


So two options:

Commas:

PHP код:
if(PlayerInfo[playerid][pTeam] == TEAM_USA
    
rnd random(sizeof(USASpawns)),
    
SetPlayerPos(playerid,USASpawns[rnd][0],USASpawns[rnd][1],USASpawns[rnd][2]),
    
SetPlayerFacingAngle(playeridUSASpawns[rnd][3]); 
or brackets (recommended for clarity's sake):

PHP код:
if(PlayerInfo[playerid][pTeam] == TEAM_USA
{    
    
rnd random(sizeof(USASpawns)); 
    
SetPlayerPos(playerid,USASpawns[rnd][0],USASpawns[rnd][1],USASpawns[rnd][2]); 
    
SetPlayerFacingAngle(playeridUSASpawns[rnd][3]);

Hope I didn't mess up and this helps
Reply
#3

Could I still keep it all on the same line with the commas? I'm hoping to save some space here.
Reply
#4

Yes, you can.
Although this would barely take up less (if any at all; visually it's less space but I have yet to think of a reason that would ask for this) space than spacing it out and you would sacrifice quite a bit of clarity. I wouldn't recommend it but you do you.


You can also add: return 1 to every if statement so that your code doesn't have to keep checking the other teams to find the correct one after already finding one. Alternatively, if you want to take up less visual space, you can use a combination of if and else if and then you don't have to return inside every statement.
You can also ditch the ifs and just use a switch statement for this part.
Reply
#5

Random isn't as random as you'd think it would be...
Reply
#6

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Random isn't as random as you'd think it would be...
What do you mean?

Unrelated, but does anyone know why this might cause a tag mismatch warning:
Код:
GATE_ADMIN_HOUSE1 = CreateAutomaticGate(980, 1491.3000000,-699.9000200,96.5000000, 0.0000000,0.0000000,180.0000000, 1480.8000488281,-699.9000200,96.5000000, 0.000000, 0.0000000, 180.000000, 1491.3000000,-699.9000200,96.5000000, 20.0, 0.003, 1);
GATE_ADMIN_HOUSE2 = CreateAutomaticGate(980, 1502.8000000,-699.9000200,96.5000000, 0.000000, 0.0000000, 0.0000000, 1514.3000488281,-699.9000200,96.5000000, 0.000000, 10.000000, 90.000000, 1502.8000000,-699.9000200,96.5000000, 20.0, 0.003, 1);
command is from the mGates include

also this:
Код:
if(Iter_Contains(mGates, gateid) == 0) return 0; // Doesn't exist
they all cause a tag mismatch
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)