need help with this -
xir - 04.04.2011
Hello. I need some help with this.
Starting a base works fine, but when typing /base, it will set the spawn 2-4 times, really fast.
Can anyone take a look at see what's wrong?
http://pastebin.com/iN0cU5sv
Re: need help with this -
Sascha - 04.04.2011
try the loop like this:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new rand = random(sizeof(RandomSpawn));
SetPlayerInterior(i, 15);
SetPlayerPos(i, RandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2]);
SetPlayerFacingAngle(i, RandomSpawn[rand][3]);
// SetSpawnInfo(i, T_ATT, 1, RandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2],RandomSpawn[rand][3], 24, 500, 26, 500, 34, 500);
// SetSpawnInfo(i, T_DEF, 260, RandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2],RandomSpawn[rand][3], 24, 500, 26, 500, 34, 500);
GivePlayerWeapon(i, 24, 500);
GivePlayerWeapon(i, 31, 500);
GivePlayerWeapon(i, 34, 500);
TogglePlayerControllable(i, 0);
}
}
if you search for "IsPlayerConnected" it will only work for connected players and won't do it for all IDs..
additionally you used "playerid" at "SetPlayerPos"... this will set the pos for the player that uses the command only, whenever the loop comes to this point... so if there are 4 players it will do it 4 times...
if you use "i" instead it will use it for the ID who's turn it is in the loop
Re: need help with this -
xir - 04.04.2011
Works, Sascha. Thank you.
I need some more help, could you help me
implent this into my base cmd
pawn Код:
stock GetLowestCountTeam()
{
new c0, c1;
for (new i = 0; i < MAX_PLAYERS; i ++)
{
if (Team[i] == Tean) { c0 += 1; }
else if (Team[i] == Tean) { c1 += 1; }
}
if (c0 < c1) return Team;
else if (c0 > c1) return Team1;
}
cuz i am not suer if I did it right, I need when someone types /base they get teleported to the team which has the lowest players.
Thank you once again.
Re: need help with this -
Sascha - 04.04.2011
is the "Team" connected to a array variable? like the "RandomSpawn" thing?
edit: if yes:
pawn Код:
COMMAND:base(playerid, params[])
{
if(BaseOn == 0) return SendClientMessage(playerid, Red, "There is no base in progress, or the base has already started");
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new rand = random(sizeof(RandomSpawn));
new TP = GetLowestCountTeam();
SetPlayerInterior(i, 15);
SetPlayerPos(i, TP[rand][0], TP[rand][1],TP[rand][2]);
SetPlayerFacingAngle(i, TP[rand][3]);
// SetSpawnInfo(i, T_ATT, 1, TP[rand][0], TP[rand][1],TP[rand][2],TP[rand][3], 24, 500, 26, 500, 34, 500);
// SetSpawnInfo(i, T_DEF, 260, TP[rand][0], TP[rand][1],TP[rand][2],TP[rand][3], 24, 500, 26, 500, 34, 500);
GivePlayerWeapon(i, 24, 500);
GivePlayerWeapon(i, 31, 500);
GivePlayerWeapon(i, 34, 500);
TogglePlayerControllable(i, 0);
}
}
return 1;
}
stock GetLowestCountTeam()
{
new c0, c1;
for (new i = 0; i < MAX_PLAYERS; i ++)
{
if (Team[i] == Tean) { c0 += 1; }
else if (Team[i] == Tean) { c1 += 1; }
}
if (c0 < c1) return Team;
else if (c0 > c1) return Team1;
}
Re: need help with this -
xir - 04.04.2011
I got this
pawn Код:
#define T_ATT 1
#define T_DEF 2
Re: need help with this -
Sascha - 04.04.2011
I mean..
Like "RandomSpawn"... do you have saved the spawn position in such a variable?
if no, then I'd need them to put them into the code...
Re: need help with this -
xir - 04.04.2011
ooh, i get you now, no I dont got such thing
Re: need help with this -
Sascha - 04.04.2011
hm I just noticed a mistake in my code..
try something like this and just paste in the coordinates of the spawns
pawn Код:
COMMAND:base(playerid, params[])
{
if(BaseOn == 0) return SendClientMessage(playerid, Red, "There is no base in progress, or the base has already started");
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new rand = random(sizeof(RandomSpawn));
new TP = GetLowestCountTeam();
if(TP == Team) //if you don't have this variable (The stock is confusing me a bit) use "T_ATT" instead of "Team"
{
SetPlayerInterior(i, 15);
SetPlayerPos(i, X, Y, Z); //coords of the first team
SetPlayerFacingAngle(i, AZ);
GivePlayerWeapon(i, 24, 500);
GivePlayerWeapon(i, 31, 500);
GivePlayerWeapon(i, 34, 500);
TogglePlayerControllable(i, 0);
}
else if(TP == Team1) //same for above but "T_DEF"
{
SetPlayerInterior(i, 15);
SetPlayerPos(i, X, Y, Z); //coords of the 2. team
SetPlayerFacingAngle(i, AZ);
GivePlayerWeapon(i, 24, 500);
GivePlayerWeapon(i, 31, 500);
GivePlayerWeapon(i, 34, 500);
TogglePlayerControllable(i, 0);
}
}
return 1;
}
stock GetLowestCountTeam()
{
new c0, c1;
for (new i = 0; i < MAX_PLAYERS; i ++)
{
if (Team[i] == Tean) { c0 += 1; }
else if (Team[i] == Tean) { c1 += 1; }
}
if (c0 < c1) return Team;
else if (c0 > c1) return Team1;
}
Re: need help with this -
xir - 04.04.2011
Okay, but could you make the T_ATT, T_DEF in this code because I dont want to ruin it by just doing 1 mistake
This one
pawn Код:
stock GetLowestCountTeam()
{
new c0, c1;
for (new i = 0; i < MAX_PLAYERS; i ++)
{
if (Team[i] == Team0) { c0 += 1; }
else if (Team[i] == Team1) { c1 += 1; }
}
if (c0 < c1) return Team0;
else if (c0 > c1) return Team1;
return 1;
And I won't be using Randomspawns anymore? Should I delete?
Re: need help with this -
Sascha - 04.04.2011
pawn Код:
COMMAND:base(playerid, params[])
{
if(BaseOn == 0) return SendClientMessage(playerid, Red, "There is no base in progress, or the base has already started");
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new rand = random(sizeof(RandomSpawn));
new TP = GetLowestCountTeam();
if(TP == T_ATT)
{
SetPlayerInterior(i, 15);
SetPlayerPos(i, X, Y, Z); //coords of the first team
SetPlayerFacingAngle(i, AZ);
GivePlayerWeapon(i, 24, 500);
GivePlayerWeapon(i, 31, 500);
GivePlayerWeapon(i, 34, 500);
TogglePlayerControllable(i, 0);
}
else if(TP == T_DEF)
{
SetPlayerInterior(i, 15);
SetPlayerPos(i, X, Y, Z); //coords of the 2. team
SetPlayerFacingAngle(i, AZ);
GivePlayerWeapon(i, 24, 500);
GivePlayerWeapon(i, 31, 500);
GivePlayerWeapon(i, 34, 500);
TogglePlayerControllable(i, 0);
}
}
return 1;
}
stock GetLowestCountTeam()
{
new c0, c1;
for (new i = 0; i < MAX_PLAYERS; i ++)
{
if (Team[i] == Tean) { c0 += 1; }
else if (Team[i] == Tean) { c1 += 1; }
}
if (c0 < c1) return T_ATT;
else if (c0 > c1) return T_DEF;
}
depends.. if you use them on another place, too then you shouldn't.. however if you don't use them at all you can remove them