SA-MP Forums Archive
What's wrong with my if statement? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What's wrong with my if statement? (/showthread.php?tid=463098)



What's wrong with my if statement? - knackworst - 10.09.2013

Hello, I got a little weird problem/bug

I'm making a minigame, and now I'm busy with the 'stock LeaveGame' function.

Here's the code:

pawn Код:
stock LeaveCaveGame(playerid)
{
    SInfo[CaveCount] --;
    PInfo[playerid][CaveGame] = 0;
   
    printf("%d leavecavegame called", SInfo[CaveCount]);
   
    if(SInfo[CaveCount] == 0)
    {
        new string [256], PlayerName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, PlayerName,sizeof PlayerName);
        format (string, sizeof string, "[CAVE]The Game has ended, %s stayed alive for %s, server record: lala, typer /cave to try it yourself", PlayerName, ReturnSToM(SInfo[CaveUpdateCount]));
        SendClientMessageToAll(COLOR_ORANGE, string);
        SendClientMessage(playerid,COLOR_ORANGE ,"[CAVE]You won in blabla, your best: blabla");
       
        SInfo[CaveRunning] = 0;
        SInfo[CaveJoining] = 0;
       
        KillTimer(SInfo[CaveUpdateTimer]);
    }
   
    else if(SInfo[CaveCount] > 0)
    {
        SendClientMessage(playerid,COLOR_ORANGE ,"[CAVE]... has dropped out blabla");
    }
    return 1;
}
and this:
pawn Код:
LeaveCaveGame(playerid);//OnPlayerDeath
Well, so I go ingame, in the game, die, and then the function should be called, so normally it should give me the messages
pawn Код:
SendClientMessageToAll(COLOR_ORANGE, string);
        SendClientMessage(playerid,COLOR_ORANGE ,"[CAVE]You won in blabla, your best: blabla");
But it doesn't do that... So I thought, okay there's something wrong with:
pawn Код:
SInfo[CaveCount]
But when I added the print line, and I looked in the server log I saw that the array was 0, however the messages weren't called...

Do you know what could be wrong?
Thanks in advance


Re: What's wrong with my if statement? - knackworst - 10.09.2013

I'm thinking my OnPlayerDeath is bugged, is that possible?


Re: What's wrong with my if statement? - Konstantinos - 10.09.2013

Did it print "0 leavecavegame called" but the message "[CAVE]You won in blabla, your best: blabla" did not appear?

Because it should.

EDIT: if you're using killerid at all, check if the killer is not INVALID_PLAYER_ID. I used to have a similar problem with a dueling system and it was causing OnPlayerDeath not being called at all.

Use crashdetect, it's really useful.

And/or a debug:
pawn Код:
public OnPlayerDeath( playerid, killerid, reason )
{
    printf( "DEBUG: OnPlayerDeath -> %d | %d | %d", playerid, killerid, reason );
    return 1;
}



Re: What's wrong with my if statement? - knackworst - 10.09.2013

Yeah I had a look at the wiki for OnPlayerDeath, and saw that I've been using killerid wrong, -> that caused the bug.

However, when I die now I get frozen and my skin gets reset?
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(killerid != INVALID_PLAYER_ID)
    {
        PInfo[killerid][Kills] ++;
        SendDeathMessage(killerid, playerid, reason);
    }

    SetPlayerSkin(playerid, PInfo[playerid][Skin]);
    PInfo[playerid][Deaths] ++;
   
    if(PInfo[playerid][VortexJump] == 1) LeaveVortexGame(playerid);
    if(PInfo[playerid][CaveGame] == 1) LeaveCaveGame(playerid);
    if(PInfo[playerid][Racing] != -1) LeaveRace(playerid, PInfo[playerid][Racing]);
   
    return 1;
}
?


Re: What's wrong with my if statement? - Konstantinos - 10.09.2013

Remove this line:
pawn Код:
SetPlayerSkin(playerid, PInfo[playerid][Skin]);
Setting the skin when a player dies is pointless.

Set the skin in OnPlayerSpawn instead.

Plus, use:
pawn Код:
SendDeathMessage(killerid, playerid, reason);
on top of the OnPlayerDeath callback, not inside the if statement about the killerid. If a player dies by themselves, the icon won't be shown if the killerid is not valid.