Function doesn't work
#1

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(playerid15);
    
ResetPlayerWeapons(playerid);
    
GivePlayerWeapon(playerid2499999);
    
SetPlayerArmour(playerid100.0);
    if(
gTeam[playerid] == TEAM_CRIMINALS)
    {
        
SetPlayerColor(playerid0xAFAFAF00);
        
SendClientMessage(playeridCOLOR_WHITE"[Info:] Protect this building from any SWAT member!");
        
GivePlayerWeapon(playerid3099999);
        
SetPlayerPos(playerid2198.3105,-1139.0374,1029.7969);
        
SetPlayerFacingAngle(playerid172.9276);
        
gCriminals += 1;
    }
    else if(
gTeam[playerid] == TEAM_SWAT)
    {
        
SetPlayerColor(playerid0x0000BB00);
        
SendClientMessage(playeridCOLOR_WHITE"[Info:] You need to hunt down every criminal in the building!");
        
GivePlayerWeapon(playerid3199999);
        
SetPlayerPos(playerid2227.8904,-1150.5730,1025.7969);
        
SetPlayerFacingAngle(playerid80.7447);
        
gSWAT += 1;
    }
    
TogglePlayerControllable(playeridfalse);
    
SetTimer("StartRound"5000false);
    return 
1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    
SendDeathMessage(killeridplayeridreason);
    if(
gTeam[playerid] == TEAM_SWAT) { gSWAT -= 1; }
    if(
gTeam[playerid] == TEAM_CRIMINALS) { gCriminals -= 1; }
    if(
gSWAT <= || gCriminals <= 0)
    {
        new 
string[128];
        
format(stringsizeof(string), "%s has won this round! \n New round is starting up within the few next seconds!"gTeam[playerid]);
        
GameModeExit();
    }
    return 
1;

Reply
#2

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--;
Reply
#3

Still not working.
Reply
#4

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;
}
Reply
#5

Still not working
Reply
#6

Show me the full code over PM, I will give you an answer.
Reply
#7

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..
Reply
#8

You said it spawns him again, why don't you prevent the spawn and make him Spectate other players like Counter-Strike: Source?
Reply
#9

Put them in spectate when they die? Ubuntu said b4 me. ^^
Reply
#10

I actually found the problem right now but dunno how to solve it.
When I did:
PHP код:
    if(gTeam[playerid] == TEAM_SWATSWAT--;
    if(
gTeam[playerid] == TEAM_CRIMINALSCriminals--; 
It'll stop the function, how can I do it without creating brackets for each and making the function be way more longer?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)