#1

How to create team
TEAM_POLICE
TEAM_TERRORIST
TEAM_MEDIC
Please help
And Team timer GivePlayerCash +1000 2minutes
Reply
#2

Making a team deathmatch
OK, now you know how to make classes and place them about we will show you how to set teams, this will be the first bit of real coding but is fairly easy. I will just be using the two classes described on this page so if you have more remove them for now or start a new mode and make sure only those two are in. Classes are numbered in order from 0, so the first class in your file is 0, the second is 1 and so on (computers and programs nearly always start from 0 in counting (you will find that your playerid in a test game is 0)). We want to set the team based on which class they choose (either Grove or Balla), you may look at the callbacks and think that this would go in the OnPlayerRequestClass function, and you would be correct. When the select their class you want to set the team based on that, we can't do it in the OnPlayerSpawn function as at that point we don't know the class they have selected (that is a parameter and only parameters we are passed or which are global in your script (we will cover this later) can be used in any function). First we need to define our teams, under the "#include" line(s) at the top of your file add these lines:

#define TEAM_GROVE 1
#define TEAM_BALLA 2
#define TEAM_GROVE_COLOR 0x00FF00AA // Bright Green (in RGBA format)
#define TEAM_BALLA_COLOR 0xFF00FFAA // Bright PurpleIf you want to alter the colors, that's fine, just remember that the last two digits are the alpha and the lower that is the less you can see the color. Defines are purely replacements, now if you ever want to use the number 1 in your script you can use TEAM_GROVE instead, this is not a good idea for normal calculations as it makes them harder to read, but for using to denote teams, which are only denoted by a number, it makes it a lot clearer what's going on (and makes it very easy to change the teams around or modify later as you need only change the 1 in the define rather than all the instances of it throughout the code. When the code is compiled, all the "TEAM_GROVE"s will be replaced by 1, it is not like a variable, it is a constant, it doesn't change. Now under those lines add:

new gTeam[MAX_PLAYERS];This is called a global array. An array is basically lots of variables (places you store data to read and write) clumped together to store lots of data at once. The "MAX_PLAYERS" is a pre-defined constant (done in exactly the same way as we did our defines. MAX_PLAYERS is actually set at 200 in SA-MP 0.2, so this means that our array can store up to 200 pieces of data. The g on the name means global, but that doesn't make it global (it just makes it easier to tell what variables do what, defining it outside a function means it is global and can be used by all our functions. Any variable defined in a function is local to that function and it can't have the same name as another variable in the same function or a global variable (which is also why the g is useful), it can however have the same name as another variable in another function. All the "playerid" variables in your blank script are in fact all independent variables, each local to a different function, however they are all passed the same data, but just remember that any functions you make won't automatically have that data. Now we have that set up we can set the teams:

SetPlayerTeamFromClass(playerid, classid)
{
if (classid == 0)
{
gTeam[playerid] = TEAM_GROVE;
}
else
{
gTeam[playerid] = TEAM_BALLA;
}
}Place that code OUTSIDE a function in your code (as it is a new function) and put these lines as the first things after the open curly braces in your OnPlayerRequestClass callback (notice the way the variables are not global so we are having to pass them to out function too):

SetPlayerTeamFromClass(playerid, classid);This will save the players team to an array through our new function. Data in an array is referenced by a number, so array[0] is the first item of data, array[1] is the second and so on, as we are using gTeam[playerid], depending on which playerid we are passed will define where in the array to store the data, so for player 5 their data will be stored at array position 5 (remember, this is the 6th piece of data). Now copy this function:

SetPlayerToTeamColor(playerid)
{
if (gTeam[playerid] == TEAM_GROVE)
{
SetPlayerColor(playerid, TEAM_GROVE_COLOR);
}
else if (gTeam[playerid] == TEAM_BALLA)
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}
}And add the following line to OnPlayerSpawn:

