Positions on Derby gets announced several times isntead of once - what is wrong?
#1

Here is the code which is ending the derbies (don't mind the debug msg's)

pawn Код:
public EndMonsterDerby()
{
   
    //if(!MonsterDerby) return 1;
    if(players == 0) return 1;

    IRC_GroupSay(gGroupID, IRC_CHANNEL,"4<-- 10The derby has ended!4 -->");
    new Hscore = -999999, Slot1 = -1, Slot2 = -1, Slot3 = -1, Slot4 = -1;
    new str[120];
    SendClientMessageToAll(-1,"------------------------------------------------------------------------------------");
    //IRC_GroupSay(gGroupID, IRC_CHANNEL,"4<-- 1---------------------------------------------------------------------------4 -->");
    SendClientMessageToAll(0x33FF33AA,"The Monster Derby has Ended!");
                   
   
    foreach(new i:Player)
    {
        if(GetPVarInt(i,"InMonsterDerby"))
        {
            if(DerbyScore[i] > Hscore)
            {
                if(IsPlayerConnected(GetPlayerID("denNorske")))
                SendClientMessage(GetPlayerID("denNorske"), -1,""corange"Debug: "cwhite"Derby winner called on "corange"EndMonsterDerby");
                Slot1 = i;
                Hscore = DerbyScore[i];
               
                new falls;
                if(Hscore == 0)
                    falls = 0;
                else
                    falls=(Hscore/ 10 *-1);
               
                format(str,sizeof(str), ""cgreen"5Winner:1 %s 5(ID:1 %d5) - Number of falls: 1 %d",PlayerName(i),i, falls);
                IRC_GroupSay(gGroupID, IRC_CHANNEL,str);
                format(str,sizeof(str), ""cgreen"Winner:"cwhite" %s (ID:%d)"cgreen" - Number of falls:"cwhite" %d",PlayerName(i),i, falls);
                SendClientMessageToAll(0x33FF33AA,str);
                SetPlayerScore(i,GetPlayerScore(i)+10);
                AccInfo[i][cookies]=AccInfo[i][cookies]  + 5;
                GivePlayerMoney(i, 5000);
            }
        }
    }
   
    Hscore = -999999;
   
    foreach(new i:Player)
    {
        if(GetPVarInt(i,"InMonsterDerby") && i != Slot1)
        {
            if(DerbyScore[i] > Hscore)
            {
                if(IsPlayerConnected(GetPlayerID("denNorske")))
                SendClientMessage(GetPlayerID("denNorske"), -1,""corange"Debug: "cwhite"Derby 2. place called on "corange"EndMonsterDerby");
                Slot2 = i;
                Hscore = DerbyScore[i];
                new falls;             
                    falls=(Hscore/ 10 * -1);
                format(str,sizeof(str), ""cgreen"5Second Place:1 %s 5(ID:1 %d5) - Number of falls: 1 %d",PlayerName(i),i, falls);
                IRC_GroupSay(gGroupID, IRC_CHANNEL,str);
                format(str,sizeof(str), ""cyellow"Second Place:"cwhite" %s (ID:%d)"cyellow" - Number of falls:"cwhite" %d",PlayerName(i),i, falls);
                SendClientMessageToAll(0x33FF33AA,str);
                SetPlayerScore(i,GetPlayerScore(i)+5);
                AccInfo[i][cookies]=AccInfo[i][cookies]  + 3;
                GivePlayerMoney(i, 2500);
               
            }
        }
    }
    Hscore = -999999;
    foreach(new i:Player)
    {
        if(GetPVarInt(i,"InMonsterDerby") && i != Slot1 && i != Slot2)
        {
            if(DerbyScore[i] > Hscore)
            {
                Slot3 = i;
                Hscore = DerbyScore[i];
                new falls;             
                    falls=(Hscore/ 10 * -1);
                format(str,sizeof(str), ""cgreen"5Third Place:1 %s 5(ID:1 %d5) - Number of falls: 1 %d",PlayerName(i),i, falls);
                IRC_GroupSay(gGroupID, IRC_CHANNEL,str);
                format(str,sizeof(str), ""corange"Third Place:"cwhite" %s (ID:%d)"corange" - Number of falls:"cwhite" %d",PlayerName(i),i, falls);
                SendClientMessageToAll(0x33FF33AA,str);
                SetPlayerScore(i,GetPlayerScore(i)+1);
                AccInfo[i][cookies]=AccInfo[i][cookies]  + 1;

                GivePlayerMoney(i, 500);
               
            }
        }
    }
    Hscore = -999999;
    foreach(new i:Player)
    {
        if(GetPVarInt(i,"InMonsterDerby")  && i != Slot1 && i != Slot2 && i != Slot3)
        {
            if(DerbyScore[i] > Hscore)
            {
                Slot4 = i;
                Hscore = DerbyScore[i];
                new falls;             
                    falls=(Hscore/ 10 * -1);
                format(str,sizeof(str), ""cgreen"5Fourth Place:1 %s 5(ID:1 %d5) - Number of falls: 1 %d",PlayerName(i),i, falls);
                IRC_GroupSay(gGroupID, IRC_CHANNEL,str);
                format(str,sizeof(str), ""cblue"Fourth Place:"cwhite" %s (ID:%d)"cblue" - Number of falls:"cwhite" %d",PlayerName(i),i, falls);
                SendClientMessageToAll(0x33FF33AA,str);

            }
        }
    }
    Hscore = -999999;
    foreach(new i:Player)
    {
        if(GetPVarInt(i,"InMonsterDerby")  && i != Slot1 && i != Slot2 && i != Slot3 && i != Slot4)
        {
            if(DerbyScore[i] > Hscore)
            {
                Hscore = DerbyScore[i];
                new falls;             
                    falls=(Hscore/ 10 * -1);
                format(str,sizeof(str), ""cgreen"5Fifth Place:1 %s 5(ID:1 %d5) - Number of falls: 1 %d",PlayerName(i),i, falls);
                IRC_GroupSay(gGroupID, IRC_CHANNEL,str);
                format(str,sizeof(str), ""cred"Fifth Place:"cwhite" %s (ID:%d)"cred" - Number of falls:"cwhite" %d",PlayerName(i),i, falls);
                SendClientMessageToAll(0x33FF33AA,str);
            }
        }
    }
    SendClientMessageToAll(-1,"------------------------------------------------------------------------------------");
    //IRC_GroupSay(gGroupID, IRC_CHANNEL,"4<-- 1---------------------------------------------------------------------------4 -->");
    if(Slot1 != -1)
        SendClientMessage(Slot1, blue, "Information: "cwhite"You won 5 cookies, 10 score and 5000$!");
    if(Slot2 != -1)
        SendClientMessage(Slot2, blue, "Information: "cwhite"You earned 3 cookies, 5 score and 2500$!");
    if(Slot3 != -1)
        SendClientMessage(Slot3, blue, "Information: "cwhite"You earned 1 cookie, 1 score and 500$");
       
       
    foreach(new i:Player)
    {
        if(GetPVarInt(i,"InMonsterDerby"))
        {
            DerbyScore[i]=0;
            SetPVarInt(i,"InMonsterDerby",0);
            if(GetPVarInt(i, "wasgodon") == 0)
            {
                SetPVarInt(i, "GOD", 0);
                SetPVarInt(i, "wasgodon", 0);
            }      
            DestroyVehicle(GetPVarInt(i,"MonsterID")) && SetPVarInt(i, "MonsterID", -1);
            SetPlayerPos(i,GetPVarFloat(i,"Xpos"),GetPVarFloat(i,"Ypos"),GetPVarFloat(i,"Zpos"));
            SetPlayerInterior(i, 0);
            SetPlayerVirtualWorld(i, 0);
        }
    }
    players = 0;
    SetTimer("StartMonsterDerby",TimeBetweenDerby*1000,0);
    new namez = GetPlayerID("denNorske");
        if(IsPlayerConnected(namez))
            SendClientMessage(namez, -1, "DEBUG: StartMonsterDerby TIMER started on EndMonsterDerby ( Winners announced)");

    MonsterDerby = 0;
    KillTimer(scorecheck);
    DerbyOpen = 0;
    return 1;
}
This is how it looks at the moment when there is only one player left (the other players leave by commands or exiting vehicles)




And this is when there are multiple people getting called up on the "endmonsterderby" callback. This is ofc when the derby ends and the scores are counted for 120 seconds in the derby.

Here is two players in endmonsterderby. (old pic, no debug msgs)




This makes no sense to me at all, since i used
pawn Код:
Slot1/2/3/4 = i;
in the code, and afterwards checking if the slots are taken or not.

What is my problem here, and how can i fix it ?
Reply
#2

just let me bump this.

Hope someone gets an idea of what i meant
Reply
#3

is this REALLY so hard? Like; i can provide more code and such / more details about my problem, no problem.
Aaanyone?

Thanks in advance (i've been trying myself to debug and such but i'm kinda confused)
Reply
#4

If you post the SendClientMessageToAll inside the foreach, every time new guy gets better score, his name will be called..
So, place it below foreach..
I've done 2for you. Continue for the rest.. 3rd/4th/5th etc.
Hope it helps.
Код:
public EndMonsterDerby()
{

    //if(!MonsterDerby) return 1;
    if(players == 0) return 1;

    IRC_GroupSay(gGroupID, IRC_CHANNEL,"4<-- 10The derby has ended!4 -->");
    new Hscore = -999999, Slot1 = -1, Slot2 = -1, Slot3 = -1, Slot4 = -1;
    new str[120];
    SendClientMessageToAll(-1,"------------------------------------------------------------------------------------");
    //IRC_GroupSay(gGroupID, IRC_CHANNEL,"4<-- 1---------------------------------------------------------------------------4 -->");
    SendClientMessageToAll(0x33FF33AA,"The Monster Derby has Ended!");

	new falls; //Made it Function Global.
    foreach(new i:Player)
    {
        if(GetPVarInt(i,"InMonsterDerby"))
        {
            if(DerbyScore[i] > Hscore)
            {
                if(IsPlayerConnected(GetPlayerID("denNorske")))
                SendClientMessage(GetPlayerID("denNorske"), -1,""corange"Debug: "cwhite"Derby winner called on "corange"EndMonsterDerby");
                Slot1 = i;
                Hscore = DerbyScore[i];

				if(Hscore == 0)
                    falls = 0;
                else
                    falls=(Hscore/ 10 *-1);
            }
        }
    }
    format(str,sizeof(str), ""cgreen"5Winner:1 %s 5(ID:1 %d5) - Number of falls: 1 %d",PlayerName(Slot1),Slot1, falls);
    IRC_GroupSay(gGroupID, IRC_CHANNEL,str);
    format(str,sizeof(str), ""cgreen"Winner:"cwhite" %s (ID:%d)"cgreen" - Number of falls:"cwhite" %d",PlayerName(Slot1),Slot1, falls);
    SendClientMessageToAll(0x33FF33AA,str);
    SetPlayerScore(Slot1,GetPlayerScore(Slot1)+10);
    AccInfo[Slot1][cookies]=AccInfo[Slot2][cookies]  + 5;
	GivePlayerMoney(Slot1, 5000);

    Hscore = -999999;
    falls =0 //Make it 0 after every foreach
    foreach(new i:Player)
    {
        if(GetPVarInt(i,"InMonsterDerby") && i != Slot1)
        {
            if(DerbyScore[i] > Hscore)
            {
                if(IsPlayerConnected(GetPlayerID("denNorske")))
                SendClientMessage(GetPlayerID("denNorske"), -1,""corange"Debug: "cwhite"Derby 2. place called on "corange"EndMonsterDerby");
                Slot2 = i;
                Hscore = DerbyScore[i];
                    falls=(Hscore/ 10 * -1);
            }
        }
    }
	format(str,sizeof(str), ""cgreen"5Second Place:1 %s 5(ID:1 %d5) - Number of falls: 1 %d",PlayerName(Slot2),i, falls);
	IRC_GroupSay(gGroupID, IRC_CHANNEL,str);
	format(str,sizeof(str), ""cyellow"Second Place:"cwhite" %s (ID:%d)"cyellow" - Number of falls:"cwhite" %d",PlayerName(Slot2),Slot2, falls);
	SendClientMessageToAll(0x33FF33AA,str);
	SetPlayerScore(Slot2,GetPlayerScore(Slot2)+5);
	AccInfo[Slot2][cookies]=AccInfo[Slot2][cookies]  + 3;
    GivePlayerMoney(Slot2, 2500);



    Hscore = -999999;
    falls =0
Reply
#5

Okay thankyou, I will read the code carefully and try to understand what you meant. I'm sure i will get an idea after a while.

Let me change, test and see if it works; and if i get it working i'll hand you a +rep.

Thanks again
Reply
#6

No worries bro.. Have a good day.
Reply
#7

That was working, but the positions are now random.
it's supposed to be f.ex.:

1. 1 fall
2. 2 falls
3. 3 falls
4. 4 falls

but now it is completely random:

1. 2 falls
2. 1 fall
3. 4 falls
4. 3 falls

Any ideas? This was also a tricky one.
Reply
#8

Try using "break;" at the end of the loop(For the winner).. or try creating a var., which detects if a winner has been chosen( new bool:WinnerChosen; ), and the winner's id( new WinnerID[ MAX_PLAYERS ]; ) ..

If a winner has been chosen, you stop the loop( break; ), if not, then you do the highscore stuff.
Reply
#9

Quote:
Originally Posted by Kyance
Посмотреть сообщение
Try using "break;" at the end of the loop(For the winner).. or try creating a var., which detects if a winner has been chosen( new bool:WinnerChosen; ), and the winner's id( new WinnerID[ MAX_PLAYERS ]; ) ..

If a winner has been chosen, you stop the loop( break; ), if not, then you do the highscore stuff.
Thanks alot for the idea! I'll try to do that aswell
Reply
#10

Quote:
Originally Posted by Kyance
Посмотреть сообщение
Try using "break;" at the end of the loop(For the winner).. or try creating a var., which detects if a winner has been chosen( new bool:WinnerChosen; ), and the winner's id( new WinnerID[ MAX_PLAYERS ]; ) ..

If a winner has been chosen, you stop the loop( break; ), if not, then you do the highscore stuff.
This confuses me a bit. Would you mind explaining a bit further what you meant?
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)