[Tutorial] Making a simple Team Death Match
#1

Oky, I'm gonna teach you how to make a simple TDM today.


Beginning


Before we start, We must define somethings for the sake of convenience:

pawn Код:
/* Under includes */

#define Criminals 1
#define Cops 2

#define CriminalsColor 0xFF0000AA
#define CopsColor 0x0015FFAA
Explanation:
We simply defined Criminals as the number 1 ( In this case, TEAM 1) and Cops as the number 2 ( In this case, TEAM 2) and defined CriminalsColor as RED ( 0xFF0000AA ) and CopsColor as BLUE ( 0x0015FFAA)

We're gonna use these later in our script.


Now, we're gonna set up 1 class for each team!

pawn Код:
// Under OnGameModeInIt //
AddPlayerClass(/* Cops Skin ID here */,/*Spawn Coords, Spawn Coords, Spawn Coords,Angle,Weapon 1,Weapon1amom,weapon2,weapon2ammo,weapon3,weapon3ammo*/);   
AddPlayerClass(/* Criminals Skin ID here */,/*Spawn Coords, Spawn Coords, Spawn Coords,Angle,Weapon 1,Weapon1amom,weapon2,weapon2ammo,weapon3,weapon3ammo*/);
Okay, we've set this up till now. But how will PAWNO know what class has what team? We'll have to do that now!
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
// So, we're gonna simply use a switch instead of if-else if structure

    switch(classid) // Switching between the classids
    {
         case 0/* The first classid is of the cops*/:
         {
              SetPlayerTeam(playerid, Cops); // Setting players team
              GameTextForPlayer(playerid, "~b~Cops", 1000, 3); // Screen msg for player to show what team
          }
 
         case 1/* The second classid is of the criminals*/:
         {
              SetPlayerTeam(playerid, Criminals); // Same as above
              GameTextForPlayer(playerid, "~r~Criminals, 1000", 3); // Same as above
          }
     }
     return 1;
}
Okay, we're done but but but, Now we want to add the colors, and give special bonuses to different teams!

pawn Код:
/* OnPlayerSpawn */
    if(GetPlayerTeam(playerid) == Cops)
    {
        SetPlayerColor(playerid, CopsColor); // Set his color to CopsColor (BLUE)
           /* Any other bonus you want for Cops team! A special gun, skin, color, attachedobject, A random spawn! */
    }
   
    else if(GetPlayerTeam(playerid) ==Criminals)
    {
        SetPlayerColor(playerid, CriminalsColor);  // Same as above but in this case, CriminalsColor (RED)
    }
What we did above was:

We checked WHAT team did the player belong to (SELECTED IN THE CLASS SELECTION) and according to that set his color, health, weapons etc. etc. etc. etc.


Now, we'll make some special features that be a must have in a TDM!


1. Random team spawns

Okay, this might seem complicated, but its quite simple. First of all, You just do one thing:

Go ingame, Do /save TEAMNAMERANDOMSPAWN1/2/3.
Do that for each team and have at least 2-3 spawn coords for each team.

Now using a random spawn array generator, Get the following codes. I'm not gonna teach you HOW to use the randomspawn array generator because this is meant to be a simple TDM, not an app usage tutorial.
BTW, I used this array generator: https://sampforum.blast.hk/showthread.php?tid=199377
pawn Код:
new Float:CopRandomSpawns[4][3] = {
    {2494.8743,-1686.0897,13.5129},
    {2514.5706,-1672.4789,13.6054},
    {2487.3936,-1648.9874,13.6405},
    {2459.4307,-1689.4059,13.5369}
};


new Float:CriminalRandomSpawns[4][3] = {
    {2140.0620,-1699.6169,15.0784},
    {2166.7761,-1672.4318,15.0752},
    {2163.2312,-1659.7107,15.0859},
    {2173.2839,-1702.9806,14.3778}
};
Now you have the coords, you have everything, But you still can't enable the random spawns? We'll do that now:

We'll make custom functions for each team now :

pawn Код:
/// Outside all callbacks //
forward SetPlayerRandomCopSpawn(playerid); // Forwarding the function
public SetPlayerRandomCopSpawn(playerid) // Setting it up
{
    new rand = random(sizeof(CopRandomSpawns)); // Making it select random options instead of a definite one
    SetPlayerPos(playerid, CopRandomSpawns[rand][0], CopRandomSpawns[rand][1], CopRandomSpawns[rand][2]); // [rand] tag means random, [0] = X, [1] = Y, [2] = Z
    return 1;
}

/// Rest is same as above, just Cops replaced Criminals
forward SetPlayerRandomCriminalSpawn(playerid);
public SetPlayerRandomCriminalSpawn(playerid)
{
    new rand = random(sizeof(CriminalRandomSpawns));
    SetPlayerPos(playerid, CriminalRandomSpawns[rand][0], CriminalRandomSpawns[rand][1], CriminalRandomSpawns[rand][2]);
    return 1;
}

Now, just add the following in our previous OnPlayerSpawn :

pawn Код:
/* OnPlayerSpawn */
    if(GetPlayerTeam(playerid) == Cops)
    {
        SetPlayerColor(playerid, CopsColor); // Set his color to CopsColor (BLUE)
        SetPlayerRandomCopSpawn(playerid); /// NEW LINE! Enabling random spawns
           /* Any other bonus you want for Cops team! A special gun, skin, color, attachedobject, A random spawn! */
    }
   
    else if(GetPlayerTeam(playerid) ==Criminals)
    {
        SetPlayerColor(playerid, CriminalsColor);  // Same as above but in this case, CriminalsColor (RED)
        SetPlayerRandomCriminalSpawn(playerid);///// Same as above
    }

2. The Team radio
pawn Код:
public OnPlayerText(playerid,text[])
{
    if(text[0] == ':') // : can be changed to whatever symbol u wanna use for player to enable the teamchat.
    {
        new string[128];  GetPlayerName(playerid, string, sizeof(string)); // Making the new's
        format(string, sizeof(string), "[Team Radio] %s: %s", string, text[1]); // Formatted the message
        printf("%s", string); // Printed it BOTH ingame + the server log

        for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
        {
            if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
        }
        return 0;
    }

    return 1;
}

Voila! Your TDM has got its base! You can do the rest yourself!
Reply


Messages In This Thread
Making a simple Team Death Match - by Gangs_Rocks - 29.05.2012, 10:34
Re: Making a simple Team Death Match - by [GF]Logic - 29.05.2012, 11:00
Re: Making a simple Team Death Match - by StrangeLove - 29.05.2012, 12:21
Re: Making a simple Team Death Match - by Gangs_Rocks - 29.05.2012, 13:05
Re: Making a simple Team Death Match - by StrangeLove - 30.05.2012, 03:27
Re: Making a simple Team Death Match - by Gangs_Rocks - 30.05.2012, 06:23
Re: Making a simple Team Death Match - by StrangeLove - 30.05.2012, 11:56
Re: Making a simple Team Death Match - by StrangeLove - 31.05.2012, 04:38
Re: Making a simple Team Death Match - by JohnDoVaS12345 - 31.05.2012, 07:42
Re: Making a simple Team Death Match - by efrim123 - 28.09.2013, 01:59

Forum Jump:


Users browsing this thread: 1 Guest(s)