SetPlayerToTeamColor(playerid);We now have our teams, but what have we actually done?

if (classid == 0)
{
gTeam[playerid] = TEAM_GROVE;
}In our first function, we check which class they chose (remember we said that the first class defined in your file was class 0?) "==" means "is equal to", a single equals sign simply sets the variable to the number given (as seen on the next line but one). The curly braces separate the functions between them from the rest of the code, bits in there are only executed if the selected class is 0 (cj), if it isn't, the else command comes into play and executes instead (this executes whenever the "if" command is false (i.e. the class isn't 0)), since we only have two classes to choose from this must mean we're Balla:

else
{
gTeam[playerid] = TEAM_BALLA;
}We don't need a return here as there is no data to return.



The second half set the players' color when they spawn, so you can tell who's on which team. As we saved their team to a global array, we can still access the data even though it is in a separate function.

if (gTeam[playerid] == TEAM_GROVE)
{
SetPlayerColor(playerid, TEAM_GROVE_COLOR);
}Hopefully you can see what this is doing now, if the player who just spawned (as referenced by playerid) is in TEAM_GROVE, we set their color to TEAM_GROVEs color.

else if (gTeam[playerid] == TEAM_BALLA)
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}This next section is a little different, it could easilly have been done like this:

else
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}But the way it is done allows you to set their color to TEAM_BALLAs color only if the first part is false (as sorted by the ELSE) AND if they are in TEAM_BALLA, this allows you to add more options by adding more "else if ()" blocks to the end as one will only be executed if all the blocks before it weren't.
Reply
#3

Is there also a way too make a team admin only?

Reply
#4

Quote:
Originally Posted by [UF
XtreaMeR ]
Is there also a way too make a team admin only?

Yes, use IsPlayerAdmin and stuff for the teams cmd and spawns?
Reply
#5

My teaming is different!

pawn Код:
// my onplayerspawn    

    if(gTeam[playerid] == TEAM_WORKER) {
    SetPlayerColor(playerid,COLOR_GREEN); // Green
        }
    else if(gTeam[playerid] == TEAM_PIMP) {
    SetPlayerColor(playerid,COLOR_RED); // Red
        }
    else if(gTeam[playerid] == TEAM_GOLFER) {
    SetPlayerColor(playerid,COLOR_YELLOW); // Yellow
        }
    else if(gTeam[playerid] == TEAM_TRIAD) {
    SetPlayerColor(playerid,COLOR_PINK); // Pink
        }
    else if(gTeam[playerid] == TEAM_MECHANIC) {
    SetPlayerColor(playerid,COLOR_BLUE); // Blue
        }
    else if(gTeam[playerid] == TEAM_VALET) {
    SetPlayerColor(playerid,COLOR_LIGHTBLUE); // Light Blue
        }
    else if(gTeam[playerid] == TEAM_MEDIC) {
    SetPlayerColor(playerid,COLOR_DARKRED); // Dark Red
        }
    else if(gTeam[playerid] == TEAM_FBI) {
    SetPlayerColor(playerid,COLOR_ORANGE); // Orange
        }
    else if(gTeam[playerid] == TEAM_ADMIN) {
    SetPlayerColor(playerid,COLOR_ADMINISTRATOR); // COLOR_ADMINISTRATOR
        }
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerClass(playerid, classid);
    SetupPlayerForClassSelection(playerid);
    gPlayerClass[playerid] = classid;
    switch (classid) {
      case 0:
        {
                GameTextForPlayer(playerid, "~g~Worker", 500, 3);
            }
        case 1:
          {
                GameTextForPlayer(playerid, "~g~Pimp", 500, 3);
            }
        case 2:
        {
                GameTextForPlayer(playerid, "~g~Golfer", 500, 3);
            }
        case 3:
        {
                GameTextForPlayer(playerid, "~g~Triad", 500, 3);
            }
        case 4:
        {
                GameTextForPlayer(playerid, "~g~Mechanic", 500, 3);
            }
        case 5:
        {
                GameTextForPlayer(playerid, "~g~Valet", 500, 3);
            }
        case 6:
        {
                GameTextForPlayer(playerid, "~g~Medic", 500, 3);
            }
        case 7:
        {
                GameTextForPlayer(playerid, "~g~FBI", 500, 3);
            }
        case 8:
        {
                GameTextForPlayer(playerid, "~g~ADMIN ONLY!", 500, 3);

    }
}
    return 1;
}

