SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/07/2012, 07:38 AM   #1
Gangs_Rocks
Big Clucker
 
Join Date: Feb 2012
Location: Mars
Posts: 115
Reputation: 13
Default Need to learn

Okay,I'm working on a counterstrike gamemode with MULTIPLE maps.

Now, what I'm doing is trying to create a UNIT limit for each team

Unit = Players.
Once a player of that team dies = 1 unit goes down for that team.
If the units of a team reach 0, the other team wins by default.

Now I'm really confused, I have no idea how I can give the score to the other team with my code:

pawn Code:
enum TeamInfo
{
    Units,
    Zones,
    Bonus,
};
#define MAX_TEAMS 2
new tInfo[MAX_TEAMS][TeamInfo];

public OnPlayerDeath(playerid, killerid, reason)
{
    SaveStats(playerid);
   
    new team = GetPlayerTeam(playerid);
    tInfo[team][Units]--;
   
    if(tInfo[team][Units] == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i)) continue;
            {
                SendClientMessage(i, GREEN, "%s has run out of soldiers! The other team wins by default! ");
            }
        }
    }
    return 1;
}

I'd appreciate a 20-30 minutes lesson on this and some doubt clearing OR simply if someone could tell me how to do it.
Gangs_Rocks is offline   Reply With Quote
Old 14/07/2012, 08:29 AM   #2
Sinner
Gangsta
 
Sinner's Avatar
 
Join Date: Aug 2010
Location: On This Mortal Coil
Posts: 850
Reputation: 289
Default Re: Need to learn

In your case, I'd say you just give score to everyone who is NOT on the team of which the Units has ran out (so let's assume TEAM0 has no more units, TEAM1 would win, correct?).

To do this:

pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    SaveStats(playerid);
   
    new team = GetPlayerTeam(playerid);
    tInfo[team][Units]--;
   
    if(tInfo[team][Units] == 0)
    {
        new opposite_team = !team;
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(GetPlayerTeam(i) == opposite_team) {
                // Give them score because the other team has no more units
            }
        }
    }
    return 1;
}

We assume the team IDs are 0 and 1, otherwise this example will not work;
A better solution would be:

pawn Code:
// Define your teams
#define TEAM1        556415  // Some team IDS
#define TEAM2        156465  // That don't have to be 0 or 1

// Then get the opposite team in the example above using:

new team = GetPlayerTeam(playerid); // Losing team, as seen above
new opposite_team = (team == TEAM1 ? TEAM2 : TEAM1);
__________________
Please use the search feature before asking a question.
Sinner is offline   Reply With Quote
Old 14/07/2012, 11:44 AM   #3
Gangs_Rocks
Big Clucker
 
Join Date: Feb 2012
Location: Mars
Posts: 115
Reputation: 13
Default Re: Need to learn

Compiler crash with that code...
Gangs_Rocks is offline   Reply With Quote
Old 14/07/2012, 12:15 PM   #4
Andi_Evandy
Big Clucker
 
Join Date: Nov 2011
Location: Indonesia
Posts: 126
Reputation: 23
Default Re: Need to learn

like this?
pawn Code:
enum TeamInfo
{
    Units,
    Zones,
    Bonus,
};
#define MAX_TEAMS 2
new tInfo[MAX_TEAMS][TeamInfo];

public OnPlayerDeath(playerid, killerid, reason)
{
    SaveStats(playerid);
   
    new team = GetPlayerTeam(playerid);
    tInfo[team][Units]--;
   
    if(tInfo[team][Units] == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i)) SendClientMessage(i, GREEN, "%s has run out of soldiers! The other team wins by default! ");
            if(GetPlayerTeam(i) != team) SetPlayerScore(i, GetPlayerScore(i) + 1); //if Player "i" is not in Team "team", then SetPlayerScore... (CMIIW)
        }

    }
    return 1;
}

well, i don't sure if it works or not
Andi_Evandy is offline   Reply With Quote
Old 14/07/2012, 03:32 PM   #5
Gangs_Rocks
Big Clucker
 
Join Date: Feb 2012
Location: Mars
Posts: 115
Reputation: 13
Default Re: Need to learn

Crashed with BOTH the codes.
Gangs_Rocks is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What to Learn killanator10 Everything and Nothing 15 31/08/2011 10:06 AM
How I learn PHP? Ricop522 Everything and Nothing 4 19/06/2011 05:07 AM
Will this help me learn? NewTorran Everything and Nothing 20 03/06/2010 08:44 PM
learn for nothing? Sfinx_17 Help Archive 39 24/11/2009 06:01 PM


All times are GMT. The time now is 05:27 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.