Problem with GiveTeamReward stock.
#1

So I've tried to create a little stock, that will give the winning team a reward when my game mode changes.
Here's the current stock.
pawn Код:
stock GiveTeamReward()
{
    foreach(Player, i)
    {
        if(winner == 1) //ct
        {
            if(gTeam[i] == TEAM_CT)
            {
                GivePlayerMoney(i, 10000);
            }
        }
        if(winner == 2) //te
        {
            if(gTeam[i] == TEAM_TE)
            {
                GivePlayerMoney(i, 10000);
            }
        }
    }
}
And here's my ChangeMode function.
pawn Код:
//this is only the relevant part.
forward ChangeMode();
public ChangeMode()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(winner == 1)
        {
            GiveTeamReward();
        }
        else if(winner == 2)
        {
            GiveTeamReward();
        }
    }
It's giving the winners like 500k. Why's that?
Reply
#2

pawn Код:
forward ChangeMode();
public ChangeMode()
{
    for(new i = 0; i < MAX_PLAYERS; i++)//MAX_PLAYERS = 500, so it will loop 500 times...
    {
        if(winner == 1)
        {
            GiveTeamReward();
        }
        else if(winner == 2)
        {
            GiveTeamReward();
        }
    }
Change it to

pawn Код:
forward ChangeMode();
public ChangeMode()
{
    GiveTeamReward();
}
Reply
#3

Because you put the GiveTeamReward in a loop. Simply remove the for loop in ChangeMode:

pawn Код:
public ChangeMode()
{    
    GiveTeamReward();
Reply
#4

What a simple mistake. I haven't tested it yet, but hopefully it won't loop 500 times and give the players x500 cash. Thank you guys.
Reply
#5

It's not giving everyone on the winning team a reward. Only the person that gets the kill.
pawn Код:
stock GiveTeamReward()
{
    foreach(Player, i)
    {
        if(winner == 1) //ct
        {
            if(gTeam[i] == TEAM_CT)
            {
                GivePlayerMoney(i, 10000);
            }
        }
        if(winner == 2) //te
        {
            if(gTeam[i] == TEAM_TE)
            {
                GivePlayerMoney(i, 10000);
            }
        }
    }
}
And here's this, since its relevant.
pawn Код:
tscore[gTeam[killerid]]++;
    new astring[128];
    format(astring,sizeof(astring), "You have killed %s, and earned one score for your team. (Total Score: %d)",GetName(playerid),tscore[gTeam[killerid]]);
    SendClientMessage(killerid,COLOR_CYAN, astring);
    if(gTeam[killerid] == TEAM_TE)
    {
        if(tscore[gTeam[killerid]] == 10)
        {
            winner = 2; //te win
            new pstring[128];
            format(pstring,sizeof(pstring), "%s has won the round for Terrorists. The team earned 10k cash.",GetName(killerid));
            SendClientMessageToAll(COLOR_RED, pstring);
            ChangeMode();
        }
    }
    else if(gTeam[killerid] == TEAM_CT)
    {
        if(tscore[gTeam[killerid]] == 10)
        {
            winner = 1; //ct win
            new pstring[128];
            format(pstring,sizeof(pstring), "%s has won the round for Counter Terrorists The team earned 10k cash.",GetName(killerid));
            SendClientMessageToAll(COLOR_MEDIUMBLUE, pstring);
            ChangeMode();
        }
    }
What's the problem? :3
Reply
#6

Since I don't really have the 'full' code..

pawn Код:
tscore[gTeam[killerid]]++;
    new astring[128];
    format(astring,sizeof(astring), "You have killed %s, and earned one score for your team. (Total Score: %d)",GetName(playerid),tscore[gTeam[killerid]]);
    SendClientMessage(killerid,COLOR_CYAN, astring);
   
    if(tscore[gTeam[killerid]] == 10)
    {
        winner = gTeam[killerid];
        new pstring[128];
        format(pstring,sizeof(pstring), "%s%s has won the round for %ss. Their team has earned 10k cash.",TeamColor(killerid), GetName(killerid), TeamName(killerid));
        SendClientMessageToAll(COLOR_RED, pstring);
        ChangeMode();
    }


forward ChangeMode();
public ChangeMode()
{
    foreach(Player, i) if(gTeam[i] == winner) GivePlayerMoney(i, 10000); //this is now your team reward thing
    winner=-1; //reset the winner
   
    //rest of your mode change
}

stock TeamColor(playerid)
{
    new col[9];
    switch(gTeam[playerid])
    {
        case TEAM_TE: col="{CC0000}"; //this would be red (same as below if you want)
        case TEAM_CT: col="{0000FF}"; //replace this with your medium blue define (take out the 0x and the last 2 numbers)
    }
    return col;
}
stock TeamName(playerid) //This is useful for /stats and stuff too
{
    new tname[20];
    switch(gTeam[playerid])
    {
        case TEAM_CT: tname="Counter Terrorist";
        case TEAM_TE: tname="Terrorist";
    }
    return tname;
}
Is that what you're trying to do?
Reply
#7

I appreciate the help. I'm about to test it, and I'll get back to you.
Reply
#8

Quote:
Originally Posted by rangerxxll
Посмотреть сообщение
I appreciate the help. I'm about to test it, and I'll get back to you.
k tell me if it works/doesn't
Reply
#9

It works. Could you please tell me what I did wrong so i can prevent it in the future? I'm having a bit of trouble understanding. Does the stock not work?
Reply
#10

Basically, ChangeMode was giving the players their reward MAX_PLAYERS amount of times (default would make it 500 times)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)