pawn Код:
SetPlayerClass(playerid, classid) {
    if(classid == 0) {
    gTeam[playerid] = TEAM_WORKER;
    } else if(classid == 1) {
    gTeam[playerid] = TEAM_PIMP;
    } else if(classid == 2) {
    gTeam[playerid] = TEAM_GOLFER;
    } else if(classid == 3) {
    gTeam[playerid] = TEAM_TRIAD;
    } else if(classid == 4) {
    gTeam[playerid] = TEAM_MECHANIC;
    } else if(classid == 5) {
    gTeam[playerid] = TEAM_VALET;
    } else if(classid == 6) {
    gTeam[playerid] = TEAM_MEDIC;
    } else if(classid == 7) {
    gTeam[playerid] = TEAM_FBI;
    }else if(classid == 8) {
    gTeam[playerid] = TEAM_ADMIN;
    }
How'd I make an admin only out of those 3? thanks.

Reply
#6

Quote:
Originally Posted by [UF
XtreaMeR ]
My teaming is different!

pawn Код:
// my onplayerspawn  

    if(gTeam[playerid] == TEAM_WORKER) {
    SetPlayerColor(playerid,COLOR_GREEN); // Green
        }
    else if(gTeam[playerid] == TEAM_PIMP) {
    SetPlayerColor(playerid,COLOR_RED); // Red
        }
    else if(gTeam[playerid] == TEAM_GOLFER) {
    SetPlayerColor(playerid,COLOR_YELLOW); // Yellow
        }
    else if(gTeam[playerid] == TEAM_TRIAD) {
    SetPlayerColor(playerid,COLOR_PINK); // Pink
        }
    else if(gTeam[playerid] == TEAM_MECHANIC) {
    SetPlayerColor(playerid,COLOR_BLUE); // Blue
        }
    else if(gTeam[playerid] == TEAM_VALET) {
    SetPlayerColor(playerid,COLOR_LIGHTBLUE); // Light Blue
        }
    else if(gTeam[playerid] == TEAM_MEDIC) {
    SetPlayerColor(playerid,COLOR_DARKRED); // Dark Red
        }
    else if(gTeam[playerid] == TEAM_FBI) {
    SetPlayerColor(playerid,COLOR_ORANGE); // Orange
        }
    else if(gTeam[playerid] == TEAM_ADMIN) {
    SetPlayerColor(playerid,COLOR_ADMINISTRATOR); // COLOR_ADMINISTRATOR
        }
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerClass(playerid, classid);
    SetupPlayerForClassSelection(playerid);
    gPlayerClass[playerid] = classid;
    switch (classid) {
      case 0:
        {
                GameTextForPlayer(playerid, "~g~Worker", 500, 3);
            }
        case 1:
          {
                GameTextForPlayer(playerid, "~g~Pimp", 500, 3);
            }
        case 2:
        {
                GameTextForPlayer(playerid, "~g~Golfer", 500, 3);
            }
        case 3:
        {
                GameTextForPlayer(playerid, "~g~Triad", 500, 3);
            }
        case 4:
        {
                GameTextForPlayer(playerid, "~g~Mechanic", 500, 3);
            }
        case 5:
        {
                GameTextForPlayer(playerid, "~g~Valet", 500, 3);
            }
        case 6:
        {
                GameTextForPlayer(playerid, "~g~Medic", 500, 3);
            }
        case 7:
        {
                GameTextForPlayer(playerid, "~g~FBI", 500, 3);
            }
        case 8:
        {
                GameTextForPlayer(playerid, "~g~ADMIN ONLY!", 500, 3);

    }
}
    return 1;
}

