Function Not Working +REP
#1

I Made The Killer Of The Day System,And After It's Timer Ends,It Suppose To Send Some Messages And Give Money And Score To The Killer Of The Day,But There is nothing working. At These Codes:
pawn Код:
stock GetHighestKiller()
{
    new m;
    for(new i = 0 ; i <= MAX_PLAYERS ; i++)
    {
        if(KillerScore[i] > KillerScore[m])
        {
            m = i;
        }
    }
    return 1;
}
forward KillingScore();
public KillingScore()
{
     new highestkiller = GetHighestKiller();
     new str[64];
     if(highestkiller != INVALID_PLAYER_ID)
     {
        format(str, sizeof(str), "Congratulations!, You Are The {FF0000}Killer {FFEE00}Of The Day, Reward: $10000 Cash And 10 Scores!");
        SendClientMessage(highestkiller, 0xFFEE00FF, str);
        GivePlayerMoney(highestkiller, 10000);
        SetPlayerScore(highestkiller, GetPlayerScore(highestkiller)+10);
        GameTextForPlayer(highestkiller, "~g~Killer Of The Day! Reward: $10000 And 10 Scores!", 5000, 4);
        foreach(Player, i)
        {
          format(str, sizeof(str), "%s Is The {FF0000}Killer {FFEE00}Of The Day, Congratulations! With: %d Kills Today!", highestkiller, KillerScore[highestkiller]);
          SendClientMessage(highestkiller, 0x00FFF2FF, str);
          KillerScore[i] = 0;
        }
     }
}
The Codes Of The Timer Under OnGameModeInit:
pawn Код:
SetTimer("KillingScore", 1380000, true);
The Codes Of The Variable KillerScore[MAX_PLAYERS] Under OnPlayerDeath:
pawn Код:
KillerScore[killerid] ++;
Please Help For REP.
Reply
#2

pawn Код:
stock GetHighestKiller()
{
    new m;
    for(new i = 0 ; i <= MAX_PLAYERS ; i++)
    {
        if(KillerScore[i] > KillerScore[m])
        {
            return i;
        }
    }
    return -1;
}
Also why you have m variable to be compared ?
When you
pawn Код:
new m;
It'll have "0" as a value.
Reply
#3

pawn Код:
stock GetHighestKiller()
{
    new m;
    for(new i = 0 ; i <= MAX_PLAYERS ; i++)
    {
        if(KillerScore[i] > KillerScore[m])
        {
            m = i;
        }
    }
    return 1;
}
The ideea is good but you declare m,and then you compare each score with KillerScore[m] which at first is KillerScore[0]. This some time might work, but some time might not. Anyway, that's less important since you always return 1, not the "m" variable, so the highestkiller will always be the player with the id 1.
Check this:
pawn Код:
stock GetHighestKiller()
{
    new mkill=0, mplayer=INVALID_PLAYER_ID;
    for(new i = 0 ; i < MAX_PLAYERS ; i++)//Usually you go from 0 to MAX_PLAYERS-1 because you probably declared KillerScore[MAX_PLAYERS]
    {
        if(KillerScore[i] > mkill)
        {
            mkill=KillerScore[i];
            mplayer=i;
        }
    }
    return mplayer;
}
In mkill you store the highest numbers of kilss and in the mplayer you store the player who gained them.
pawn Код:
forward KillingScore();
public KillingScore()
{
     new highestkiller = GetHighestKiller();
     new str[64];
     if(highestkiller != INVALID_PLAYER_ID)
     {
        format(str, sizeof(str), "Congratulations!, You Are The {FF0000}Killer {FFEE00}Of The Day, Reward: $10000 Cash And 10 Scores!");
        SendClientMessage(highestkiller, 0xFFEE00FF, str);
        GivePlayerMoney(highestkiller, 10000);
        SetPlayerScore(highestkiller, GetPlayerScore(highestkiller)+10);
        GameTextForPlayer(highestkiller, "~g~Killer Of The Day! Reward: $10000 And 10 Scores!", 5000, 4);
        format(str, sizeof(str), "%s Is The {FF0000}Killer {FFEE00}Of The Day, Congratulations! With: %d Kills Today!", highestkiller, KillerScore[highestkiller]);
        SendClientMessageToAll(0x00FFF2FF, str); //You send this message to the whole server.
        foreach(Player, i)
        {
          KillerScore[i] = 0; //resset all the scores
        }
     }
}
You can optimize this if you reset the players score in the GetHighestKiller (without the HighestKiller of course) and then just reset his score.

pawn Код:
stock GetHighestKiller()
{
    new mkill=0, mplayer=INVALID_PLAYER_ID;
    for(new i = 0 ; i <= MAX_PLAYERS ; i++)
    {
        if(KillerScore[i] > mkill)
        {
            mkill=KillerScore[i];
            mplayer=i;
        }
        else KillerScore[i]=0;
    }
    return mplayer;
}
Reply
#4

wait i will try that
Reply
#5

It Doesn't Send me any message.
Reply
#6

pawn Код:
GetHighestKiller()
{
    new m = 0, score = 0;
    foreach(new i : Player)
    {
        if(KillerScore[i] > score)
        {
            score = KillerScore[i];
            m = i;
        }
    }
    return m;
}

forward KillingScore();
public KillingScore()
{
    new highestkiller = GetHighestKiller();
    if(highestkiller != INVALID_PLAYER_ID)
    {
        new str[110], playername[MAX_PLAYER_NAME];
        format(str, sizeof(str), "Congratulations! You Are The {FF0000}Killer {FFEE00}Of The Day, Reward: $10000 Cash And 10 Score!");
        SendClientMessage(highestkiller, 0xFFEE00FF, str);
        GivePlayerMoney(highestkiller, 10000);
        SetPlayerScore(highestkiller, GetPlayerScore(highestkiller) + 10);
        GameTextForPlayer(highestkiller, "~g~Killer Of The Day!~n~~p~Reward: ~g~$10000 ~p~And ~g~10 Scores!", 5000, 4);
        GetPlayerName(highestkiller, playername, sizeof(playername));
        format(str, sizeof(str), "%s Is The {FF0000}Killer {FFEE00}Of The Day, Congratulations! With: %d Kills Today!", playername, KillerScore[highestkiller]);
        SendClientMessageToAll(0x00FFF2FF, str);
        foreach(new i : Player) KillerScore[i] = 0;
    }
    else SendClientMessageToAll(0xFF0000FF, "There was no killer of the day, as nobody was killed.");
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(killerid != INVALID_PLAYER_ID) KillerScore[killerid]++;
    //Rest of code...
    return 1;
}
Reply
#7

Thanks,Threshold it worked
Reply


Forum Jump:


Users browsing this thread: