PDA

View Full Version : What's wrong with my if statement?


knackworst
10/09/2013, 11:08 AM
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:

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:
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 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: 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 :)

knackworst
10/09/2013, 11:24 AM
I'm thinking my OnPlayerDeath is bugged, is that possible?

Konstantinos
10/09/2013, 11:26 AM
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:

public OnPlayerDeath( playerid, killerid, reason )
{
printf( "DEBUG: OnPlayerDeath -> %d | %d | %d", playerid, killerid, reason );
return 1;
}

knackworst
10/09/2013, 11:37 AM
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?
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;
}
?

Konstantinos
10/09/2013, 12:02 PM
Remove this line:

SetPlayerSkin(playerid, PInfo[playerid][Skin]);

Setting the skin when a player dies is pointless.

Set the skin in OnPlayerSpawn instead.

Plus, use:

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.