A auto team picker. -
persious - 04.10.2011
Hello SA-MP forum! I actually started coding PAWN yesterday, and I have to say that's it's fun. I'm just stuck with a problem. On my gamemode, I simply need a auto team picker, like when the player join's, he automaticly joins the team with less player's. My team's are MILITARY and TERRORIST. I'd realy appreciate ANY help, thanks!
Re: A auto team picker. -
Backwardsman97 - 05.10.2011
Kinda difficult for someone to help without seeing the whole script and how you set it up.
Re: A auto team picker. -
hittt - 05.10.2011
SetPlayerSpawnInfo
Re: A auto team picker. -
persious - 05.10.2011
Yeah, but I'm new. Let me post my code here. (Yeah, sorry because I'm new. Don't know how good or poorly the code is.)
pawn Код:
#include <a_samp>
new MilitaryAirport, Area51, TerroristArea;
new gTeam[MAX_PLAYERS];
#define MILITARY 0
#define TERRORIST 1
#define COLOR_GREEN 0x00FF0BFF
#define COLOR_RED 0xFF0000FF
public OnGameModeInit()
{
SetGameModeText("PersiousWar");
//----------------------------------------------------------------------------------------------------//
// MILITARY AIRPORT //
AddPlayerClassEx(MILITARY,165,296.3174,2059.2976,17.6406,183.7194,31,1000,0,0,0,0); // Military Spawn 1
AddPlayerClassEx(MILITARY,166,298.5066,2059.1160,17.6406,184.2834,31,1000,0,0,0,0); // Military Spawn 2
AddPlayerClassEx(MILITARY,280,300.6361,2059.1563,17.6406,188.7955,31,1000,0,0,0,0); // Military Spawn 3
AddPlayerClassEx(MILITARY,281,302.5984,2059.8735,17.6406,181.4634,31,1000,0,0,0,0); // Military Spawn 4
AddPlayerClassEx(MILITARY,282,304.9218,2059.5300,17.6406,181.4634,31,1000,0,0,0,0); // Military Spawn 5
AddPlayerClassEx(MILITARY,283,306.9520,2059.7734,17.6406,182.2154,31,1000,0,0,0,0); // Military Spawn 6
// AREA 51 //
AddPlayerClassEx(MILITARY,284,413.6353,2536.8433,19.1484,177.9784,31,1000,0,0,0,0); // Military Spawn 7
AddPlayerClassEx(MILITARY,285,413.2689,2530.8328,19.1779,354.4888,31,1000,0,0,0,0); // Military Spawn 8
AddPlayerClassEx(MILITARY,286,394.0936,2544.4868,16.5434,98.8297,31,1000,0,0,0,0); // Military Spawn 9
AddPlayerClassEx(MILITARY,287,355.1437,2535.2834,16.7147,180.7985,31,1000,0,0,0,0); // Military Spawn 10
//----------------------------------------------------------------------------------------------------//
// TERRORIST BASE //
AddPlayerClassEx(TERRORIST,124,-1561.9209,-226.6674,14.1440,33.8733,30,1000,0,0,0,0);
AddPlayerClassEx(TERRORIST,125,-1566.6169,-231.2649,14.1440,47.7854,30,1000,0,0,0,0);
AddPlayerClassEx(TERRORIST,126,-1571.8624,-236.5135,14.1440,47.7854,30,1000,0,0,0,0);
AddPlayerClassEx(TERRORIST,127,-1574.7235,-239.0641,14.1440,47.7854,30,1000,0,0,0,0);
AddPlayerClassEx(TERRORIST,111,-1577.8744,-241.9350,14.1440,47.7854,30,1000,0,0,0,0);
AddPlayerClassEx(TERRORIST,112,-1581.9219,-245.7941,14.1440,47.7854,30,1000,0,0,0,0);
AddPlayerClassEx(TERRORIST,113,-1585.5641,-249.1764,14.1440,47.5974,30,1000,0,0,0,0);
//----------------------------------------------------------------------------------------------------//
AddStaticVehicleEx(520,291.5609,2538.2405,17.5372,180.5756,0,0,5); // Hydra 1 - Military Airport
AddStaticVehicleEx(520,326.6140,2538.5601,17.5274,179.3083,0,0,5); // Hydra 2 - Military Airport
AddStaticVehicleEx(425,365.7119,2539.2390,17.1910,356.5695,43,0,5); // Cobra 1 - Military Airport
AddStaticVehicleEx(470,324.4907,1981.5381,17.6336,85.1864,43,0,5); // Hummer 1 - Area 51
AddStaticVehicleEx(470,323.8524,1971.9628,17.6329,89.4741,43,0,5); // Hummer 2 - Area 51
AddStaticVehicleEx(470,324.0744,1958.9252,17.6347,85.3343,43,0,5); // Hummer 3 - Area 51
AddStaticVehicleEx(432,279.5623,2027.0767,17.6533,271.0956,43,0,5); // Tank 1 - Area 51
AddStaticVehicleEx(432,280.8330,2018.9037,17.6533,269.3884,43,0,5); // Tank 2 - Area 51
//----------------------------------------------------------------------------------------------------//
Area51 = GangZoneCreate(-315.3026, 1564.835, 572.2159, 2207.118);
MilitaryAirport = GangZoneCreate(-420.4035, 2265.508, 607.2495, 2755.979);
TerroristArea = GangZoneCreate(-1810.071, -829.1292, -910.8743, 513.8265);
//----------------------------------------------------------------------------------------------------//
return 1;
}
public OnPlayerSpawn(playerid)
{
GangZoneShowForPlayer(playerid, Area51, 0x00FF4096);
GangZoneShowForPlayer(playerid, MilitaryAirport, 0x00FF4096);
GangZoneShowForPlayer(playerid, TerroristArea, 0xFF000096);
return 1;
}
SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 0)
{
gTeam[playerid] = MILITARY;
}
else if(classid == 1)
{
gTeam[playerid] = TERRORIST;
}
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid,220.3261,1822.9734,7.5368);//The Place postion
SetPlayerCameraLookAt(playerid,220.3261,1822.9734,7.5368);//Camera Look at the player
SetPlayerCameraPos(playerid,226.7491,1823.0441,7.4141);//Camera Postiion
SetPlayerFacingAngle(playerid, 270 );//The Facing Angle
SetPlayerTeamFromClass(playerid, classid);//It set's the player to the choosing team
return 1;
}
Re: A auto team picker. -
persious - 05.10.2011
Anyone?
Re: A auto team picker. -
hittt - 05.10.2011
pawn Код:
#include <a_samp>
new MilitaryAirport, Area51, TerroristArea;
new gTeam[MAX_PLAYERS];
new cTeam[1];
new WasSpawned[MAX_PLAYERS];
#define MILITARY 0
#define TERRORIST 1
#define COLOR_GREEN 0x00FF0BFF
#define COLOR_RED 0xFF0000FF
forward SpawnAsTerrorist(playerid);
public SpawnAsTerrorist(playerid);
{
new random = random(7);
switch(random)
{
case 0: SetSpawnInfo(playerid,TERRORIST,124,-1561.9209,-226.6674,14.1440,33.8733,30,1000,0,0,0,0);
case 1: SetSpawnInfo(playerid,TERRORIST,125,-1566.6169,-231.2649,14.1440,47.7854,30,1000,0,0,0,0);
case 2: SetSpawnInfo(playerid,TERRORIST,126,-1571.8624,-236.5135,14.1440,47.7854,30,1000,0,0,0,0);
case 3: SetSpawnInfo(playerid,TERRORIST,127,-1574.7235,-239.0641,14.1440,47.7854,30,1000,0,0,0,0);
case 4: SetSpawnInfo(playerid,TERRORIST,111,-1577.8744,-241.9350,14.1440,47.7854,30,1000,0,0,0,0);
case 5: SetSpawnInfo(playerid,TERRORIST,112,-1581.9219,-245.7941,14.1440,47.7854,30,1000,0,0,0,0);
case 6: SetSpawnInfo(playerid,TERRORIST,113,-1585.5641,-249.1764,14.1440,47.5974,30,1000,0,0,0,0);
}
}
forward SpawnAsMilitary(playerid);
public SpawnAsMilitary(playerid);
{
new random = random(10);
switch(random)
{
case 0: SetSpawnInfo(playerid,MILITARY,165,296.3174,2059.2976,17.6406,183.7194,31,1000,0,0,0,0); // Military Spawn 1
case 1: SetSpawnInfo(playerid,MILITARY,166,298.5066,2059.1160,17.6406,184.2834,31,1000,0,0,0,0); // Military Spawn 2
case 2: SetSpawnInfo(playerid,MILITARY,280,300.6361,2059.1563,17.6406,188.7955,31,1000,0,0,0,0); // Military Spawn 3
case 3: SetSpawnInfo(playerid,MILITARY,281,302.5984,2059.8735,17.6406,181.4634,31,1000,0,0,0,0); // Military Spawn 4
case 4: SetSpawnInfo(playerid,MILITARY,282,304.9218,2059.5300,17.6406,181.4634,31,1000,0,0,0,0); // Military Spawn 5
case 5: SetSpawnInfo(playerid,MILITARY,283,306.9520,2059.7734,17.6406,182.2154,31,1000,0,0,0,0); // Military Spawn 6
// AREA 51
case 6: SetSpawnInfo(playerid,MILITARY,284,413.6353,2536.8433,19.1484,177.9784,31,1000,0,0,0,0); // Military Spawn 7
case 7: SetSpawnInfo(playerid,MILITARY,285,413.2689,2530.8328,19.1779,354.4888,31,1000,0,0,0,0); // Military Spawn 8
case 8: SetSpawnInfo(playerid,MILITARY,286,394.0936,2544.4868,16.5434,98.8297,31,1000,0,0,0,0); // Military Spawn 9
case 9: SetSpawnInfo(playerid,MILITARY,287,355.1437,2535.2834,16.7147,180.7985,31,1000,0,0,0,0); // Military Spawn 10
}
}
public OnGameModeInit()
{
SetGameModeText("PersiousWar");
AddStaticVehicleEx(520,291.5609,2538.2405,17.5372,180.5756,0,0,5); // Hydra 1 - Military Airport
AddStaticVehicleEx(520,326.6140,2538.5601,17.5274,179.3083,0,0,5); // Hydra 2 - Military Airport
AddStaticVehicleEx(425,365.7119,2539.2390,17.1910,356.5695,43,0,5); // Cobra 1 - Military Airport
AddStaticVehicleEx(470,324.4907,1981.5381,17.6336,85.1864,43,0,5); // Hummer 1 - Area 51
AddStaticVehicleEx(470,323.8524,1971.9628,17.6329,89.4741,43,0,5); // Hummer 2 - Area 51
AddStaticVehicleEx(470,324.0744,1958.9252,17.6347,85.3343,43,0,5); // Hummer 3 - Area 51
AddStaticVehicleEx(432,279.5623,2027.0767,17.6533,271.0956,43,0,5); // Tank 1 - Area 51
AddStaticVehicleEx(432,280.8330,2018.9037,17.6533,269.3884,43,0,5); // Tank 2 - Area 51
//----------------------------------------------------------------------------------------------------//
Area51 = GangZoneCreate(-315.3026, 1564.835, 572.2159, 2207.118);
MilitaryAirport = GangZoneCreate(-420.4035, 2265.508, 607.2495, 2755.979);
TerroristArea = GangZoneCreate(-1810.071, -829.1292, -910.8743, 513.8265);
//----------------------------------------------------------------------------------------------------//
return 1;
}
public OnPlayerSpawn(playerid)
{
GangZoneShowForPlayer(playerid, Area51, 0x00FF4096);
GangZoneShowForPlayer(playerid, MilitaryAirport, 0x00FF4096);
GangZoneShowForPlayer(playerid, TerroristArea, 0xFF000096);
return 1;
}
SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 0)
{
gTeam[playerid] = MILITARY;
}
else if(classid == 1)
{
gTeam[playerid] = TERRORIST;
}
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
if (WasSpawned[playerid]) cTeam[gTeam[playerid]]--;
if (cTeam[MILITARY] > cTeam[TERRORIST])
{
SpawnAsTerrorist(playerid);
cTeam[TERRORIST]++;
SetPlayerTeamFromClass(playerid,TERRORIST);
}
else
{
SpawnAsMilitary(playerid);
cTeam[MILITARY]++;
SetPlayerTeamFromClass(playerid,MILITARY);
}
return 1;
}
And under OnPlayerDisconnect, add:
pawn Код:
if (WasSpawned[playerid]) cTeam[gTeam[playerid]]--;
P.S.: Stop bumping.
Re: A auto team picker. -
persious - 05.10.2011
Thanks and sorry.
EDIT:
When I try compiling it, the compiler crashes.
Re: A auto team picker. -
Backwardsman97 - 05.10.2011
Try this out. This won't auto team pick, but it should prevent them from spawning on the team with less players.
http://pastebin.com/NxFLRZM2
Re: A auto team picker. -
persious - 05.10.2011
This time the compiler didn't crash, thanks.