Function doesn't work -
Tomer!.$ - 17.04.2012
Well I made two global variables gSWAT and gCriminals and did when someone spawns if he's in the swat team it adds one to gSWAT and if he's in the criminals team it adds one to gCriminals.
So I did when a player dies it reduces the variable one less and then I did if any of the variables equals to 0 it'll exit the gamemode.
But it basically doesn't, when a player dies even if he's the last one in his team it's just spawning him again, like the function I made doesn't work.
PHP код:
new gSWAT = 0;
new gCriminals = 0;
public OnPlayerSpawn(playerid)
{
SetPlayerInterior(playerid, 15);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 24, 99999);
SetPlayerArmour(playerid, 100.0);
if(gTeam[playerid] == TEAM_CRIMINALS)
{
SetPlayerColor(playerid, 0xAFAFAF00);
SendClientMessage(playerid, COLOR_WHITE, "[Info:] Protect this building from any SWAT member!");
GivePlayerWeapon(playerid, 30, 99999);
SetPlayerPos(playerid, 2198.3105,-1139.0374,1029.7969);
SetPlayerFacingAngle(playerid, 172.9276);
gCriminals += 1;
}
else if(gTeam[playerid] == TEAM_SWAT)
{
SetPlayerColor(playerid, 0x0000BB00);
SendClientMessage(playerid, COLOR_WHITE, "[Info:] You need to hunt down every criminal in the building!");
GivePlayerWeapon(playerid, 31, 99999);
SetPlayerPos(playerid, 2227.8904,-1150.5730,1025.7969);
SetPlayerFacingAngle(playerid, 80.7447);
gSWAT += 1;
}
TogglePlayerControllable(playerid, false);
SetTimer("StartRound", 5000, false);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
SendDeathMessage(killerid, playerid, reason);
if(gTeam[playerid] == TEAM_SWAT) { gSWAT -= 1; }
if(gTeam[playerid] == TEAM_CRIMINALS) { gCriminals -= 1; }
if(gSWAT <= 0 || gCriminals <= 0)
{
new string[128];
format(string, sizeof(string), "%s has won this round! \n New round is starting up within the few next seconds!", gTeam[playerid]);
GameModeExit();
}
return 1;
}
Re: Function doesn't work -
[MG]Dimi - 17.04.2012
Well I kinda don't know could this cause it but when you wanna add/reduce one put ++;/--; , not += 1;/-=1;
Ex.
pawn Код:
if(gTeam[playerid] == TEAM_SWAT) gSWAT--;
if(gTeam[playerid] == TEAM_CRIMINALS) gCriminals--;
Re: Function doesn't work -
Tomer!.$ - 17.04.2012
Still not working.
Re: Function doesn't work -
Ubuntu - 17.04.2012
Try this:
Replace the current gTeam[MAX_PLAYERS]; by static gTeam[MAX_PLAYERS];
Код:
static gSWAT = 0;
static gCriminals = 0;
static gTeam[MAX_PLAYERS];
public OnPlayerSpawn(playerid)
{
SetPlayerInterior(playerid, 15);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 24, 99999);
SetPlayerArmour(playerid, 100.0);
if(gTeam[playerid] == TEAM_CRIMINALS)
{
SetPlayerColor(playerid, 0xAFAFAF00);
SendClientMessage(playerid, COLOR_WHITE, "[Info:] Protect this building from any SWAT member!");
GivePlayerWeapon(playerid, 30, 99999);
SetPlayerPos(playerid, 2198.3105,-1139.0374,1029.7969);
SetPlayerFacingAngle(playerid, 172.9276);
gCriminals++;
}
else if(gTeam[playerid] == TEAM_SWAT)
{
SetPlayerColor(playerid, 0x0000BB00);
SendClientMessage(playerid, COLOR_WHITE, "[Info:] You need to hunt down every criminal in the building!");
GivePlayerWeapon(playerid, 31, 99999);
SetPlayerPos(playerid, 2227.8904,-1150.5730,1025.7969);
SetPlayerFacingAngle(playerid, 80.7447);
gSWAT++;
}
TogglePlayerControllable(playerid, false);
SetTimer("StartRound", 5000, false);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
SendDeathMessage(killerid, playerid, reason);
if(gTeam[playerid] == TEAM_SWAT) { gSWAT--; }
if(gTeam[playerid] == TEAM_CRIMINALS) { gCriminals--; }
if(gSWAT <= 0 || gCriminals <= 0)
{
new string[128];
format(string, sizeof(string), "%s has won this round! \n New round is starting up within the few next seconds!", gTeam[playerid]);
GameModeExit();
}
return 1;
}
Re: Function doesn't work -
Tomer!.$ - 17.04.2012
Still not working
Re: Function doesn't work -
Ubuntu - 17.04.2012
Show me the full code over PM, I will give you an answer.
Re: Function doesn't work -
Tomer!.$ - 17.04.2012
I really don't see the need for me to send you the whole code.
And I also don't think it's something related to static and such..
Re: Function doesn't work -
Ubuntu - 17.04.2012
You said it spawns him again, why don't you prevent the spawn and make him Spectate other players like Counter-Strike: Source?
Re: Function doesn't work -
iggy1 - 17.04.2012
Put them in spectate when they die? Ubuntu said b4 me. ^^
Re: Function doesn't work -
Tomer!.$ - 17.04.2012
I actually found the problem right now but dunno how to solve it.
When I did:
PHP код:
if(gTeam[playerid] == TEAM_SWAT) SWAT--;
if(gTeam[playerid] == TEAM_CRIMINALS) Criminals--;
It'll stop the function, how can I do it without creating brackets for each and making the function be way more longer?