pawn Код:
SetPlayerClass(playerid, classid) {
    if(classid == 0) {
    gTeam[playerid] = TEAM_WORKER;
    } else if(classid == 1) {
    gTeam[playerid] = TEAM_PIMP;
    } else if(classid == 2) {
    gTeam[playerid] = TEAM_GOLFER;
    } else if(classid == 3) {
    gTeam[playerid] = TEAM_TRIAD;
    } else if(classid == 4) {
    gTeam[playerid] = TEAM_MECHANIC;
    } else if(classid == 5) {
    gTeam[playerid] = TEAM_VALET;
    } else if(classid == 6) {
    gTeam[playerid] = TEAM_MEDIC;
    } else if(classid == 7) {
    gTeam[playerid] = TEAM_FBI;
    }else if(classid == 8) {
    gTeam[playerid] = TEAM_ADMIN;
    }
How'd I make an admin only out of those 3? thanks.

Please help with that post.

Bump.
Reply
#7

if I understand you correctly:
pawn Код:
//to make the team defines, at top of script
#define TEAM_POLICE 0
#define TEAM_TERRORIST 1
#define TEAM_MEDIC 2
new gTeam[MAX_PLAYERS]; //will be the variable to check if the player is to a certain team
Now, here's an example of using gTeam to check what team a player is in
pawn Код:
if(gTeam[playerid] == TEAM_POLICE)
{
  SetPlayerColor(playerid, colorhere);
}
That will check if the player team is the TEAM_POLICE.

And this would be the timer:
pawn Код:
//top of script after #include <a_samp>
forward GiveCash();

//OnGameModeInit()
SetTimer("GiveCash", 120000, 1);

//Somewhere after main()
public GiveCash()
{
  for(new i = 0; i<MAX_PLAYERS; i++)
  {
   GivePlayerMoney(i, 1000);
  }
}
Reply
#8

pawn Код:
else if(gTeam[playerid] == TEAM_ADMIN && IsPlayerAdmin(playerid)) // Checks for RCON admin
{
SetPlayerColor(playerid,COLOR_ADMINISTRATOR); // COLOR_ADMINISTRATOR
}
else
{
SendClientMessage(playerid,COLOR_RED,"You're not an administrator! Choose another skin!");
SetPlayerHealth(playerid, 0.0);
ForceClassSelection(playerid);
}
Indent the code yourself.
Reply
#9

Quote:
Originally Posted by Klutty
pawn Код:
else if(gTeam[playerid] == TEAM_ADMIN && IsPlayerAdmin(playerid)) // Checks for RCON admin
{
SetPlayerColor(playerid,COLOR_ADMINISTRATOR); // COLOR_ADMINISTRATOR
}
else
{
SendClientMessage(playerid,COLOR_RED,"You're not an administrator! Choose another skin!");
SetPlayerHealth(playerid, 0.0);
ForceClassSelection(playerid);
}
Indent the code yourself.
I love you man! (No HOMO!!) <3
Reply
#10

Quote:
Originally Posted by [UF
XtreaMeR ]
Quote:
Originally Posted by Klutty
pawn Код:
else if(gTeam[playerid] == TEAM_ADMIN && IsPlayerAdmin(playerid)) // Checks for RCON admin
{
SetPlayerColor(playerid,COLOR_ADMINISTRATOR); // COLOR_ADMINISTRATOR
}
else
{
SendClientMessage(playerid,COLOR_RED,"You're not an administrator! Choose another skin!");
SetPlayerHealth(playerid, 0.0);
ForceClassSelection(playerid);
}
Indent the code yourself.
I love you man! (No HOMO!!) <3
No prob. <3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)